React Native 新架构是指使用新的工具和库来提升开发体验和性能,其中最知名的就是使用 React Native 的新版本(0.72及以上),它引入了新的JSI(JavaScript Interface),用于提供更好的JavaScript和原生之间的通信性能。
以下是一个简单的React Native应用程序的代码示例,展示了如何使用新架构创建一个简单的组件:
import React from 'react';
import { Text, View, Button } from 'react-native';
 
export default class App extends React.Component {
  handlePress = () => {
    console.log('Button was pressed!');
  };
 
  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Hello, React Native!</Text>
        <Button onPress={this.handlePress} title="Press Me" />
      </View>
    );
  }
}在这个例子中,我们创建了一个名为 App 的组件,它在屏幕中心显示文本和一个按钮。当按钮被按下时, handlePress 函数会被调用,并在控制台打印一条消息。这个应用程序展示了如何使用React Native的基本组件,并处理用户的交互。