react-native-paper#Modal JavaScript Examples
The following examples show how to use
react-native-paper#Modal.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From puente-reactnative-collect with MIT License | 6 votes |
export default function TermsModal(props) {
const { visible, setVisible } = props;
return (
<Portal theme={theme}>
<Modal
visible={visible}
theme={theme}
contentContainerStyle={styles.modal}
dismissable={false}
>
<ScrollView>
<Headline theme={theme}>{I18n.t('termsModal.termsService')}</Headline>
<Text>{I18n.t('termsModal.policy')}</Text>
<Button mode="contained" theme={theme} color="#3E81FD" style={styles.button} onPress={() => setVisible(false)}>{I18n.t('termsModal.ok')}</Button>
</ScrollView>
</Modal>
</Portal>
);
}
Example #2
Source File: index.js From puente-reactnative-collect with MIT License | 4 votes |
export default function UseCamera(
{
cameraVisible, setCameraVisible, formikProps, formikKey, setImage
}
) {
const [hasPermission, setHasPermission] = useState(null);
const [type, setType] = useState(Camera.Constants.Type.back);
const [cameraImage, setCameraImage] = useState(null);
const [zoom, setZoom] = useState(0);
useEffect(() => {
(async () => {
const { status } = await Camera.requestPermissionsAsync();
setHasPermission(status === 'granted');
})();
}, []);
const takePicture = async () => {
if (camera) {
const photo = await camera.takePictureAsync({
base64: true,
aspect: [4, 3],
quality: 1
});
setCameraImage(photo.uri);
setImage(photo.uri);
formikProps.setFieldValue(formikKey, `data:image/jpg;base64,${photo.base64}`);
}
};
const resetPicture = () => {
setCameraImage(null);
formikProps.setFieldValue(formikKey, null);
};
let camera = useRef(null);
if (hasPermission === null) {
return <View />;
}
if (hasPermission === false) {
return <Text>{I18n.t('camera.noAccess')}</Text>;
}
return (
<Portal theme={theme}>
<Modal
visible={cameraVisible}
theme={theme}
contentContainerStyle={styles.modal}
dismissable={false}
>
<View style={{ width: 'auto', height: 500, padding: 10 }}>
{cameraImage ? (
<>
<Image source={{ uri: cameraImage }} style={{ width: 'auto', height: 400 }} />
<Button onPress={resetPicture}>{I18n.t('camera.retake')}</Button>
</>
) : (
<>
<Camera
style={{ flex: 5 }}
type={type}
ref={(ref) => {
camera = ref;
}}
autofocus
zoom={zoom}
base64
>
<View
style={styles.cameraButtonContainer}
>
<TouchableOpacity
style={styles.flipContainer}
onPress={() => {
setType(
type === Camera.Constants.Type.back
? Camera.Constants.Type.front
: Camera.Constants.Type.back
);
}}
>
<Text style={styles.cameraButtonText}>{I18n.t('camera.flip')}</Text>
</TouchableOpacity>
<View style={styles.cameraButtonContainer}>
<View style={styles.zoomContainer}>
<TouchableOpacity
onPress={() => {
setZoom(
zoom === 0.4
? zoom
: zoom + 0.1
);
}}
>
<Text style={styles.cameraButtonText}> + </Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => {
setZoom(
zoom === 0
? zoom
: zoom - 0.1
);
}}
>
<Text style={styles.cameraButtonText}> - </Text>
</TouchableOpacity>
</View>
</View>
</View>
</Camera>
<Button onPress={takePicture}>{I18n.t('camera.takePicture')}</Button>
</>
)}
</View>
<Button mode="contained" style={styles.button} onPress={() => setCameraVisible(false)}>{I18n.t('camera.done')}</Button>
</Modal>
</Portal>
);
}