-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Create Camera Singleton #2230
Description
Question
To Do First
Ask your Question
I'm working on an app that uses react-navigation (createBottomTabNavigator) to toggle between the following views:
- Help
- Take Picture (or navigate to camera if on other screens)
- About
The routing is as follows, the camera icon inside <BottomNavComponent /> either navigates the user to <CameraScreen /> if there are not there, or should take a picture if the user is there.
However, I am unable how to figure out how the pass a reference to the camera from <CameraScreen />, which has a render method that uses <RNCamera />, up to <BottomNavComponent />.
Below are some relevant pieces of code:
CameraScreen.js
class CameraScreen extends Component {
render() {
return (
<View style={CameraScreenStyles.ViewContainer}>
<RNCamera
style={CameraScreenStyles.Preview}
ref={(ref) => { this.camera = ref; }}
captureAudio={false}
type={RNCamera.Constants.Type.back}
flashMode={RNCamera.Constants.FlashMode.auto}
/>
</View>
);
}
}
BottomNavComponent
export default BottomTabNavigator = createBottomTabNavigator(
{
...
Home: {
screen: CameraScreen,
navigationOptions: () => ({
tabBarIcon: () => <CircleNavButton />
})
},
...
}, {
initialRouteName: 'Home',
...
}
CircleNavButton is the component that renders the circle.
App.js
const AppContainer = createAppContainer(BottomTabNavigator);
export default class App extends Component {
render() {
return (
<Provider store={store}>
<AppContainer />
</Provider>
);
}
}
You can find my project here. I believe it's currently public, please let me know if it's not.
Thanks for helping!
