Browse Source

trying to launch camera

master
analuizaff 4 years ago
parent
commit
35898d8ff7
  1. 3
      src/App.js
  2. 54
      src/app/components/LaunchCamera.js

3
src/App.js

@ -8,6 +8,8 @@ import openDatabase from "./app/database/database-connection";
import initDatabase from "./app/database/database-init";
import FlashMessage from "react-native-flash-message";
import LaunchCamera from "./app/components/LaunchCamera";
export default function App() {
global.userDataBase = openDatabase();
initDatabase(global.userDataBase);
@ -17,5 +19,6 @@ export default function App() {
<AppNavigator />
<FlashMessage position="top" />
</NavigationContainer>
/*<LaunchCamera/>*/
);
}

54
src/app/components/LaunchCamera.js

@ -0,0 +1,54 @@
import React from "react";
import { StyleSheet, Text, View, SafeAreaView, Image, Button } from "react-native";
import * as ImagePicker from "expo-image-picker";
import { useState, useEffect } from "react";
import * as Permissions from 'expo-permissions';
function LaunchCamera() {
const [image, setImage] = useState();
const takePicture = async () => {
await Permissions.askAsync(Permissions.CAMERA);
const { cancelled, uri } = await ImagePicker.launchCameraAsync({
allowsEditing: false,
});
setImage({ image: uri });
};
const handlePress = () => {
takePicture();
};
return (
<View style={styles.container}>
<Image style={styles.image} source={{ uri: image }} />
<View style={styles.row}>
<Button title="Camera" onPress={handlePress} />
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#ffffff',
alignItems: 'center',
justifyContent: 'center',
},
text: {
fontSize: 21,
},
row: {
flexDirection: 'row'
},
image: {
width: 300, height: 300, backgroundColor: 'gray'
},
button: {
padding: 13,
margin: 15,
backgroundColor: '#dddddd',
},
})
export default LaunchCamera;
Loading…
Cancel
Save