gpt4 book ai didi

react-native - react 导航 : Is it possible to goBack() or pop() with params?

转载 作者:行者123 更新时间:2023-12-04 15:55:32 24 4
gpt4 key购买 nike

我正在使用 React Navigation (V2),我有一个基本的屏幕设置,如下所示:

import {
createDrawerNavigator,
createStackNavigator,
createSwitchNavigator
} from "react-navigation";

import DetailScreen from "../screens/DetailScreen";
import HomeScreen from "../screens/HomeScreen";
import LoginScreen from "../screens/LoginScreen";
import SettingsScreen from "../screens/SettingsScreen";

const StackNavigator = createStackNavigator({
Home: { screen: HomeScreen },
Detail: { screen: DetailScreen }
});

StackNavigator.navigationOptions = ({ navigation }) => {
let drawerLockMode = "unlocked";
if (navigation.state.index > 0) {
drawerLockMode = "locked-closed";
}
return {
drawerLockMode
};
};

const DrawerNavigator = createDrawerNavigator({
HomeStack: { screen: StackNavigator },
Settings: { screen: SettingsScreen }
});

const Navigator = createSwitchNavigator(
{ LoginScreen, DrawerNavigator },
{ initialRouteName: "LoginScreen" }
);

export default Navigator;

在使用我的应用程序时,用户最终会进入 DetailScreen,做出一些选择,然后应该返回到 HomeScreen。我想在返回时将参数传递给 HomeScreen。不幸的是它看起来像pop()goBack()不接受任何参数。

我怎样才能返回屏幕并同时传递参数?

最佳答案

您可以使用 listeners屏幕并在那里触发刷新更改。

didFocus - 屏幕聚焦(如果有过渡,过渡完成)

// In your component
componentDidMount () {
this._onFocusListener = this.props.navigation.addListener('didFocus', (payload) => {
// Update the component (API calls here)
});
}

关于react-native - react 导航 : Is it possible to goBack() or pop() with params?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51855131/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com