Requirement is such that User goes to Login Screen (Built on React Native) -> PIN Screen (Native Screen) -> Device Registration Screen (Built on React Native)
I was able to go from Login Screen -> PIN Screen, but not able to go from PIN Screen to Device Registration Screen.
It goes without a doubt that the state should be preserved. i.e. if we click back from Device Registration Screen we should land on PIN Screen and again back is clicked from PIN Screen, we should land on Login Screen.
Navigation Implementation
const MainNavigator = createStackNavigator(
{
Login: {
screen: Login,
navigationOptions: {
title: 'Login',
header: null
}
},
DeviceRegistration: {
screen : DeviceRegistration,
navigationOptions: {
title: 'Device Registration',
header: null
}
},
{
initialRouteName: 'Login'
}
);
const Navigation = createAppContainer(MainNavigator);
LoginScreen Implementation
import React, { Component } from 'react';
import { StyleSheet, View, Text, Button, NativeModules, AppRegistry } from 'react-native';
import { SafeAreaView } from 'react-navigation';
class LoginScreen extends Component {
_goToNativePinPage(){
NativeModules.ChangeViewBridge.changeToNativeView();
}
render() {
const { navigate } = this.props.navigation;
var s = require('../../styles/style');
return (
<SafeAreaView>
<View style={s.container}>
<Text>This is Login page</Text>
<Button onPress={() => this._goToNativePinPage()} title="PIN PAGE"></Button>
</View >
</SafeAreaView>
);
}
}
AppRegistry.registerComponent('LoginScreen',() => LoginScreen);
export default Login;
Bridge implementation from React Native to Native
#import <React/RCTBridgeModule.h>
@interface ChangeViewBridge : NSObject <RCTBridgeModule>
- (void) changeToNativeView;
@end
#import "ChangeViewBridge.h"
#import "AppDelegate.h"
#import <React/RCTBridgeModule.h>
@implementation ChangeViewBridge
RCT_EXPORT_MODULE(ChangeViewBridge);
RCT_EXPORT_METHOD(changeToNativeView) {
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate goToNativeView];
}
@end
Inside App Delegate
- (void) goToNativeView {
dispatch_async(dispatch_get_main_queue(), ^{
UIViewController *vc = [UIStoryboard storyboardWithName:@"main" bundle:nil].instantiateInitialViewController;
self.window.rootViewController = vc;
});
}