1

首先我想说对不起,因为我在这里的英语不好......

我想在 Route.js 文件中使用 setState 或使用 State 挂钩,但我不知道该怎么做。如果有人知道答案 - 请帮助我..

我使用了 asyncstorage,但它不会在数据更新后自动生效。它想要随时刷新或保存 Route.js 文件。

这是我的 Route.js 文件

import React from 'react';
import { Button, Image } from 'react-native';
import {createAppContainer} from 'react-navigation';
import {createBottomTabNavigator} from 'react-navigation-tabs';
import {createStackNavigator} from 'react-navigation-stack';

import HomeScreen from './pages/HomeScreen';
import SettingsScreen from './pages/SettingsScreen';
import DetailsScreen from './pages/DetailsScreen';
import ProfileScreen from './pages/ProfileScreen';

const HomeStack = createStackNavigator(
{
   Home: { screen: HomeScreen },
   Details: { screen: DetailsScreen },
},
{
  defaultNavigationOptions: {
  headerStyle: {
   backgroundColor: '#42f44b',
   },
   headerTintColor: '#FFFFFF',
   title: 'Home',
   },
 }
);
const SettingsStack = createStackNavigator(
{
  Settings: { screen: SettingsScreen },
  Details: { screen: DetailsScreen },   
},  // here i have use asycstroage but it is not working properly
{
  defaultNavigationOptions: {
  headerStyle: {
    backgroundColor: '#42f44b',
  },
   headerTintColor: '#FFFFFF',
   title: 'Settings',
   },
 }
);               
const App = createBottomTabNavigator(
{
  Home: { screen: HomeStack },
  Settings: { screen: SettingsStack },
},
{
 defaultNavigationOptions: ({ navigation }) => ({
  tabBarIcon: ({ focused, horizontal, tintColor }) => {
   const { routeName } = navigation.state;
    if (routeName === 'Home') {
     return ( <Image source={ focused ? require('./asset/home.png') : 
      require('./asset/bar.png')}
       style={{ width: 20,
       height: 20,
       borderRadius: 40 / 2,
     }} />
   );
  } else if (routeName === 'Settings') {
     return ( <Image source={ focused ? require('./asset/setting.png') : 
      require('./asset/bar.png')}
       style={{ width: 20,
       height: 20,
       borderRadius: 40 / 2,
     }} />  
    );
    }
   },
   }),
  }
 );
export default createAppContainer(App);

那么我该怎么做呢?

以及如何通过导航屏幕传递这种状态..

谢谢..

4

0 回答 0