Gok*_*oku 11 android components custom-component reactjs react-native
我正在按照这篇中等文章FloatingTitleTextInputField
在我的反应本机项目中使用
下面是我的项目结构
这是我的代码HomeScreen.js
import React, {Component} from 'react';
import {Text, View, TextInput, StyleSheet} from 'react-native';
import FloatingTitleTextInputField from './customComponents/floating_title_text_input_field';
export default class HomeScreen extends Component {
render() {
return (
// <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
// <Text>My First React App</Text>
// <TextInput style={{height: 40, borderColor: 'gray', borderWidth: 1}} />
// </View>
<View style={styles.container}>
<View style={styles.container}>
<Text style={styles.headerText}>Its Amazing</Text>
<FloatingTitleTextInputField
attrName="firstName"
title="First Name"
value={this.state.firstName}
updateMasterState={this._updateMasterState}
/>
<FloatingTitleTextInputField
attrName="lastName"
title="Last Name"
value={this.state.lastName}
updateMasterState={this._updateMasterState}
/>
</View>
</View>
);
}
}
var styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 65,
backgroundColor: 'white',
},
labelInput: {
color: '#673AB7',
},
formInput: {
borderBottomWidth: 1.5,
marginLeft: 20,
borderColor: '#333',
},
input: {
borderWidth: 0,
},
});
Run Code Online (Sandbox Code Playgroud)
FloatingTitleTextInputField
当我尝试在内部使用时,HomeScreen.js
出现以下错误
error Unable to resolve module `./floating_title_text_input_field` from `React Native/AwesomeProject/screens/
HomeScreen.js`: The module `./floating_title_text_input_field` could not be found from `/React Native/AwesomeProject/screens/HomeScreen.js`. Indeed, none of these files exist:
* `/React Native/AwesomeProject/screens/floating_title_text_input_field(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)`
* `/React Native/AwesomeProject/screens/floating_title_text_input_field/index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)`. Run CLI with --verbose flag for more details.
Error: Unable to resolve module `./floating_title_text_input_field` from `React Native/AwesomeProject/screens/HomeScreen.js`: The module `./floating_title_text_input_field` could not be found from `/React Native/AwesomeProject/screens/HomeScreen.js`. Indeed, none of these files exist:
Run Code Online (Sandbox Code Playgroud)
谁能帮我解决这个问题
如果需要更多信息,请告诉我。提前致谢。您的努力将受到赞赏。
HomeScreen
您从目录中的组件引用它screens
。因为您使用的是本地./
路径,所以它会尝试在screens/customComponents
. 使用../customComponents/floating_title_text_input_field
应该可以修复它。
尽管您的错误是在require
声明期间使用了错误的路径,但我认为分享我如何解决此问题可能会很有用,其中文件导入路径不是错误的原因。在添加一些图像资源并在我的组件中需要它们后,我遇到了这个问题。但我忘记再次构建应用程序。经过多次尝试,这是对我有用的解决方案。
yarn android/ios
。yarn start
。 归档时间: |
|
查看次数: |
67663 次 |
最近记录: |