範例一

  • 手機的控制項與瀏覽器不同。所以手機的控制項是直接使用react native提供組件或引入由第三方開發者提供的組件。

  • 不同的組件有不同的參數(props)設定,使用時要再查詢確認

  • 瀏覽器的每一個區塊是用<div>。但手機是用<view>或第三方組件。

  • react native 目前還沒驗證過加入redux是否可正常運作及其適用性。(redux 非必要)

  • react native中的換頁是用navigator.xxx(),也可傳參數。下頁有說明。

  • 用 Chrome 開發者工具除錯

// app.js 範例
// 
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

// 建立元件並匯出
export default function App() {
  return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
    </View>
  );
}

// 建立樣式的語法
// 樣式是駝峰命名
// 尺寸是無單位的
// 值若是字串要加上單引號
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});


// index.js 0.62 版本,預設寫法
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

// 在最外層的元件要註冊此APP名稱,提供給原生平台
AppRegistry.registerComponent(appName, () => App);

Last updated