0

我试过哪个工作正常react-nativeButton我想定制Button,所以这让我选择了TouchableOpacity. 我正在尝试设置如下所示的反应本机导航,但现在无法正常工作。

我用它来导航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);
4

3 回答 3

1

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

我纠正了它,它现在正在工作。this.navigate("EnableNotification");

于 2017-04-28T10:26:01.140 回答
0

onPress 道具应该在 TouchableOpacity 内部,而不是像您拥有的那样在 View 道具内部。见下面的伪代码

<TouchableOpacity onPress = {...}>
    <View style = {{}}>
    //Rest of the code

这应该解决它。在旁注中,我建议为您的视图组件添加一个新样式,那里有很多元素:P

编辑:

            <TouchableOpacity onPress = {/*do this*/}>
                <View style={{ backgroundColor: "#FE434C",
                               alignItems: "center",
                               justifyContent: "center",
                               borderRadius: 10,
                               width: 240, marginTop: 30,
                               height: 40 }}>
                    <Text style={{ color: "white" }}>
                        {"CONTINUE"}
                    </Text>
                </View>
            </TouchableOpacity>
于 2017-04-25T10:28:40.270 回答
0

使用以下对我有用。使用反应原生 0.62.2。请参阅 TouchableOpacity 在 KeyboardAvoidingView 和 ScrollView 中的keyboardShouldPersistTaps。

 <ScrollView keyboardShouldPersistTaps="handled">
    <KeyboardAvoidingView enabled>
      <View>
        <TouchableOpacity
          onPress={() => functionNameToNavigate('ScreenToMoveOn')}> <Text>Click me</text>
        </TouchableOpacity>
      </View>
    </KeyboardAvoidingView>
  </ScrollView>
于 2020-11-16T15:19:37.160 回答