大家好,
我正在开发一个 React Native 项目,我刚刚安装了 react-native-navigation
模块并按照文档提供的说明进行操作。
我在开始之前执行了 gradlew clean
来清理应用程序。一旦我启动应用程序,我会在 Android 模拟器上看到一个空白屏幕,并在 js 调试器窗口的控制台中看到一条警告消息。
Unable to define method 'getConstants()' on NativeModule 'RNNBridgeModule'. NativeModule 'RNNBridgeModule' already has a constant or method called 'getConstants'. Please remove it.
这是我在终端中打开的 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
}
})
}
我希望你们中的一个人能找到这个问题的答案,因为在最后一小时的搜索中我并没有真正找到任何与此类似的内容。
感谢大家的宝贵时间和建议。
最佳答案
就我而言,创建一个新的 rn 项目,然后我按照 https://wix.github.io/react-native-navigation/#/docs/Installing 进行操作。说明,但无需替换 build.gradle 中的版本,它适用于我
关于android - 如何修复 native react 中的 "unable to find method ' getConstants( )'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55534728/