React Native

150 阅读1分钟

Q 函数式组件

import React from 'react';
import { Text, View } from 'react-native';

const HelloWorldApp = () => {
  return (
    <View style={{
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center'
      }}>
      <Text>Hello, world!</Text>
    </View>
  );
}

export default HelloWorldApp;

Q Class 组件

import React, { Component } from 'react';
import { Text, View } from 'react-native';

class HelloWorldApp extends Component {
  render() {
    return (
      <View style={{
          flex: 1,
          justifyContent: "center",
          alignItems: "center"
        }}>
        <Text>Hello, world!</Text>
      </View>
    );
  }
}

export default HelloWorldApp;

Q JSX

  • {}

Q Props

  • 定制组件渲染的参数

Q State

  • 组件的私人数据记录
  • Redux

Q 处理触摸事件

<Button\ onPress={() => {\ Alert.alert('你点击了按钮!');\ }}\ title="点我!"\ />

Q Touchable 系列组件

Q ScrollView

  • flex: 1

Q 使用长列表

Q 特定平台代码

Q React

Q 常用的第三方库

精心整理的资源列表 中文资源列表

Q Proguard

  • Java 字节码混淆压缩工具 def enableProguardInReleaseBuilds = true

Q 打包发布

  1. 生成一个签名密钥
  2. 设置 gradle 变量
  3. 把签名配置加入到项目的 gradle 配置中
  4. 生成发行 APK 包
  5. 测试应用的发行版本
  6. 针对不同的 CPU 架构生成 APK 以减小 APK 文件的大小
  7. 启用 Proguard 来减少 apk 的大小(可选)
  8. 生成发行 AAB 包

Q 和原生端通信

  1. 属性

致谢

感谢 React Native 中文网