import React from 'react';
import { Alert, Image, Text, View, Switch } from 'react-native';
import * as DocumentPicker from 'expo-document-picker';
import Button from '../components/Button';
interface State {
document?: DocumentPicker.DocumentResult;
copyToCache: boolean;
}
export default class DocumentPickerScreen extends React.Component<{}, State> {
static navigationOptions = {
title: 'DocumentPicker',
};
readonly state: State = {
copyToCache: false,
};
_openPicker = async () => {
const result = await DocumentPicker.getDocumentAsync({
copyToCacheDirectory: this.state.copyToCache,
});
if (result.type === 'success') {
this.setState({ document: result });
} else {
setTimeout(() => {
Alert.alert('Document picked', JSON.stringify(result, null, 2));
}, 100);
}
}
_renderDocument() {
if (!this.state.document) {
return null;
}
return (
{this.state.document.name!.match(/\.(png|jpg)$/gi) ? (
) : null}
{this.state.document.name} ({this.state.document.size! / 1000} KB)
URI: {this.state.document.uri}
);
}
render() {
return (
Copy to cache
this.setState({ copyToCache: value })}
/>
{this._renderDocument()}
);
}
}