ReactNative的基本组件的认识
2024-10-13 19:26:41
通过官网的react-native init myProject,并打开Android Studio的手机模拟器进行调试
下面的代码使用了 Text 、Image、View、TextInput和的react-native-modal-dropdown(下拉框)的组件,初步开发了一个登陆界面
1、Image的 source静态资源需要 require的引入,服务器资源的引入uri: 'https://upload.wikimedia.org/wikipedia/commons/d/de/Bananavarieties.jpg'
2、一行显示设置flexDirection: 'row'
3、android的输入框TextInput的
<TextInput
style={{height: 40,width:200,padding: 0}}
underlineColorAndroid="transparent" 去掉下边框
keyboardType ='numeric' 调起的是数字键盘
placeholder="请输入手机号"
onChangeText={(text) => this.setState({text})}
secureTextEntry={true} 像password的输入
/>
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/ import React, {
Component
} from 'react';
import {
Platform,
StyleSheet,
Text,
View,
Image,
TextInput
} from 'react-native'; import ModalDropdown from 'react-native-modal-dropdown'; const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
}); type Props = {};
export default class App extends Component < Props > {
constructor(props) {
super(props);
this.state = {
text: '',
value:'',
c:'86'
}
}
render() {
let pic = {
uri: 'https://upload.wikimedia.org/wikipedia/commons/d/de/Bananavarieties.jpg'
};
let phone=[86,100,200,300]
return(
<View style={styles.container}>
<Image source={require('./img/img.jpg')} style={{width: 193, height: 110}} />
<Text style={styles.title}>
代理后台
</Text> <View style={{flexDirection: 'row',borderBottomColor:'#dbdbdb',borderBottomWidth:1}}>
<Text style={{marginRight:10}}>
国家/地区
</Text>
<ModalDropdown
options={['中国大陆', '香港','台湾','美国']}
dropdownStyle={{height: 300,width:200}}
textStyle={{height: 30,width:200,padding:0}}
defaultValue='中国大陆'
onSelect={(index,value)=>{
this.setState({
c:phone[index]
})
}}
/>
</View>
<View style={{flexDirection: 'row',borderBottomColor:'#dbdbdb',borderBottomWidth:1}}>
<Text style={{height: 40,marginRight:40,lineHeight:40}}>
+ {this.state.c}
</Text>
<TextInput
style={{height: 40,width:200,padding: 0}}
underlineColorAndroid="transparent"
keyboardType ='numeric'
placeholder="请输入手机号"
onChangeText={(text) => this.setState({text})}
secureTextEntry={true}
/>
</View>
<View style={{
borderBottomColor:'#dbdbdb',
borderBottomWidth:1
}}>
<TextInput
style={{height: 40,width:200,padding:0}}
keyboardType ='numeric'
underlineColorAndroid="transparent"
placeholder="请输入验证码"
onChangeText={(text) => this.setState({text})}
/>
</View>
<Text style={styles.instructions}>
{this.state.text}
</Text>
<Text style={styles.instructions}>
{instructions}
</Text>
</View>
);
}
} const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'flex-start',
paddingTop: 10,
alignItems: 'center',
backgroundColor: '#fff',
},
title: {
fontSize: 20,
textAlign: 'center',
color: '#000',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
最新文章
- 深度解析C语言int与unsigned int
- P1546 最短网络 Agri-Net
- db2look和db2move详解
- NFS服务器+客户端配置
- jquery总结06-动画事件04-自定义动画
- GithubPage 的简单使用
- hdu4782 Beautiful Soup (模拟)
- Java内存模型---并发编程网 - ifeve.com
- LVS包转发模型和调度算法(转)
- 番茄钟App(Pomodoro Tracker)
- char数组与char指针
- Layout.xml中控件的ID命名方式
- SWMM代码移植到64位平台
- C#入门经典第九章定义类-1
- EXCEL数据导入数据库实例(NPOI)
- Windows下用Composer安装Laravel步骤(集成php环境用phpStudy2016版本)
- 一步一步从原理跟我学邮件收取及发送 12.telnet命令行收一封信pop3
- 使用 HttpRequester 更方便的发起 HTTP 请求
- B. Obtaining the String(模拟)
- [转]ORACLE 11G 导出报错(EXP-00003)未找到段 (0,0) 的存储定义