反应本机导入
React Native Import
我们可以使用单个关键字而不是 '' import { Text, TextInput, Button, StyleSheet, View } from 'react-native'; “在本机反应中?是否有可用的选项 "Text, TextInput, Button, StyleSheet, View" 的单个关键字?
import { Button, StyleSheet, View } from 'react-native';
export default class ButtonBasics extends Component {
_onPressButton() {
alert('You tapped the button!')
}
render() {
return (
<View style={styles.container}>
<View style={styles.buttonContainer}>
<Button
onPress={this._onPressButton}
title="Press Me"
color="#841584"
/>
</View>
<View style={styles.alternativeLayoutButtonContainer}>
<Button
onPress={this._onPressButton}
title="This looks great!"
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
buttonContainer: {
margin: 20
},
alternativeLayoutButtonContainer: {
margin: 20,
flexDirection: 'row',
justifyContent: 'space-between'
}
});
您可以 import ReactNative from 'react-native'
并将它们用作 <ReactNative.View/>
等等,但我不建议这样做。这不是 99% 的 RN 开发者期望它的阅读方式。
我们可以使用单个关键字而不是 '' import { Text, TextInput, Button, StyleSheet, View } from 'react-native'; “在本机反应中?是否有可用的选项 "Text, TextInput, Button, StyleSheet, View" 的单个关键字?
import { Button, StyleSheet, View } from 'react-native';
export default class ButtonBasics extends Component {
_onPressButton() {
alert('You tapped the button!')
}
render() {
return (
<View style={styles.container}>
<View style={styles.buttonContainer}>
<Button
onPress={this._onPressButton}
title="Press Me"
color="#841584"
/>
</View>
<View style={styles.alternativeLayoutButtonContainer}>
<Button
onPress={this._onPressButton}
title="This looks great!"
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
buttonContainer: {
margin: 20
},
alternativeLayoutButtonContainer: {
margin: 20,
flexDirection: 'row',
justifyContent: 'space-between'
}
});
您可以 import ReactNative from 'react-native'
并将它们用作 <ReactNative.View/>
等等,但我不建议这样做。这不是 99% 的 RN 开发者期望它的阅读方式。