ReactNativeにNativeBaseを導入してUIを整える
概要
天気の情報を入れた、が! CloudsとかClearとか言われてもわけわからん! いつの天気!? みたいに思うのでとりあえずUIをそれっぽくしてみようと思った。
前回:
情報設計
L2. いつ L1. 天候 L3. 気温, 湿度, 気圧 L4. 更新
対応フロー
実装調査
起動時初期化
ContainerでcomponentDidMount
時にasyncAction発行すれば行けそう。
UI
他のMaterial系とかも探したけど、 ここ数ヶ月でメンテされてて、情報がありそうなフレームワークがぱっと見みつからなかった。
そういうの探すのにおすすめな記事とかあれば知りたい。 そういうの探すのにおすすめな記事とかあれば知りたい。(こういうのとか)
Comonents
まあこの辺使えばいけるんじゃないの?的なやつ。
- Layout Components · NativeBase
- Header Components · NativeBase
- Spinner Components · NativeBase
- Button Components · NativeBase
- Icon Components · NativeBase
実装
- API通信が「取得」から「読み込み(自動)」「再読込(ユーザアクション)」に別れたことで、UseCase, Action, Reducerに変更が必要となった
- めんどくさくてUseCaseだけ分けた
- あとで違うインタラクションにしてくれって言われたときに困るかもしれない
- ローディングの有無とか、表示の仕方とか
- 困らないかもしれない
- Viewから見て別れていれば一旦おk
- いやこれ、絶対あとで「クソだろ」って思う
- react-baseがコケた
Error: Unable to resolve module 'create-react-class'
- NativeBaseでReactNativeのComponentを置き換え
- NativeBaseでアイコン利用
- type, name を指定するが、☓になる
- 名前を変えても☓
react-native link
してなかった- デフォルトはIonicons
- ボタン+アイコンがいい感じの配置にならない
- ドキュメントのコードとキャプチャが違う
- サンプルを示してくれ!!!!
Error: Unable to resolve module create-react-class
Loading dependency graph, done. error: bundling failed: Error: Unable to resolve module `create-react-class` from `/Users/mizuki/project/rnapp-weather/node_modules/native-base/dist/src/basic/Picker.android.js`: Module `create-react-class` does not exist in the Haste module map
インストールで解決。
$ npm install --save create-react-class
NativeBaseの利用
$ npm install --save native-base $ react-native link
Android EmulatorのScreen shot
$ adb shell screencap -p /sdcard/screen.png $ adb pull /sdcard/screen.png /tmp/screen.png $ adb shell rm /sdcard/screen.png $ open /tmp/screen.png
参考: MacでAndroid開発中に手軽にスクリーンショットを撮る
完成図