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

2019-04-09  本文已影响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',
    },
    
});

上一篇下一篇

猜你喜欢

热点阅读