This repository has been archived by the owner on Feb 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
891b502
commit 9883cd8
Showing
6 changed files
with
2,076 additions
and
2,390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import * as React from 'react'; | ||
import { View, Image, ScrollView, Dimensions, StyleSheet } from 'react-native'; | ||
import { withNavigation } from '@react-navigation/core'; | ||
|
||
@withNavigation | ||
class NavigationAwareScrollView extends React.Component { | ||
componentDidMount() { | ||
this.props.navigation.addListener('willFocus', () => { | ||
this._isFocused = true; | ||
}); | ||
|
||
this.props.navigation.addListener('willBlur', () => { | ||
this._isFocused = false; | ||
}); | ||
|
||
this.props.navigation.addListener('refocus', () => { | ||
if (this._isFocused) { | ||
this._component.scrollTo({ x: 0, y: 0 }); | ||
} | ||
}); | ||
} | ||
|
||
setNativeProps(props) { | ||
this._component.setNativeProps(props); | ||
} | ||
|
||
_setComponentRef(c) { | ||
this._component = c; | ||
} | ||
|
||
getNode() { | ||
return this._component; | ||
} | ||
|
||
render() { | ||
return ( | ||
<ScrollView | ||
{...this.props} | ||
ref={view => { | ||
this._component = view; | ||
}} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default function PhotoGrid({ id }) { | ||
const PHOTOS = Array.from({ length: 24 }).map( | ||
(_, i) => `https://unsplash.it/300/300/?random&__id=${id}${i}` | ||
); | ||
|
||
return ( | ||
<NavigationAwareScrollView contentContainerStyle={styles.content}> | ||
{PHOTOS.map(uri => ( | ||
<View key={uri} style={styles.item}> | ||
<Image source={{ uri }} style={styles.photo} /> | ||
</View> | ||
))} | ||
</NavigationAwareScrollView> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
content: { | ||
flexDirection: 'row', | ||
flexWrap: 'wrap', | ||
padding: 4, | ||
}, | ||
item: { | ||
height: Dimensions.get('window').width / 2, | ||
width: '50%', | ||
padding: 4, | ||
}, | ||
photo: { | ||
flex: 1, | ||
resizeMode: 'cover', | ||
}, | ||
}); |
Oops, something went wrong.