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')} />
              )
          }
      },

});

4

1 回答 1

1

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

import drawerContentComponents from './Drawer';

const AppDrawerNavigator = createDrawerNavigator({

  Home: {screen: Home,}
  },

},
  {contentComponent: drawerContentComponents,}

  );

//抽屉源码

//i use this library 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>

        )
    }
}

于 2019-11-28T08:21:16.123 回答