美文网首页
reqct-native 点击导航左边三角返回指定页面

reqct-native 点击导航左边三角返回指定页面

作者: 知命者夏洛特 | 来源:发表于2019-01-31 17:06 被阅读0次
    import { TouchableOpacity,Platform,BackHandler,Image } from 'react-native'
    
    
    class Dome extends React.Component {
    
        static navigationOptions = ({navigation, screenProps}) => ({
            headerTitle: '导航',
            headerLeft:(
                <TouchableOpacity  onPress={()=>navigation.state.params.navigatePress()}  style={{padding:10}} >
                   <Image
                    source={require('../../../images/icon-arrow-left.png')}
                    style={{ width: 9, height: 16 }}
                    />
                </TouchableOpacity>
            )
        });
    
     _onBackAndroid=()=>{
            this.props.navigation.navigate('Home')
            return true
        }
    
        componentWillMount(){
            this.props.navigation.setParams({ navigatePress:this._onBackAndroid })
            if (Platform.OS === 'android') {
                BackHandler.addEventListener("hardwareBackPress", this._onBackAndroid);
            }
        }
     componentWillUnmount() {
            if (Platform.OS === 'android') {
                BackHandler.removeEventListener("hardwareBackPress", this._onBackAndroid);
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:reqct-native 点击导航左边三角返回指定页面

          本文链接:https://www.haomeiwen.com/subject/bsclsqtx.html