今天是个好日子,
我正在研究一个反应本机项目,我刚刚安装了react-native-navigation
模块,并按照文档提供的说明进行操作。
在开始之前我做了一个gradlew clean
来清理应用程序。一旦我启动应用程序,我在android模拟器上得到一个空白屏幕,并在js调试器窗口的控制台中显示一条警告消息。
无法在NativeModule'RNNBridgeModule'上定义方法'getConstants()'。 NativeModule'RNNBridgeModule'已经有一个名为'getConstants'的常量或方法。请删除它。
这是我在终端中打开的metro服务器控制台中没有显示错误的警告。
这是我到目前为止创建的组件:
import React from 'react';
import {
View,
Text,
TextInput,
TouchableOpacity,
Image,
StyleSheet,
Dimensions
} from "react-native";
import Icon from 'react-native-vector-icons/MaterialIcons'
import { colors, fontSizes, dimensions } from '../../styles/base.js';
import showToast from '../generic/Toast';
export default class Login extends React.Component {
constructor() {
super();
this.state = {
username: '',
password: ''
}
}
render() {
return (
<View style={styles.login}>
<Image
source={require('../../img/logo.png')}
style={styles.img}
resizeMode="contain"
resizeMethod="scale"
/>
<TextInput
onChange={uname => this.setState({ username: uname })}
placeholder={"Username"}
style={styles.input}
/>
<TextInput
onChange={pwd =>
this.setState({
password: pwd
})
}
placeholder={"Password"}
style={[styles.input, styles.password]}
secureTextEntry={true}
/>
< TouchableOpacity onPress = {
() => {/*showToast({
msg: dimensions.fl + " " + dimensions.fw
})*/
console.log("height: "+ dimensions.fl);
console.log("width: "+ dimensions.fw);
}} >
<Text style={styles.btn}>Login</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => console.log("settings...")} style={styles.iconBtn}>
<Icon name="settings" size={35} style={styles.icon} />
</TouchableOpacity>
</View>
);
}
}
let width,mbi,mtb,mtp;
if(dimensions.fw <= 568) {
width = "90%";
mbi = 10;
mtb = 15;
mtp = 10;
fontSize = fontSizes.textSizeSmall;
} else if (dimensions.fw > 586 && dimensions.fw <= 768) {
width = "80%";
mbi = 20;
mtb = 25;
mtp = 20;
fontSize = fontSizes.textSizeMedium;
} else if (dimensions.fw > 768) {
width = "65%";
mbi = 60;
mtb = 35;
mtp = 30;
fontSize = fontSizes.textSizeLarge
}
const styles = StyleSheet.create({
login: {
width: "100%",
height: "100%",
justifyContent: "center",
alignItems: "center",
backgroundColor: colors.sky
},
input: {
height: 55,
width,
borderBottomWidth: 1,
borderBottomColor: colors.red,
fontSize
},
password: {
marginTop: mtp
},
btn: {
paddingTop: 15,
paddingBottom: 15,
paddingLeft: 40,
paddingRight: 40,
color: colors.light,
backgroundColor: colors.darksky,
fontSize,
marginTop: mtb
},
img: {
width: "80%",
height: "50%",
marginBottom: mbi,
marginTop: "-8%"
},
icon: {
marginRight: 25,
marginBottom: 15,
color: colors.dark
},
iconBtn: {
alignSelf: "flex-end",
position: "absolute",
bottom: 0
}
});
import React, { Component } from 'react';
import Toast from 'react-native-root-toast';
export default showToast = (props) => {
return Toast.show(props.msg, {
duration: Toast.durations.LONG,
position: Toast.positions.BOTTOM,
shadow: true,
hideOnPress: true,
animation: true,
delay: 500,
backgroundColor: props.backgroundColor || "black",
shadowColor: props.shadowColor || "gray",
textColor: props.textColor || "white",
containerStyle: {
width: "100%",
borderRadius: 0,
paddingBottom: 10
}
})
}
我希望你们中的一个人能够解决这个问题,因为在搜索的最后一小时里我没有找到任何与此类似的东西。
谢谢,大家都有你的时间和建议。
@chawki challadia沿着最新版本的react-navigation你需要安装手势处理程序(npm install --save react-native-gesture-handler),这里提到https://reactnavigation.org/docs/en/getting-started.html。这就是你收到警告的原因。另外,不要忘记使用react-native链接react-native-gesture-handler链接手势处理程序库。它应该工作正常。
在我的情况下创建一个新的项目,我遵循https://wix.github.io/react-native-navigation/#/docs/Installing说明,但没有替换build.gradle中的版本,它适用于我的