react-native NavigatorIOS 使用方法

import React, {Component} from 'react';
import {
    Platform,
    StyleSheet,
    Text,
    View,
    NavigatorIOS,
    TouchableOpacity
} from 'react-native';

export default class App extends Component<Props> {
    render() {
        return (
            <NavigatorIOS
                style={{flex: 1}} // 此项不设置,创建的导航控制器只能看见导航条而看不到界面
                interactivePopGestureEnabled={true}//决定是否启用滑动返回手势。
                translucent={true}//决定导航条是否半透明
                initialRoute={{//初始化路由
                    component: Home,//路由的根视图
                    title: '首页',//标题
                }}
            />
        );
    }
}
class Home extends Component {
    _onPressView(nextRoute) {
        this.props.navigator.push(nextRoute)
    }

    render() {
        const nextRoute = {
            component: Detail,//目的地视图
            title: '详情',//目的地标题
            titleTextColor: 'blue',//标题颜色
            shadowHidden: true,//决定是否要隐藏1像素的阴影
            barTintColor: 'white',//导航条的背景颜色
            tintColor: 'orange',  // 按钮的颜色
            leftButtonTitle: '返回',//导航条的左按钮
            onLeftButtonPress: () => {
                this.props.navigator.pop()
            },
            rightButtonTitle: '相册',//导航条的右按钮
            onRightButtonPress: () => {//导航条右按钮触发事件
                alert('没有该照片');
            },
            passProps: {myProp: 'bar'}
        };
        return (
            <View style={styles.container}>
                <TouchableOpacity
                    onPress={() => {
                        this._onPressView(nextRoute)
                    }}
                >
                    <Text>{"详情!"}</Text>
                </TouchableOpacity>
            </View>
        )
    }
}
class Detail extends Component {

    render() {
        return (
            <View style={[styles.container, {backgroundColor: "green"}]}>
                <TouchableOpacity
                    onPress={() => {
                        this.props.navigator.pop()
                    }}
                >
                    <Text>{"首页!"}</Text>
                </TouchableOpacity>
            </View>
        )
    }
}
const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: 'red',
    }
});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值