Chapter8: React native

This section contain the following items:

1) Building Development environment (For OS X)

2) Building Sublime environment (for ES6)

3) React-native es6模組的寫法

4) ES6 Promise

4) 風格樣式, 排版

5) 行動元件

6) 平台API

1.Building Development environment (For OS X)

  • command:

    • sudo brew install node

    • sudo brew install watchman

    • sudo brew install flow

    • brew update (盡量不要用)

    • brew upgrade (盡量不要用)

  • Android Enviroment

    • Install JDK:

       brew install android-sdk
       export ANDROID_HOME=/usr/local/opt/android-sdk
       -> 這段可用Android Studio取代比較安全, 比較順
    • open Android SDK manager:

          sudo android
          Install Android SDK builexusd-tools version 23.0.1
          Install Android 6.0
          Install Android Support Library
    • Create and Launch android simulator:

          sudo android avd, create a instance (ex. nexus)
          Start instance
          react-native run-android

      2.Building Sublime environment (for ES6)

  • Save react-native project as .sublime-project file, add following string to disable jshint:

3.React-native es6模組的寫法

4.ES6 Promise

5. 風格樣式, 排版

  • 使用方式

    • Stylesheet.Create

  • 傳統css樣式

    • 通常是全域, 如果不小心可能一個元件的樣式可能會破壞另一個元件的樣式

  • 行內樣式

  • 樣式物件

  • 透過屬性

    • example:

  • flexbox

    • 能夠為動態調整大小的元素建構可預期的佈局結構

    • 基本排版練習

      • 以下範例皆以下面程式碼為基礎修改:

  • demo:

  • flex與flexDirection屬性

    • 改變flex及flexDirection

      • 左: 修改styles:

        const styles = StyleSheet.create({ parent: { flex: 1, flexDirection: 'column', backgroundColor: '#F5FCFF', borderColor: '#0099AA', borderWidth: 5, marginTop: 30 }, child: { flex: 1, borderColor: '#AA0099', borderWidth: 2, textAlign: 'center', fontSize: 24 } });

      • 右: 修改styles:

  • 改變alignItems

    • 左: 修改styles:

  • 練習較複雜的排版

    • 要點

      • 1.由外到內, 由左到右安排排版, 以flex設定權重, 以fleDirection設定子元素的方向

        • 以外層用flexDirection調整內部元素的排列方向

        • 內部元素用flex調整權重

      • 2.共用的style可抽出來,加入多個style時記得用陣列表示

    • code:

    • demo:

6. 行動元件

  • HTML元素與React元件的對比

  • Text

  • Image

  • 使用手勢與觸控

    • touchableHighlight

  • 使用組織性元件

    • ListView

    • Navigator

  • 平台專屬元件

7. 平台API

  • Polyfill

  • AsyncStorage

    • AsyncStorage的儲存鍵可為任何字串: 通常使用@AppName: Key格式

    • AsyncStorage以getItem與setItem回應.

    • Example

Last updated