shubhnik / redux-react-navigation-demos Goto Github PK
View Code? Open in Web Editor NEWReact-Native + Redux + Redux-Persist + React Navigation ( Authentication Flow with Redux demos)
React-Native + Redux + Redux-Persist + React Navigation ( Authentication Flow with Redux demos)
Its a doubt rather than a issue , how the Logout action is handled in navigation reducer,
I checked code , where u reset using Navigation Action and again init with login routeName.
How does it work internally. i have usecase where
TabNavigator({
banner: {screen: banner},
login: {screen: login},
home: TabNav({
logout: { screen: logout },
eventListing: StackNav({
event: { screen: event }
})
})
})
let say my im in Logout screen , how do i update stateForLoggedOut using NavigationAction reset.
branch NestedNavigators face issue in tab navigation in add stacknavigation is not working proper so how use ?
`export const Profile = StackNavigator({
addpeople: {
screen: peopleScreen
},
removepeople: {
screen: RemovePeopleScreen
}
});
export const Tabs = TabNavigator({
Explore: {
screen: Explore
},
booking: {
screen: BookingScreen
},
Status: {
screen: StatusScreen,
},
WishpointView: {
screen: Wishpoint,
},
logout: {
screen: Logout,
navigationOptions: {
tabBarLabel: "Logout",
title: "Logout"
}
}
});
const navigator = StackNavigator({
login: {
screen: Login
},
signup: {
screen: Signup
},
mainScreens: {
screen: Tabs,
navigationOptions: {
gesturesEnabled: false,
headerLeft: null
}
}
});
export default navigator;`
Hey! Just cloned master branch and ran the app for the first time it's throwing error:-
TypeError: undefined is not a function (evaluating 'e')
Any idea what's this about.
Hi,
I am running your example ( nestedNavigators ) and when I press Logout on the logout screen I get
the following error
Unhandled JS Exception: Invariant Violation: Cannot get config because the route does not have a routeName.
I am just starting to use the react navigation with redux so I would appreciate the help, I am sure it's something small and stupid so thanks in advance
i copy your code, but im getting error like this:
TypeError: undefined is not an object (evaluating '_this.props.navigation.state.index')
I'm trying to upgrade the nestedNavigators
branch but I'm getting this error:
null is not an object (evaluating 'action.type')
getStateForAction
StackRouter.js:164:17
<unknown>
navigationReducer.js:25:2
loadModuleImplementation
require.js:178:12
<unknown>
store.js:11
loadModuleImplementation
require.js:178:12
<unknown>
App.js:12
loadModuleImplementation
require.js:178:12
<unknown>
index.js:2
loadModuleImplementation
require.js:178:12
guardedLoadModule
require.js:123:45
global code
<unknown file>:0
diff --git a/App.js b/App.js
index ef96f38..16a51f1 100644
--- a/App.js
+++ b/App.js
@@ -9,8 +9,8 @@ import { Platform, StyleSheet, Text, View } from "react-native";
import { Provider } from "react-redux";
import { PersistGate } from "redux-persist/es/integration/react";
// import store from './store'
-import AppNavigation from "./src/Navigation";
import configureStore from "./store";
+import AppNavigation from "./src/Navigation";
const { store, persistor } = configureStore();
diff --git a/package.json b/package.json
index bf156db..750d0c9 100644
--- a/package.json
+++ b/package.json
@@ -9,10 +9,11 @@
"dependencies": {
"react": "16.0.0-beta.5",
"react-native": "0.49.3",
- "react-navigation": "1.0.0-beta.15",
+ "react-navigation": "1.5.8",
+ "react-navigation-redux-helpers": "^1.0.2",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
- "redux-persist": "^5.2.2"
+ "redux-persist": "^5.7.0"
},
"devDependencies": {
"babel-jest": "21.2.0",
diff --git a/src/Navigation/index.js b/src/Navigation/index.js
index d938945..f252a9b 100644
--- a/src/Navigation/index.js
+++ b/src/Navigation/index.js
@@ -2,8 +2,12 @@ import React, { Component } from "react";
import { BackHandler } from "react-native";
import { connect } from "react-redux";
import { addNavigationHelpers, NavigationActions } from "react-navigation";
+import { createReduxBoundAddListener } from "react-navigation-redux-helpers";
+
import NavigationStack from "./navigationStack";
+const addListener = createReduxBoundAddListener("root");
+
class AppNavigation extends Component {
componentDidMount() {
BackHandler.addEventListener("hardwareBackPress", this.onBackPress);
@@ -29,7 +33,9 @@ class AppNavigation extends Component {
? navigationState.stateForLoggedIn
: navigationState.stateForLoggedOut;
return (
- <NavigationStack navigation={addNavigationHelpers({ dispatch, state })} />
+ <NavigationStack
+ navigation={addNavigationHelpers({ dispatch, state, addListener })}
+ />
);
}
}
diff --git a/store.js b/store.js
index 85743e1..5d24455 100644
--- a/store.js
+++ b/store.js
@@ -1,10 +1,11 @@
-import { createStore, combineReducers } from "redux";
+import { createStore, combineReducers, applyMiddleware } from "redux";
import {
persistCombineReducers,
persistStore,
persistReducer
} from "redux-persist";
import storage from "redux-persist/es/storage";
+import { createReactNavigationReduxMiddleware } from "react-navigation-redux-helpers";
import counterReducer from "./src/Reducers/counterReducer";
import NavigationReducer from "./src/Reducers/navigationReducer";
@@ -36,15 +37,24 @@ const reducer = {
const CounterReducer = persistReducer(config, counterReducer);
const LoginReducer = persistReducer(config1, loginReducer);
-// combineReducer applied on persisted(counterReducer) and NavigationReducer
+// combineReducer applied on CounterReducer + persisted(loginReducer) + NavigationReducer
const rootReducer = combineReducers({
CounterReducer,
NavigationReducer,
LoginReducer
});
+// Note: createReactNavigationReduxMiddleware must be run before createReduxBoundAddListener
+const middleware = createReactNavigationReduxMiddleware(
+ "root",
+ state =>
+ state.LoginReducer.isLoggedIn == true
+ ? state.NavigationReducer.stateForLoggedIn
+ : state.NavigationReducer.stateForLoggedOut
+);
+
function configureStore() {
- let store = createStore(rootReducer);
+ let store = createStore(rootReducer, applyMiddleware(middleware));
let persistor = persistStore(store);
return { persistor, store };
}
Hey @shubhnik
So just tried out the nestedTab
branch. While the initial login flow works seamless. I am trying to replicate a scenario when a user is already logged in, and opens the app.
In this scenario the user should directly land on to the feed
tab under TabNavigator
I tried fixing it by giving the loggedIn state the screen name as screen2
or feed
none of them works. Any ideas here ?
The back button on header when inside Tab navigator should not go back to any of the login
StackNavigators.
The structure looks like this:
const Tabs = TabNavigator({
feed: {
screen: Feed
},
logout: {
screen: Logout
}
});
const LoginsFlow = StackNavigator({
login: {
screen: Login
},
screen1: {
screen: Screen1
},
});
const navigator = StackNavigator({
login: {
screen: LoginsFlow
},
screen2: {
screen: Tabs
}
});
navigate = () => {
const navigateToScreen2 = NavigationActions.navigate({
routeName:'screen2',
params:{name:'Shubhnik'}
})
// navigateToscreen2 will look like this:
/*
{
"type": "Navigation/NAVIGATE",
"routeName": "screen2",
"params":{
"name":"Shubhnik"
}
}
*/
// The navigateToScreen2 action is dispatched and new navigation state will be calculated in basicNavigationReducer here ---> https://gist.github.com/shubhnik/b55602633aaeb5919f6f3c15552d1802
this.props.navigation.dispatch(navigateToScreen2)
}
this method not working
hi! in my code, after the user successfully log in apears the mainSreen, but if the user close the App and then open it again, comes for a few miliseconds the LoginScreen. do you know how to correct that problem?
kind Regards
Helmer
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.