【问题标题】:React native redux stacknavigation issue: View not getting loaded反应本机 redux 堆栈导航问题:视图未加载
【发布时间】:2017-12-10 06:39:27
【问题描述】:

我是 redux 的新手。我想用我的 react-native 应用程序实现 redux。这是我的代码。

从 index.android.js 初始化应用程序

render() {
    return (
  <View>
    <RootComponent />
  </View>
 );
}

根组件是我正在初始化我的 stacknavigator 的组件/容器。

const AppNavigator = StackNavigator({
Login: { screen: LoginContainer },
App: { screen: AppContainer }
},
{
    headerMode: 'none'
}
);

const navReducer = (state, action) => {
  const nextState = AppNavigator.router.getStateForAction(action, state);
  return nextState || state;
};

const appReducer = combineReducers({
  nav: navReducer
});

class App extends Component {
render() {
    return (
        <AppNavigator navigation={addNavigationHelpers({
            dispatch: this.props.dispatch,
            state: this.props.nav,
        }) } />
    );
}
}

const mapStateToProps = (state) => ({
  nav: state.nav
});

const AppWithNavigationState = connect(mapStateToProps)(App);

const store = createStore(appReducer);

export default class RootComponent extends Component {
constructor(props) {
    super(props);
}

render() {
    return (
        <Provider store={store}>
            <AppWithNavigationState />
        </Provider>
    );
}
}

根据我的导航,我应该转到登录组件/容器。容器如下:

export default class LoginContainer extends Component {
constructor(props) {
    super(props);
    alert('In login component');
}

render() {
    return (
        <View>
            <Text>
                Login Screen
            </Text>
        </View>
    );
}
}

运行代码后,我可以看到登录组件的构造函数中写入的警报。虽然,视图在模拟器上不可见,也没有显示任何错误。

任何人都可以帮助我吗?

【问题讨论】:

  • 请在 github 上查看我的问题。我问过我是否应该将 redux 集成到 react-navigator 中。 github.com/react-community/react-navigation/issues/2003 答案是否定的。所以海事组织你不应该尝试整合。这样做没有任何好处,而且你会浪费时间。
  • @FurkanO:感谢您的回复。即使我不确定是否使用它。这篇文章有帮助。再次感谢:)

标签: reactjs react-native react-redux react-navigation


【解决方案1】:

只需将样式添加到您的父 &lt;View&gt; 标记中,例如 &lt;View style={{flex: 1}}&gt;,它们充当 index.android.js 和 LoginContainer 内所有 JSX 的包装器。

您的&lt;View&gt;s 基本上在屏幕上不可见,因为它们没有任何高度和宽度。

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-16
    • 2021-08-04
    • 2019-12-16
    • 2023-01-27
    • 2018-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多