Skip to content

Instantly share code, notes, and snippets.

@benmort benmort/App.js
Last active Oct 22, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.