Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 38 additions & 30 deletions Examples/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Image,
TouchableOpacity,
FlatList,
Dimensions,
Dimensions
} from 'react-native';

import { Transition, FluidNavigator } from '../lib';
Expand All @@ -15,23 +15,26 @@ class ListScreen extends React.Component {
constructor(props) {
super(props);
this.state = {
items: [],
items: []
};
}

componentWillMount() {
componentDidMount() {
const items = [];
const imageSize = 80;
const numberOfImages = 40;
const randMax = 100;
for (let i = 0; i < numberOfImages; i++) {
let randomNumber = Math.floor((Math.random() * randMax) + 1);
const idExists = (e) => e.id === randomNumber;
let randomNumber = Math.floor(Math.random() * randMax + 1);
const idExists = e => e.id === randomNumber;
while (items.findIndex(idExists) > -1) {
randomNumber = Math.floor((Math.random() * randMax) + 1);
randomNumber = Math.floor(Math.random() * randMax + 1);
}

items.push({ url: `https://picsum.photos/${imageSize}/${imageSize}?image=${randomNumber}`, id: randomNumber });
items.push({
url: `https://picsum.photos/${imageSize}/${imageSize}?image=${randomNumber}`,
id: randomNumber
});
}
this.setState({ ...this.state, items });
}
Expand All @@ -51,7 +54,9 @@ class ListScreen extends React.Component {
renderItem = ({ item, index }) => (
<TouchableOpacity
style={styles.row}
onPress={() => { this.props.navigation.navigate('details', { item, index }); }}
onPress={() => {
this.props.navigation.navigate('details', { item, index });
}}
>
<Transition shared={`image${index}`}>
<Image style={styles.image} source={{ uri: item.url }} />
Expand All @@ -61,8 +66,7 @@ class ListScreen extends React.Component {
<Text>{item.url}</Text>
</View>
</TouchableOpacity>

)
);
}

class DetailsScreen extends React.Component {
Expand All @@ -81,7 +85,10 @@ class DetailsScreen extends React.Component {
<Text style={styles.caption}>Image URI:</Text>
<Text>{this.props.navigation.state.params.item.url}</Text>
</View>
<TouchableOpacity style={styles.button} onPress={() => this.props.navigation.goBack()}>
<TouchableOpacity
style={styles.button}
onPress={() => this.props.navigation.goBack()}
>
<Text>Back</Text>
</TouchableOpacity>
</View>
Expand All @@ -93,7 +100,7 @@ class DetailsScreen extends React.Component {

const styles = StyleSheet.create({
container: {
flex: 1,
flex: 1
},
row: {
margin: 10,
Expand All @@ -106,57 +113,58 @@ const styles = StyleSheet.create({
shadowOffset: { width: 0, height: 5 },
shadowOpacity: 0.4,
flexDirection: 'row',
elevation: 3,
elevation: 3
},
textContainer: {
flexDirection: 'column',
marginLeft: 18,
flex: 1,
justifyContent: 'center',
justifyContent: 'center'
},
image: {
width: 80,
height: 80,
borderRadius: 40,
borderRadius: 40
},
caption: {
fontWeight: 'bold',
fontSize: 14,
fontSize: 14
},
largeImage: {
width: Dimensions.get('window').width,
height: Dimensions.get('window').width,
height: Dimensions.get('window').width
},
bottomContainer: {
backgroundColor: '#ECECEC',
flex: 1,
padding: 20,
padding: 20
},
button: {
padding: 12,
backgroundColor: '#CECECE',
justifyContent: 'center',
alignItems: 'center',
},
alignItems: 'center'
}
});

const Navigator = FluidNavigator({
list: { screen: ListScreen },
details: { screen: DetailsScreen },
}, {
defaultNavigationOptions: {
gesturesEnabled: true,
const Navigator = FluidNavigator(
{
list: { screen: ListScreen },
details: { screen: DetailsScreen }
},
});
{
defaultNavigationOptions: {
gesturesEnabled: true
}
}
);

class FlatListScreen extends React.Component {
static router = Navigator.router;

render() {
const { navigation } = this.props;
return (
<Navigator navigation={navigation} />
);
return <Navigator navigation={navigation} />;
}
}

Expand Down
106 changes: 65 additions & 41 deletions Examples/ImageTransition.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,83 @@
import React, { Component } from 'react';
import { View, Text, Dimensions, Button, TouchableOpacity, FlatList, Image, StyleSheet } from 'react-native';
import {
View,
Text,
Dimensions,
Button,
TouchableOpacity,
FlatList,
Image,
StyleSheet
} from 'react-native';
import chunk from 'lodash.chunk';
import { FluidNavigator, Transition } from '../lib';

const styles = StyleSheet.create({
container: {
flex: 1,
flex: 1
},
detailsImage: {
width: Dimensions.get('window').width,
height: Dimensions.get('window').width * 0.5,
height: Dimensions.get('window').width * 0.5
},
detailsView: {
padding: 10,
backgroundColor: '#ECECEC',
flex: 1,
flex: 1
},
buttonContainer: {
flex: 1,
justifyContent: 'flex-end',
justifyContent: 'flex-end'
},
text: {
paddingBottom: 40,
paddingBottom: 40
},
row: {
flexDirection: 'row',
flexDirection: 'row'
},
cell: {
margin: 2,
margin: 2
},
header: {
height: 65,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#0000FA',
backgroundColor: '#0000FA'
},
headerText: {
fontWeight: 'bold',
fontSize: 18,
color: '#FFF',
color: '#FFF'
},
imageContainer: {
flexDirection: 'row',
},
flexDirection: 'row'
}
});

class ImageListScreen extends React.Component {
constructor(props) {
super(props);
this.state = {
items: [],
items: []
};
}

componentWillMount() {
componentDidMount() {
const items = [];
const size = Dimensions.get('window').width;
const max = 39;
const randMax = 100;
for (let i = 0; i < max; i++) {
let randomNumber = Math.floor((Math.random() * randMax) + 1);
const idExists = (e) => e.id === randomNumber;
let randomNumber = Math.floor(Math.random() * randMax + 1);
const idExists = e => e.id === randomNumber;
while (items.findIndex(idExists) > -1) {
randomNumber = Math.floor((Math.random() * randMax) + 1);
randomNumber = Math.floor(Math.random() * randMax + 1);
}

items.push({ url: `https://picsum.photos/${size}/${size}?image=${randomNumber}`, id: randomNumber });
items.push({
url: `https://picsum.photos/${size}/${size}?image=${randomNumber}`,
id: randomNumber
});
}
this.setState({ ...this.state, items });
}
Expand All @@ -75,9 +87,12 @@ class ImageListScreen extends React.Component {
<View style={styles.container}>
<ImageGrid
images={this.state.items}
imageSelected={(image) => this.props.navigation.navigate('imageDetails', { url: image.url })}
imageSelected={image =>
this.props.navigation.navigate('imageDetails', { url: image.url })
}
/>
</View>);
</View>
);
}
}

Expand All @@ -101,7 +116,7 @@ class ImageDetailsScreen extends React.Component {
<View style={styles.detailsView}>
<Text style={styles.text}>{uri}</Text>
<View style={styles.buttonContainer}>
<Button title="Back" onPress={() => navigation.goBack()} />
<Button title='Back' onPress={() => navigation.goBack()} />
</View>
</View>
</Transition>
Expand All @@ -116,20 +131,24 @@ class ImageGrid extends Component {
this._colCount = 3;
const { width: windowWidth } = Dimensions.get('window');
this._margin = 2;
this._photoSize = (windowWidth - this._margin * this._colCount * 2) / this._colCount;
this._photoSize =
(windowWidth - this._margin * this._colCount * 2) / this._colCount;
this.state = { chunkedImages: chunk(props.images, this._colCount) };
}

_colCount
_colCount;

_photoSize
_photoSize;

_margin
_margin;

_chunkedImages
_chunkedImages;

componentWillReceiveProps(nextProps) {
this.setState({ ...this.state, chunkedImages: chunk(nextProps.images, this._colCount) });
static getDerivedStateFromProps(nextProps, prevState) {
this.setState({
...prevState,
chunkedImages: chunk(nextProps.images, this._colCount)
});
}

render() {
Expand All @@ -138,7 +157,8 @@ class ImageGrid extends Component {
data={this.state.chunkedImages}
keyExtractor={this.keyExtractor}
renderItem={this.renderItem.bind(this)}
/>);
/>
);
}

keyExtractor(item, index) {
Expand All @@ -155,11 +175,14 @@ class ImageGrid extends Component {

renderCell(image) {
return (
<TouchableOpacity onPress={() => this.props.imageSelected(image)} key={image.url}>
<TouchableOpacity
onPress={() => this.props.imageSelected(image)}
key={image.url}
>
<View style={styles.cell}>
<Transition shared={image.url}>
<Image
resizeMode="cover"
resizeMode='cover'
source={{ uri: image.url }}
style={{ width: this._photoSize, height: this._photoSize }}
/>
Expand All @@ -170,23 +193,24 @@ class ImageGrid extends Component {
}
}

const Navigator = FluidNavigator({
imageList: { screen: ImageListScreen },
imageDetails: { screen: ImageDetailsScreen },
}, {
defaultNavigationOptions: {
gesturesEnabled: true,
const Navigator = FluidNavigator(
{
imageList: { screen: ImageListScreen },
imageDetails: { screen: ImageDetailsScreen }
},
});
{
defaultNavigationOptions: {
gesturesEnabled: true
}
}
);

class ImageTransitions extends React.Component {
static router = Navigator.router;

render() {
const { navigation } = this.props;
return (
<Navigator navigation={navigation} />
);
return <Navigator navigation={navigation} />;
}
}

Expand Down
Loading