Reputation: 1627
Hi Guys I need to create a button component that will give options 1) choose pics from Gallery 2) take photo from camera and I want to be able to access the cameraComponent described here: https://github.com/expo/camerja , (App.js of this is renamed as CameraScreen) my parent component App.js looks as below -which has a camera button but does nothing when clicked
import React from 'react';
import { StyleSheet, Text, View,WebView ,Button} from 'react-native';
import CameraScreen from './CameraScreen';
export default class App extends React.Component {
render() {
return (
<View>
<Button onPress = {CameraScreen} title="Camera"
color="#841584"
accessibilityLabel="Learn more about this purple button"></Button>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Upvotes: 0
Views: 2112
Reputation: 603
You can use react-native-image-picker and call it onClick. It opens camera easily. react-native-image-picker
Image-picker has following options -
Also if you want any other options you can pass it
Upvotes: 1
Reputation: 11
You aren't giving a function to the onPress prop and you missed the tags for the CameraScreen component.
Try this: First create a function that returns the CameraScreen component
renderCamera(){
return( <CameraScreen /> );
}
Then bind it to the onPress prop:
onPress={this.renderCamera().bind(this)}
Upvotes: 1