我在react-native
上尝试了Button
,这工作正常。我想自定义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);
答案 0 :(得分:1)
这一行this.navigate("EnableNotifcation");
我纠正了它,现在正在运作。 this.navigate("EnableNotification");
答案 1 :(得分: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>
答案 2 :(得分:0)
使用以下内容对我有用。使用React Native 0.62.2。请参见TouchableOpacity位于KeyboardAvoidingView和ScrollView keyboardShouldPersistTaps内部。
'products.json'