Skip to content

Instantly share code, notes, and snippets.

@dharavp
Last active March 31, 2019 18:44
Show Gist options
  • Save dharavp/c902a62490c8cbc3d3ae2fb520849b07 to your computer and use it in GitHub Desktop.
Save dharavp/c902a62490c8cbc3d3ae2fb520849b07 to your computer and use it in GitHub Desktop.
const LeftNavigator = DrawerNavigator({
Home: {
screen: Home
},
sideMenuScreen1: {
screen: sideMenuScreen1
},
sideMenuScreen2: {
screen: sideMenuScreen2
},
},
{
drawerPosition: 'left',
contentComponent: SideMenu,
drawerWidth: Dimensions.get('window').width * 0.75
});
const defaultGetStateForAction = LeftNavigator.router.getStateForAction;
LeftNavigator.router.getStateForAction = (action, state) => {
// if (state && action.type === 'Navigation/NAVIGATE' && action.routeName === 'DrawerClose') {
// StatusBar.setHidden(false);
// }
if (state && action.type === 'Navigation/NAVIGATE' && action.routeName === 'DrawerOpen') {
DeviceEventEmitter.emit('eventKey', { isOpen: true });
}
return defaultGetStateForAction(action, state);
};
const AppRouteConfig = StackNavigator({
Splash: {
screen: Splash
},
SignUp: {
screen: SignUp, navigationOptions: {
gesturesEnabled: false,
}
},
Login: {
screen: Login, navigationOptions: {
gesturesEnabled: false,
}
},
Home: {
screen: LeftNavigator, navigationOptions: {
gesturesEnabled: false,
}
},
Drawer: {
screen: LeftNavigator, navigationOptions: {
gesturesEnabled: false
}
}
}, {
headerMode: 'none'
});
// test google key:
AIzaSyAYuhpyz_1RdpKFMo8zds-nBdeLd-CH9O4
//in router page:
let _container;
export function getContainer() {
return _container;
}
//back handle in custom navigation bar
componentWillMount() {
if (Platform.OS === 'android' && !this.props.isBackHide) {
BackHandler.addEventListener('hardwareBackPress', () => {
if (getContainer) {
let routeName = ''
let routes = getContainer().props.navigation.state.routes.filter((r) => {
routeName = r.routeName;
return (r.routeName !== "Home" && r.routeName !== "Login");
})
if (routeName === "ABC") {
//back handle for perticular screen
DeviceEventEmitter.emit('BackHandle', { isOpen: true });
return true;
}
if (routes.length === 0) {
BackHandler.exitApp();
return true;
}
getContainer().props.navigation.dispatch(NavigationActions.back());
return true;
} else {
console.log('getContainer is null', 'navigationRoutes');
return false;
}
});
}
}
componentWillUnmount() {
if (Platform.OS === 'android' && !this.props.isBackHide) {
BackHandler.removeEventListener('hardwareBackPress');
}
}
// open settings
openSettings() {
Alert.alert(
'title',
'message',
[
{
text: 'Setting', onPress: () => {
Linking.canOpenURL('app-settings:').then(supported => {
if (!supported) {
console.log('Can\'t handle settings url');
} else {
return Linking.openURL('app-settings:');
}
}).catch(err => console.error('An error occurred', err));
}
},
{ text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel' },
],
{ cancelable: false }
)
}
//open screen from outside of the component
this.props.navigation.dispatch(NavigationActions.navigate({
routeName: 'name of screen', params: {
data:data
}
}));
const resetAction = NavigationActions.reset({
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'First screen' }),
]
});
this.props.navigation.dispatch(resetAction);
//mapStateToProps
const mapStateToProps = ({ reducer1,reducer2 }) => {
const { reducerVar1 } = reducer1;
const { reducerVar2 } = reducer2;
return {reducerVar1,reducerVar2 };
};
export default connect(mapStateToProps, {action1,action2 })(ClassName);
//
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation]
||([[GIDSignIn sharedInstance] handleURL:url sourceApplication:sourceApplication annotation:annotation])
|| ([RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation]);
}
//router
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { addNavigationHelpers } from 'react-navigation';
import AppRouteConfig from './AppRouteConfig';
import {
createReduxBoundAddListener,
createReactNavigationReduxMiddleware
} from 'react-navigation-redux-helpers';
let _container;
export function getContainer() {
return _container;
}
const reduxMiddleware = createReactNavigationReduxMiddleware(
'root',
(state) => state.nav,
);
export const addListener = createReduxBoundAddListener('root');
class Router extends Component {
render() {
return (
<AppRouteConfig
ref={(navigatorRef) => {
_container = navigatorRef;
}}
navigation={{
dispatch: this.props.dispatch,
state: this.props.nav,
addListener,
}}
/>
);
}
}
function mapStateToProps(state) {
return {
nav: state.nav,
};
}
export default connect(mapStateToProps)(Router);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment