美文网首页
页面返回(自定义返回页面)

页面返回(自定义返回页面)

作者: 知命者夏洛特 | 来源:发表于2019-04-09 20:43 被阅读0次
    
    import React from 'react';
    import { StyleSheet, View, TouchableOpacity, Image, Platform, BackHandler} from 'react-native';
    import { connect } from 'react-redux';
    
    class Select extends React.Component {
    
        static navigationOptions = ({navigation, screenProps}) => ({
            headerTitle: '头部信息',
            headerLeft:(
                <TouchableOpacity  onPress={()=>navigation.state.params.navigatePress()} style={{padding:10}} >
                   <Image
                    source={require('../../../images/icon-left.png')}
                    style={{ width: 9, height: 16 }}
                    />
                </TouchableOpacity>
            )
        });
    
        constructor(props) {
            super(props);
            this.state={
              
            }
        }
    
        _onBackAndroid=()=>{
            this.props.navigation.navigate('要返回的页面路由')
        }
        
        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);
            }
        }
    
        
        render() {
            return (
                <View style={styles.container}>
                   
                </View>
            );
        }
    }
    
    export default connect()(Select);
    
    const styles = StyleSheet.create({
        container: {
            flex: 1,
            backgroundColor: '#FFFFFF',
        },
        
    });
    
    

    相关文章

      网友评论

          本文标题:页面返回(自定义返回页面)

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