allow users to upload any file #39

Merged
akinwale merged 1 commit from file-uploads into master 2019-09-10 13:57:26 +02:00
2 changed files with 41 additions and 7 deletions
Showing only changes of commit 625559528d - Show all commits

View file

@ -79,6 +79,7 @@ class PublishPage extends React.PureComponent {
state = { state = {
canPublish: false, canPublish: false,
canUseCamera: false, canUseCamera: false,
documentPickerOpen: false,
editMode: false, editMode: false,
titleFocused: false, titleFocused: false,
descriptionFocused: false, descriptionFocused: false,
@ -137,6 +138,8 @@ class PublishPage extends React.PureComponent {
// this.didFocusListener = navigation.addListener('didFocus', this.onComponentFocused); // this.didFocusListener = navigation.addListener('didFocus', this.onComponentFocused);
DeviceEventEmitter.addListener('onGalleryThumbnailChecked', this.handleGalleryThumbnailChecked); DeviceEventEmitter.addListener('onGalleryThumbnailChecked', this.handleGalleryThumbnailChecked);
DeviceEventEmitter.addListener('onAllGalleryThumbnailsChecked', this.handleAllGalleryThumbnailsChecked); DeviceEventEmitter.addListener('onAllGalleryThumbnailsChecked', this.handleAllGalleryThumbnailsChecked);
DeviceEventEmitter.addListener('onDocumentPickerFilePicked', this.onFilePicked);
DeviceEventEmitter.addListener('onDocumentPickerCanceled', this.onPickerCanceled);
} }
componentWillUnmount() { componentWillUnmount() {
@ -145,6 +148,8 @@ class PublishPage extends React.PureComponent {
} }
DeviceEventEmitter.removeListener('onGalleryThumbnailChecked', this.handleGalleryThumbnailChecked); DeviceEventEmitter.removeListener('onGalleryThumbnailChecked', this.handleGalleryThumbnailChecked);
DeviceEventEmitter.removeListener('onAllGalleryThumbnailsChecked', this.handleAllGalleryThumbnailsChecked); DeviceEventEmitter.removeListener('onAllGalleryThumbnailsChecked', this.handleAllGalleryThumbnailsChecked);
DeviceEventEmitter.removeListener('onDocumentPickerFilePicked', this.onFilePicked);
DeviceEventEmitter.removeListener('onDocumentPickerCanceled', this.onPickerCanceled);
} }
handleGalleryThumbnailChecked = evt => { handleGalleryThumbnailChecked = evt => {
@ -406,6 +411,7 @@ class PublishPage extends React.PureComponent {
this.setState( this.setState(
{ {
publishStarted: false, publishStarted: false,
documentPickerOpen: false,
editMode: false, editMode: false,
currentMedia: null, currentMedia: null,
@ -457,6 +463,36 @@ class PublishPage extends React.PureComponent {
} }
}; };
handleUploadPressed = () => {
if (this.state.documentPickerOpen) {
return;
}
this.setState(
{
documentPickerOpen: true,
},
() => {
NativeModules.UtilityModule.openDocumentPicker('*/*');
}
);
};
onFilePicked = evt => {
this.setState({ documentPickerOpen: false }, () => {
const currentMedia = {
id: -1,
filePath: `file://${evt.path}`,
duration: 0,
};
this.setCurrentMedia(currentMedia);
});
};
onPickerCanceled = () => {
this.setState({ documentPickerOpen: false });
};
handleCloseCameraPressed = () => { handleCloseCameraPressed = () => {
this.setState({ showCameraOverlay: false, videoRecordingMode: false }); this.setState({ showCameraOverlay: false, videoRecordingMode: false });
}; };
@ -725,12 +761,10 @@ class PublishPage extends React.PureComponent {
<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>
{false && (
<TouchableOpacity style={publishStyle.upload} onPress={this.handleUploadPressed}> <TouchableOpacity style={publishStyle.upload} onPress={this.handleUploadPressed}>
<Icon name="file-upload" size={48} color={Colors.White} /> <Icon name="file-upload" size={48} color={Colors.White} />
<Text style={publishStyle.actionText}>Upload a file</Text> <Text style={publishStyle.actionText}>Upload a file</Text>
</TouchableOpacity> </TouchableOpacity>
)}
</View> </View>
</View> </View>
</View> </View>

View file

@ -86,7 +86,7 @@ const publishStyle = StyleSheet.create({
marginTop: 8, marginTop: 8,
}, },
photo: { photo: {
height: 240, height: 120,
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
}, },