反应本机导入

时间:2020-01-14 20:55:02

标签: react-native react-component

我们可以使用单个关键字来代替''从'react-native'导入{Text,TextInput,Button,StyleSheet,View};在“ 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'
  }
});

1 个答案:

答案 0 :(得分:6)

您可以import ReactNative from 'react-native'并将其用作<ReactNative.View/>,依此类推,但我不建议这样做。这不是99%的RN开发人员希望阅读的方式。