improve gallery thumbnail loading and display #21

Merged
akinwale merged 3 commits from gallery-thumbnails into master 2019-08-15 20:28:48 +02:00
2 changed files with 38 additions and 16 deletions

View file

@ -82,7 +82,7 @@ class PublishPage extends React.PureComponent {
// gallery videos // gallery videos
videos: null, videos: null,
galleryThumbnailsChecked: false, checkedThumbnails: [],
// camera // camera
cameraType: RNCamera.Constants.Type.back, cameraType: RNCamera.Constants.Type.back,
@ -129,18 +129,24 @@ class PublishPage extends React.PureComponent {
componentWillMount() { componentWillMount() {
const { navigation } = this.props; const { navigation } = this.props;
// this.didFocusListener = navigation.addListener('didFocus', this.onComponentFocused); // this.didFocusListener = navigation.addListener('didFocus', this.onComponentFocused);
DeviceEventEmitter.addListener('onGalleryThumbnailsChecked', this.handleGalleryThumbnailsChecked); DeviceEventEmitter.addListener('onGalleryThumbnailChecked', this.handleGalleryThumbnailChecked);
} }
componentWillUnmount() { componentWillUnmount() {
if (this.didFocusListener) { if (this.didFocusListener) {
this.didFocusListener.remove(); this.didFocusListener.remove();
} }
DeviceEventEmitter.removeListener('onGalleryThumbnailsChecked', this.handleGalleryThumbnailsChecked); DeviceEventEmitter.removeListener('onGalleryThumbnailChecked', this.handleGalleryThumbnailChecked);
} }
handleGalleryThumbnailsChecked = () => { handleGalleryThumbnailChecked = evt => {
this.setState({ galleryThumbnailsChecked: true }); const checkedThumbnails = [...this.state.checkedThumbnails];
const { id } = evt;
// using checked because we only want thumbnails that can be displayed
if (!checkedThumbnails.includes(id)) {
checkedThumbnails.push(id);
}
this.setState({ checkedThumbnails });
}; };
onComponentFocused = () => { onComponentFocused = () => {
@ -580,7 +586,7 @@ class PublishPage extends React.PureComponent {
render() { render() {
const { balance, navigation, notify, publishFormValues } = this.props; const { balance, navigation, notify, publishFormValues } = this.props;
const { canUseCamera, currentPhase, galleryThumbnailsChecked, thumbnailPath, videos } = this.state; const { canUseCamera, currentPhase, checkedThumbnails, thumbnailPath, videos } = this.state;
let content; let content;
if (Constants.PHASE_SELECTOR === currentPhase) { if (Constants.PHASE_SELECTOR === currentPhase) {
@ -589,12 +595,24 @@ class PublishPage extends React.PureComponent {
<View style={publishStyle.actionsView}> <View style={publishStyle.actionsView}>
{canUseCamera && <RNCamera style={publishStyle.cameraPreview} type={RNCamera.Constants.Type.back} />} {canUseCamera && <RNCamera style={publishStyle.cameraPreview} type={RNCamera.Constants.Type.back} />}
<View style={publishStyle.actionsSubView}> <View style={publishStyle.actionsSubView}>
<TouchableOpacity style={publishStyle.record} onPress={this.handleRecordVideoPressed}> <TouchableOpacity
style={[
publishStyle.record,
canUseCamera ? publishStyle.transparentBackground : publishStyle.actionBackground,
]}
onPress={this.handleRecordVideoPressed}
>
<Icon name="video" size={48} color={Colors.White} /> <Icon name="video" size={48} color={Colors.White} />
<Text style={publishStyle.actionText}>Record</Text> <Text style={publishStyle.actionText}>Record</Text>
</TouchableOpacity> </TouchableOpacity>
<View style={publishStyle.subActions}> <View style={publishStyle.subActions}>
<TouchableOpacity style={publishStyle.photo} onPress={this.handleTakePhotoPressed}> <TouchableOpacity
style={[
publishStyle.photo,
canUseCamera ? publishStyle.transparentBackground : publishStyle.actionBackground,
]}
onPress={this.handleTakePhotoPressed}
>
<Icon name="camera" size={48} color={Colors.White} /> <Icon name="camera" size={48} color={Colors.White} />
<Text style={publishStyle.actionText}>Take a photo</Text> <Text style={publishStyle.actionText}>Take a photo</Text>
</TouchableOpacity> </TouchableOpacity>
@ -607,7 +625,7 @@ class PublishPage extends React.PureComponent {
</View> </View>
</View> </View>
</View> </View>
{(!videos || !thumbnailPath || !galleryThumbnailsChecked) && ( {(!videos || !thumbnailPath || checkedThumbnails.length === 0) && (
<View style={publishStyle.loadingView}> <View style={publishStyle.loadingView}>
<ActivityIndicator size="large" color={Colors.NextLbryGreen} /> <ActivityIndicator size="large" color={Colors.NextLbryGreen} />
</View> </View>
@ -619,12 +637,12 @@ class PublishPage extends React.PureComponent {
</Text> </Text>
</View> </View>
)} )}
{videos && thumbnailPath && galleryThumbnailsChecked && ( {videos && thumbnailPath && checkedThumbnails.length > 0 && (
<FlatGrid <FlatGrid
style={publishStyle.galleryGrid} style={publishStyle.galleryGrid}
itemDimension={134} itemDimension={134}
spacing={2} spacing={2}
items={this.state.videos} items={videos.filter(video => checkedThumbnails.includes(video.id))}
renderItem={({ item, index }) => { renderItem={({ item, index }) => {
return ( return (
<TouchableOpacity key={index} onPress={() => this.setCurrentMedia(item)}> <TouchableOpacity key={index} onPress={() => this.setCurrentMedia(item)}>

View file

@ -16,7 +16,7 @@ const publishStyle = StyleSheet.create({
flex: 1, flex: 1,
}, },
galleryGridImage: { galleryGridImage: {
width: 134, width: '100%',
height: 90, height: 90,
}, },
inputText: { inputText: {
@ -64,15 +64,20 @@ const publishStyle = StyleSheet.create({
overflow: 'hidden', overflow: 'hidden',
}, },
record: { record: {
backgroundColor: 'transparent',
flex: 0.5, flex: 0.5,
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
}, },
actionBackground: {
backgroundColor: Colors.Black,
},
transparentBackground: {
backgroundColor: 'transparent',
},
subActions: { subActions: {
flex: 0.5, flex: 0.5,
borderLeftWidth: 2, borderLeftWidth: 2,
borderLeftColor: Colors.DarkerGrey, borderLeftColor: Colors.DarkGrey,
}, },
actionText: { actionText: {
color: Colors.White, color: Colors.White,
@ -81,7 +86,6 @@ const publishStyle = StyleSheet.create({
marginTop: 8, marginTop: 8,
}, },
photo: { photo: {
backgroundColor: 'transparent',
height: 240, height: 240,
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
@ -90,7 +94,7 @@ const publishStyle = StyleSheet.create({
backgroundColor: Colors.Black, backgroundColor: Colors.Black,
height: 120, height: 120,
borderTopWidth: 2, borderTopWidth: 2,
borderTopColor: Colors.DarkerGrey, borderTopColor: Colors.DarkGrey,
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
}, },