React 本机导航不适用于 TouchableOpacity [英] React native navigation is not working on TouchableOpacity

查看:52
本文介绍了React 本机导航不适用于 TouchableOpacity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Button 上尝试了 react-native,它工作正常.我想自定义 Button 所以这让我选择了 TouchableOpacity.我正在尝试设置如下所示的本机导航,但现在无法正常工作.

I tried react-native on Button which is working fine. I want to customize Button so this made me to go for TouchableOpacity. I am trying to setup react native navigation like below which is not working now.

我用它来导航https://reactnavigation.org/

index.android.js

/**
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from "react";
import {
  AppRegistry,
  Image,
  View,
  Text,
  Button,
  StyleSheet,
  TouchableOpacity
} from "react-native";
import { StackNavigator } from "react-navigation";
import EnableNotificationScreen from "./EnableNotificationScreen";
import styles from "./Styles";
import * as strings from "./Strings";

class SplashScreen extends Component {
  render() {
    console.disableYellowBox = true;
    const { navigate } = this.props.navigation;
    return (
      <View style={styles.container}>
        <Image source={require("./img/talk_people.png")} />
        <Text style={styles.textStyle}> {strings.talk_people} </Text>

        <TouchableOpacity>
          <View
            style={{
              backgroundColor: "#FE434C",
              alignItems: "center",
              justifyContent: "center",
              borderRadius: 10,
              width: 240,
              marginTop: 30,
              height: 40
            }}
            onPress={() => {
              this.navigate("EnableNotifcation");
            }}
          >
            <Text style={{ color: "white" }}>CONTINUE</Text>
          </View>
        </TouchableOpacity>
      </View>
    );
  }
}

const ScheduledApp = StackNavigator(
  {
    Splash: {
      screen: SplashScreen,
      navigationOptions: {
        header: {
          visible: false
        }
      }
    },
    EnableNotification: {
      screen: EnableNotificationScreen,
      navigationOptions: {
        header: {
          visible: false
        }
      }
    }
  },
  {
    initialRouteName: "Splash"
  }
);

AppRegistry.registerComponent("Scheduled", () => ScheduledApp);

推荐答案

这是一个 tpyo 错误在这一行 this.navigate("EnableNotifcation");

It was a tpyo error at this line this.navigate("EnableNotifcation");

我更正了它,现在可以正常工作了.this.navigate("EnableNotification");

I corrected it and it is working now. this.navigate("EnableNotification");

这篇关于React 本机导航不适用于 TouchableOpacity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆