diff --git a/portable-devices/mobile/src/modules/navigation/index.tsx b/portable-devices/mobile/src/modules/navigation/index.tsx index 519701878..34bf3c2ba 100644 --- a/portable-devices/mobile/src/modules/navigation/index.tsx +++ b/portable-devices/mobile/src/modules/navigation/index.tsx @@ -5,7 +5,7 @@ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; import { NavigationContainer } from '@react-navigation/native'; import { RootAppNavigators, resolveRootRoute } from '../../react-navigation'; -import { Dashboard, Hello, Settings, PersonalInfo } from '../../pages'; +import { Dashboard, Hello, Settings, PersonalInfo,CameraScreen } from '../../pages'; export const Navigation = () => { const rootRoutes: RootAppNavigators = { @@ -80,6 +80,17 @@ export const Navigation = () => { }, }, }, + CameraScreen: { + props: { + initialParams: {}, + component: Settings, + options: { + headerShown: true, + headerTitle: 'Camera', + headerBackTitle: 'Back', + }, + }, + }, }, }, }; diff --git a/portable-devices/mobile/src/pages/CameraScreen.tsx b/portable-devices/mobile/src/pages/CameraScreen.tsx new file mode 100644 index 000000000..91b261a07 --- /dev/null +++ b/portable-devices/mobile/src/pages/CameraScreen.tsx @@ -0,0 +1,97 @@ +import React, { useState, useEffect } from 'react'; +import { StyleSheet ,Text, View, TouchableOpacity, Image} from 'react-native'; +import { Camera } from 'expo-camera'; + +export default function CameraScreen() { + const [hasCameraPermission, setHasCameraPermission] = useState(null); + const [camera, setCamera] = useState(null); + const [image, setImage] = useState(null); + const [type, setType] = useState(Camera.Constants.Type.back); +useEffect(() => { + (async () => { + const cameraStatus = await Camera.requestCameraPermissionsAsync(); + setHasCameraPermission(cameraStatus.status === 'granted'); +})(); + }, []); + const ask = async() =>{ + await Camera.requestCameraPermissionsAsync(); + //setHasCameraPermission(cameraStatus.status === 'granted'); + } +const takePicture = async () => { + if(camera){ + const data = await camera.takePictureAsync(null) + setImage(data.uri); + } + } + + if (hasCameraPermission === false) { + // return No access to camera; + ask(); + } + return ( + + + setCamera(ref)} + style={styles.fixedRatio} + type={type} + ratio={'16:9'} /> + + + { + setType( + type === Camera.Constants.Type.back + ? Camera.Constants.Type.front + : Camera.Constants.Type.back + ); + }}> + Flip Camera + + takePicture()}> + Take Picture + + {image && } + + + + ); +} +const styles = StyleSheet.create({ + cameraContainer: { + flex: 1, + flexDirection: 'row', + //alignItems:'center', + justifyContent:'center' + }, + fixedRatio:{ + //flex: 1, + width:'100%', + height:'80%', + }, + buttonContainer:{ + width:'80%', + alignSelf:'center', + alignItems:'center', + justifyContent:'center', + marginBottom:20 + }, + btnColor: { + padding: 10, + paddingHorizontal:20, + borderRadius: 40, + backgroundColor: '#eee', + marginTop: 10, + }, + textStyle:{ + fontSize:20, + fontWeight:'bold', + textAlign:'center' + + } +}) + diff --git a/portable-devices/mobile/src/pages/index.ts b/portable-devices/mobile/src/pages/index.ts index 8b53acc63..0a7cc0e31 100644 --- a/portable-devices/mobile/src/pages/index.ts +++ b/portable-devices/mobile/src/pages/index.ts @@ -1,6 +1,6 @@ import Dashboard from './dashboard'; import Hello from './hello'; - +impoert CameraScreen from './CameraScreen'; export * from './Settings'; export * from './PersonalInfo'; -export { Dashboard, Hello }; +export { Dashboard, Hello,CameraScreen };