同时适配Android和IOS

代码注释比较详细
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, {Component} from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TextInput,
Platform,
TouchableOpacity,
} from 'react-native';
var Dimensions = require('Dimensions');
var width = Dimensions.get('window').width;
class TextInputG extends Component {
render() {
return (
<View style={styles.container}>
{}
<View style={styles.textInputViewStyle}>
<TextInput
style={styles.textInputStyle}
placeholder='手机号'/>
</View>
{}
<View style={styles.textInputViewStyle}>
<TextInput
style={styles.textInputStyle}
placeholder='密码'
secureTextEntry={true}/>
</View>
{}
<TouchableOpacity onPress={()=>{alert('点击登录')}}>
{}
<View style={styles.textLoginViewStyle}>
<Text style={styles.textLoginStyle}>登录</Text>
</View>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: 140,
},
textInputViewStyle: {
width: width - 30,
height: 45,
borderRadius: 18,
borderColor: 'blue',
borderWidth: 1,
paddingLeft: 10,
paddingRight: 10,
marginTop: 10,
marginLeft: 20,
marginRight: 20,
alignSelf: 'center',
},
textInputStyle: {
width: width - 30,
height: 35,
paddingLeft: 8,
backgroundColor: '#00000000',
marginTop: Platform.OS === 'ios' ? 4 : 8,
},
textLoginViewStyle: {
width: width - 30,
height: 45,
backgroundColor: 'red',
borderRadius: 20,
marginTop: 30,
alignSelf: 'center',
justifyContent: 'center',
alignItems: 'center',
},
textLoginStyle: {
fontSize: 18,
color: 'white',
},
});
module.exports = TextInputG;