在“新闻项”操作上反应本机抽屉导航

问题描述 投票:0回答:1

在我的抽屉导航器中,当我按注销时,有一个注销按钮。我想删除app_token,但我不知道如何。

我尝试放这样的东西:

onItemPress:() => { AsyncStorage.removeItem('app_token')},

但是没有用。

const AppDrawerNavigator = createDrawerNavigator({



      Logout: {

    onItemPress:() => { AsyncStorage.removeItem('app_token')},

          screen: HomePage,
          navigationOptions: {


              drawerIcon: (
                  <Image style={{ width: 30, height: 30 }}
                         source={require('./assets/IconDrawerNavigation/logout.png')} />
              )
          }
      },

});

react-native react-navigation asyncstorage react-navigation-drawer
1个回答
0
投票

为了解决这个问题,我使用了一个名为contentComponent的道具,可以创建自己的抽屉

import drawerContentComponents from './Drawer';

const AppDrawerNavigator = createDrawerNavigator({

  Home: {screen: Home,}
  },

},
  {contentComponent: drawerContentComponents,}

  );

//抽屉源代码

//i use this package so i can restart the app and logout 
import RNRestart from 'react-native-restart'; 

export default class drawerContentComponents extends Component {


    _logout = () => {
        AsyncStorage.removeItem('sale_id');
        RNRestart.Restart();

    }
    render() {


        return (

            <View style={styles.container2}>

                <TouchableOpacity onPress={() => this.props.navigation.navigate('profile')} >
                    <View style={styles.screenStyle}>
                        <Image style={styles.iconStyle}
                            source={home} />
                        <Text style={styles.screenTextStyle}>My Profile</Text>
                    </View>
                    <View style={styles.underlineStyle} />
                </TouchableOpacity>


                <TouchableOpacity onPress={() => this.props.navigation.navigate('social')} >
                    <View style={styles.screenStyle}>
                        <Image style={styles.iconStyle}
                            source={home} />
                        <Text style={styles.screenTextStyle}>Contact US</Text>
                    </View>
                    <View style={styles.underlineStyle} />
                </TouchableOpacity>



                <TouchableOpacity onPress={this._logout} >
                    <View style={styles.screenStyle}>
                        <Image style={styles.iconStyle}
                            source={home} />
                        <Text style={styles.screenTextStyle}>Logout</Text>
                    </View>

                </TouchableOpacity>


            </View>

        )
    }
}

© www.soinside.com 2019 - 2024. All rights reserved.