NipGeihou's blog NipGeihou's blog
  • Java

    • 开发规范
    • 进阶笔记
    • 微服务
    • 快速开始
    • 设计模式
  • 其他

    • Golang
    • Python
    • Drat
  • Redis
  • MongoDB
  • 数据结构与算法
  • 计算机网络
  • 应用

    • Grafana
    • Prometheus
  • 容器与编排

    • KubeSphere
    • Kubernetes
    • Docker Compose
    • Docker
  • 组网

    • TailScale
    • WireGuard
  • 密码生成器
  • 英文单词生成器
  • 常用软件
  • Git仓库推荐
🍳烹饪
🧑‍💻关于
  • 分类
  • 标签
  • 归档

NipGeihou

我见青山多妩媚,料青山见我应如是
  • Java

    • 开发规范
    • 进阶笔记
    • 微服务
    • 快速开始
    • 设计模式
  • 其他

    • Golang
    • Python
    • Drat
  • Redis
  • MongoDB
  • 数据结构与算法
  • 计算机网络
  • 应用

    • Grafana
    • Prometheus
  • 容器与编排

    • KubeSphere
    • Kubernetes
    • Docker Compose
    • Docker
  • 组网

    • TailScale
    • WireGuard
  • 密码生成器
  • 英文单词生成器
  • 常用软件
  • Git仓库推荐
🍳烹饪
🧑‍💻关于
  • 分类
  • 标签
  • 归档
  • nodejs

  • css

  • 最佳实践

  • TypeScript

  • ajax

  • JavaScript

  • 前端工程化

  • React

  • nextjs

  • Flutter

  • Vue

  • Taro

  • ReactNative

    • React Native - 开始
      • 资料
      • 组件
        • 原生组件
        • 核心组件
      • 特定平台代码
        • Platform 模块
        • 特定平台后缀
      • 环境搭建
  • 笔记

  • 前端
  • ReactNative
NipGeihou
2026-08-12
目录

React Native - 开始

# 资料

  • 官网:https://reactnative.dev/ (opens new window)

# 组件

# 原生组件

在 Android 开发中,视图通常使用 Kotlin 或 Java 编写;在 iOS 开发中,则使用 Swift 或 Objective-C。而使用 React Native,你可以利用 React 组件通过 JavaScript 调用这些视图。在运行时,React Native 会为这些组件创建相应的 Android 和 iOS 视图。由于 React Native 组件与 Android 和 iOS 组件使用相同的视图,因此 React Native 应用的外观、体验和性能与其他应用并无二致。我们将这些平台支持的组件称为原生组件。

# 核心组件

React Native UI 组件 Android 原生视图 iOS 原生视图 Web 标签
<View> <ViewGroup> <UIView> A non-scrolling  <div>
<Text> <TextView> <UITextView> <p>
<Image> <ImageView> <UIImageView> <img>
<ScrollView> <ScrollView> <UIScrollView> <div>
<TextInput> <EditText> <UITextField> <input type="text">

# 特定平台代码

参考:Introduction · React Native (opens new window) React Native 提供了两种方法来区分平台:

  • 使用 Platform 模块.
  • 使用特定平台后缀.

# Platform 模块

import {Platform, StyleSheet} from 'react-native';

const styles = StyleSheet.create({
  // `Platform.OS`在 iOS 上会返回`ios`,而在 Android 设备或模拟器上则会返回`android`
  height: Platform.OS === 'ios' ? 200 : 100,
});

Platform.select() :

import {Platform, StyleSheet} from 'react-native';

const styles = StyleSheet.create({
  container: {
    flex: 1,
    ...Platform.select({
      ios: {
        backgroundColor: 'red',
      },
      android: {
        backgroundColor: 'green',
      },
      default: {
        // other platforms, web for example
        backgroundColor: 'blue',
      },
    }),
  },
});

# 特定平台后缀

BigButton.ios.js
BigButton.android.js

# 环境搭建

上次更新: 2026/08/13, 14:48:29
Taro - 最佳实践
组件库

← Taro - 最佳实践 组件库→

最近更新
01
Kotlin - 入门
08-12
02
3D打印机箱IO挡板
07-24
03
增肌与减脂
07-11
更多文章>
Theme by Vdoing | Copyright © 2018-2026 NipGeihou | 友情链接
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式