反应原生,反应导航,TabNavigator,当我更改标签屏幕时如何发送请求

时间:2017-07-10 03:24:01

标签: javascript react-native

我正在使用const dog&来控制react-native App。

react-navigation

const MainTab = TabNavigator({ Home: tabscreen(HomeScreen, '/home', 'home', 'home'), Chat: tabscreen(ChatScreen, '/chat', 'chat', 'chat'), Find: tabscreen(FindScreen, '/find', 'find', 'find'), Profile: tabscreen(ProfileScreen, '/profile', 'profile', 'profile') }, { tabBarPosition: 'bottom', swipeEnabled: false, animationEnabled: false, lazy: true, //...other configs tabBarOptions: { // tint color is passed to text and icons (if enabled) on the tab bar activeTintColor: '#1BBC9B', inactiveTintColor: '#9B9B9B', showIcon: true, style: { backgroundColor: '#F4F4F4', borderTopWidth: 0, height: 49 }, labelStyle: { marginTop: 0, marginLeft: 0, marginRight: 0, marginBottom: 1.5 } } }); const AppNavigator = StackNavigator({ Main: { screen: MainTab , path: '/', navigationOptions: { // header: null, headerVisible: false, gesturesEnabled: false, } }, .... { initialRouteName: 'Main', mode: 'card', headerMode: 'screen', navigationOptions: { headerVisible: false, gesturesEnabled: true, headerStyle: styles.headerStyle, headerTitleStyle: styles.headerTitleStyle, headerTintColor: 'white', headerBackTitle: null, } }); 标签中,我向后端发送请求以获取Chat ChatScreen功能中的列表数据。它运作良好。   当我从componentDidMount导航另一个屏幕时,执行某些操作,然后通过单击另一个屏幕左上角的后退按钮返回ChatScreen。我需要从列表中请求列表数据后端再次,但ChatScreen不会再次执行。

如果componentDidMount导航到另一个名为" A"的屏幕。 " A"屏幕导航返回ChatScreen。在这种情况下,我发现ChatScreen没有执行ChatScreen函数。

我需要在将屏幕更改为componentDidMount时请求列表数据。我必须在另一个ChatScreen

中发送请求

还有一件事,我使用redux来控制状态。

2 个答案:

答案 0 :(得分:0)

目前尚不支持,您可以按照问题#51进行操作。

这是v1稳定#723

的路线图

至于变通方法,您可以使用这个使用高阶组件的pmachawoski's来了解标签是否有焦点,但问题是,它总是被执行,而不是componentDidMount执行一次。

答案 1 :(得分:0)

相关问题