Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
685 views
in Technique[技术] by (71.8m points)

redux - React Drawer Navigation is not working as expected in React Native App

I am trying to implement react drawer navigation with Redux and Redux Persist. What I notice is that once I navigate to a screen using the drawer (Let us take the "Next" screen in the below pic) and return back to the screen which is on top of that (Home screen), All the controls on that screen are not working. (Unable to click even the buttons present on that screen)

Drawer items

Home screen

Next screen

Am I missing any implementation here? It looks so weird. I don't think it is because of the Redux or Redux Persist package because not the states, even the controls not working. I added multiple screens and the same happens.

Below is my App.js code.

import React from 'react';
import { SafeAreaView, StyleSheet, ScrollView, View, Text, StatusBar, AsyncStorage } from 'react-native';
import {Provider} from 'react-redux'
import AddOneComponent from './Components/AddOneComponent'
import ChangeNameComponent from './Components/ChangeNameComponent'
import {persistStore, persistReducer} from 'redux-persist'
import {createLogger} from 'redux-logger'
import { Header, LearnMoreLinks, Colors, DebugInstructions, ReloadInstructions,} from 'react-native/Libraries/NewAppScreen';
import {applyMiddleware, createStore} from 'redux'
import {PersistGate} from 'redux-persist/es/integration/react'
import rootReducer from './Redux/RootReducer'
import { changeNameAction } from './Redux/Action';
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import {createDrawerNavigator} from '@react-navigation/drawer';

const persistConfig = {
  key : 'root',
  storage : AsyncStorage,
  whitelist : ['changeNumber','changeName']
}

const persistedReducer = persistReducer(persistConfig, rootReducer)

const Store = createStore(persistedReducer, applyMiddleware(createLogger()));

const persistedStore = persistStore(Store)

const Stack = createStackNavigator();

const drawer = createDrawerNavigator();

const createAppStack = () =>
          <Stack.Navigator>
            <Stack.Screen name="Home" component={AddOneComponent} />
          </Stack.Navigator>

const App: () => React$Node = () => {
  return (
    <Provider store = {Store}>
      <PersistGate persistor={persistedStore} loading={null}>
        <NavigationContainer>
          <drawer.Navigator initialRouteName="Home">
            <drawer.Screen name="Home" children = {createAppStack} />
            <drawer.Screen name="Next" component = {ChangeNameComponent} />
          </drawer.Navigator>
        </NavigationContainer>
     </PersistGate>
    </Provider>
  );
};

const styles = StyleSheet.create({

});

export default App;

One of the Components implementation (Home):

import React from 'react'
import {View, Text, Button} from 'react-native'
import {connect} from 'react-redux'
import { bindActionCreators } from 'redux';
import {addOneAction,subOneAction} from '../Redux/Action'

const AddOneComponent = (props) => {
    return(
        <View>
            <Text>{props.currentCount}</Text>
            <Button title="ADD ONE" onPress = {props.addOneAction}></Button>
            <Button title="SUB ONE" onPress = {props.subOneAction}></Button>
        </View>
    )
}

const mapStateToProps = state => {
    return {
        currentCount : state.changeNumber.currentCount
    }
}

const mapDispatchToProps = dispatch => {
    return bindActionCreators({addOneAction,subOneAction}, dispatch)
}

export default connect(
    mapStateToProps, mapDispatchToProps
)(AddOneComponent)
question from:https://stackoverflow.com/questions/65874311/react-drawer-navigation-is-not-working-as-expected-in-react-native-app

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...