Skip to content

Instantly share code, notes, and snippets.

@benmort
Last active October 22, 2017 07:02
Show Gist options
  • Save benmort/b7a21f0c2acf1d649be3072cc2f58898 to your computer and use it in GitHub Desktop.
Save benmort/b7a21f0c2acf1d649be3072cc2f58898 to your computer and use it in GitHub Desktop.
attempting to setup navigation from within redux actions... buut failing... any help would be awesome
import { NavigationActions } from 'react-navigation'
export function navIntro() {
return function(dispatch) {
dispatch(NavigationActions.navigate({ routeName: 'Intro' }))
}
}
import React, { Component } from 'react';
import AppNavigator from './AppNavigator';
import { Provider } from 'react-redux';
import store from './store';
export default class App extends Component {
render() {
return (
<Provider store={store}>
<AppNavigator/>
</Provider>
)
}
}
import React from "react";
import { createRootNavigator } from "./router";
import { isSignedIn } from "./auth";
export default class AppNavigator extends React.Component {
constructor(props) {
super(props);
this.state = {
signedIn: false,
checkedSignIn: false
};
}
componentWillMount() {
isSignedIn()
.then(res => this.setState({ signedIn: res, checkedSignIn: true }))
.catch(err => alert("An error occurred"));
}
render() {
const { checkedSignIn, signedIn } = this.state;
// If we haven't checked AsyncStorage yet, don't render anything (better ways to do this)
if (!checkedSignIn) {
return null;
}
const AppLayout = createRootNavigator(signedIn);
return <AppLayout />;
}
}
import { createRootNavigator } from "../router";
export default (state, action) => createRootNavigator().router.getStateForAction(action, state);
import React from "react";
import { Platform, StatusBar } from "react-native";
import { StackNavigator } from 'react-navigation/lib/react-navigation.js';
import Home from "./screens/Home";
import Intro from "./screens/Intro";
const headerStyle = {
marginTop: Platform.OS === "android" ? StatusBar.currentHeight : 0
};
export const createRootNavigator = () => {
return StackNavigator(
{
Home: {
screen: Home,
path: '',
navigationOptions: {
tabBarLabel: "Home"
}
},
Intro: {
screen: Intro,
path: '',
navigationOptions: {
tabBarLabel: "Home"
}
}
},
{
headerMode: "none",
mode: "modal",
initialRouteName: "Home"
}
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment