零:當(dāng)前情況
marry.gif
marry_0606.gif
錄制效果不好胶背,參考0606_00.png,0606_01.png
0606_00.png
0606_01.png
一廷粒、前言
為什么選擇這個(gè)應(yīng)用模仿?
- Redux架構(gòu):該應(yīng)用的開(kāi)發(fā)人員使用了Redux架構(gòu)(這個(gè)不是重點(diǎn))涤姊。
- SVG:該應(yīng)用除了Icon(圖標(biāo))及LaunchImage(啟動(dòng)圖)以外的圖片嗤放,其余均使用SVG(而且是純代碼)斤吐。一開(kāi)始只是為了了解SVG,而開(kāi)始模仿這個(gè)應(yīng)用厨喂。
- 動(dòng)畫(huà):該應(yīng)用在多處地方使用了動(dòng)畫(huà)蜕煌。
注意
- 該項(xiàng)目開(kāi)發(fā)均在OS X系統(tǒng)上完成。
- 目前為止暫未使用iOS特有組件贫母,但本人未曾在Android設(shè)備上運(yùn)行該項(xiàng)目盒刚。
二因块、準(zhǔn)備
- 配置好React-Native開(kāi)發(fā)環(huán)境,React-Native中文文檔及React-Native英文文檔趾断。這一步?jīng)]有做好芋酌,將無(wú)法進(jìn)行開(kāi)發(fā)雁佳!
- 創(chuàng)建React-Native工程(本人以Marry命名此項(xiàng)目)。
- 打開(kāi)終端腮恩。
- 切換到存放工程的目錄秸滴。假設(shè)目錄為
~/Documents/ReactNativeDemo
募判,則需要在終端輸入cd ~/Documents/ReactNativeDemo
,回車(chē)释液。 - 輸入
react-native init Marry
误债,回車(chē)。等待李命,直到創(chuàng)建完成箫老。 - 運(yùn)行項(xiàng)目耍鬓,運(yùn)行成功即完成了項(xiàng)目創(chuàng)建 (iOS和Android的設(shè)備/模擬器均需要運(yùn)行成功)牲蜀。
- 依賴(lài)文件
npm install react-native-svg --save
rnpm link react-native-svg
如果輸出-bash: rnpm: command not found
,則表明未安裝rnpm
项贺。
解決:輸入npm i rnpm -g
峭判,再輸入rnpm link react-native-svg
即可.
npm install react-native-tab-navigator --save
npm install react-native-scrollable-tab-view --save
- Redux架構(gòu)相關(guān)
npm install --save redux
- React 綁定庫(kù):react-redux
npm install --save react-redux
- 開(kāi)發(fā)者工具:redux-devtools
npm install --save-dev redux-devtools
- middleware(中間件):redux-thunk或者redux-promise林螃,這里我們使用redux-thunk.
npm install --save redux-thunk
npm install --save normalizr
熱更新(該功能暫缺)
最終package.json如下(版本號(hào)可能會(huì)有所不同):
{
"name": "Marry",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
},
"dependencies": {
"normalizr": "^2.0.1",
"react": "^0.14.8",
"react-native": "^0.24.1",
"react-native-scrollable-tab-view": "^0.4.1",
"react-native-svg": "^1.0.1",
"react-native-tab-navigator": "^0.2.18",
"react-redux": "^4.4.5",
"redux": "^3.5.1",
"redux-thunk": "^2.0.1"
},
"devDependencies": {
"redux-devtools": "^3.2.0"
}
}
代碼管理(github)
- 本人將會(huì)把代碼托管到react-native-redux-marry完残。
- 推薦使用SourceTree代碼管理工具横漏。
三缎浇、開(kāi)發(fā)
第一天
題外話
5.20凌晨完成了一個(gè)愛(ài)心的SVG動(dòng)畫(huà)。
heart_svg.png
然后迷上了SVG.第一天就先從SVG開(kāi)始二蓝,剛好得意婚嫁里的icon幾乎都是SVG代碼實(shí)現(xiàn)的刊愚。
正文
查找圖片資源
- 下載-->解壓-->查看app里面圖片資源
- 發(fā)現(xiàn)只有AppIcon、LaunchImage商玫、網(wǎng)絡(luò)錯(cuò)誤(404.png)决帖、加載動(dòng)畫(huà)(loading.gif)蓖捶。這四類(lèi)圖片俊鱼,未發(fā)現(xiàn)其它圖片資源畅买。
- 抓取網(wǎng)絡(luò)數(shù)據(jù),也未發(fā)現(xiàn)相關(guān)圖片數(shù)據(jù)。飛行模式下帝火,第一次打開(kāi)應(yīng)用犀填,也可以得出此結(jié)論嗓违。
Airplane_Mode.png
- 查看app解壓后的文件蹂季,找到main.jsbundle偿洁,把里面的內(nèi)容拷貝到.txt文件里面。本人在終端中使用命令cp拷貝睬辐。
- 查看.text文件,發(fā)現(xiàn)里面有svg相關(guān)代碼鹃唯。Orz!!感受到了坡慌,來(lái)自世界深深的惡意藻三。
創(chuàng)建SVG文件
- 創(chuàng)建js/svg目錄(將用js目錄存放所有React Native相關(guān)代碼,svg目錄存放svg文件)棵帽。
- Logo.js(推薦頁(yè)上面的“得意結(jié)婚”四個(gè)字)
// Logo.js
import React, { Component } from 'react';
import Svg, {
Circle,
G,
Path,
Polygon,
} from 'react-native-svg';
export default class Logo extends Component {
render(){
return (
<Svg width={88} height={22}>
<G scale={0.5}>
<Path fill="#ff5942" d="M63.8,29.9h-4.4c0,0,0.5,6.5,5.3,7.8c3.8,1.1,6-0.2,8.3-1.5c0.7-0.4,1.5-0.8,2.3-1.1 c6.6-2.3,9.3,2.1,9.3,2.1l3.8-1.7c0,0-4.5-7.4-14.5-4c-1.1,0.4-2.1,0.9-3,1.5c-1.5,0.8-2.9,1.7-4.9,1.1 C64.1,33.6,63.8,29.9,63.8,29.9L63.8,29.9z"/>
<Path fill="#ff5942" d="M58.2,29.7h-3.4v4.4l0,0.2c0,0.5-0.3,0.7-0.7,0.6h-2.7h-0.2v2.7h0.2h1.8h0.6h1.8h0.1 c0.7,0.1,1.3-0.1,1.7-0.5c0.5-0.5,0.8-1.4,0.8-2.6L58.2,29.7L58.2,29.7z"/>
<Path fill="#ff5942" d="M86.8,15.5h-1.8h-1.8h-0.4H81h-1.8h-1.8h-1.8h-1.8h-1.8h-1.8h-1.8h-1.8h-1.8h-1.8h-1.8h-1.8h-1.8H54v12.7 h3.5h1.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8H81h1.8l0.4,0c0.7,0,1.3-0.2,1.8-0.4c0.9-0.4,1.5-1,1.8-1.9 c0.2-0.5,0.3-0.5,0.3-1.2v-9.2H86.8L86.8,15.5z M83.4,24.7c0,0.4-0.2,0.6-0.7,0.5h-0.8h-2.8h-1.8h-1.8h-1.8h-1.8h-1.8h-1.8h-1.8 h-1.8h-1.8h-1.8h-2.8h-0.8v-2h0.8h2.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8h2.8h1.4V24.7z M83.4,20.6h-1.4h-2.8h-1.8h-1.8h-1.8 h-1.8h-1.8h-1.8h-1.8h-1.8h-1.8h-1.8h-2.8h-0.8v-2h0.8h2.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8h2.8h1.4V20.6z"/>
<Path fill="#ff5942" d="M87,10.7h-1.8h-1.5L84.1,8h1H87h0.7V4.8H87h-1.8h-1.8h-1.8h-1.8h-0.6h-1.8h-1.8h-1.5V3.8h-0.4h-1.8h-1.8 h-1.8h-1.5v1.1h-0.3h-1.8h-1.8h-1.8h-1.8h-0.6h-1.8h-1.8h-1.8h-0.2v3.4h0.2h1.8h2.1l0.5,2.5h-0.5h-2h-1.8h-0.7v3h0.7h1.8h1.8h1.8 h0.6h1.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8h1.8h0.6h1.8h1.8h1.8H87h1v-3H87z M78.5,10.7L78.5,10.7h-1.2h-1.8h-1.8h-1.8h-1.8h-1.8 h-1.8h-1.8h-2.2l-0.1-0.3l-0.6-2.2h0.6h2.3h1.8h1.8h1.8h1.8h1.8h1.8h1.8h1.1h0.7L78.5,10.7z"/>
<Polygon fill="#ff5942" points="22.3,6.5 19.4,3.9 8.8,14.6 11.7,17.3 "/>
<Path fill="#ff5942" d="M48.4,15.7V4.3h-0.2H25.9h-0.5V19h0.5h1.3h17.6l0.2,0c0.7,0.1,0.9,0,1.4-0.1c0.9-0.2,1.5-0.8,1.8-1.6 C48.4,16.7,48.5,16.6,48.4,15.7z M44,14.9c0,0.3,0,0.5-0.1,0.7c-0.1,0.3-0.4,0.4-0.8,0.4H30h-0.2v-3H30h13.8H44V14.9z M44.2,10.1 h-0.3H30h-0.4V7.2H30h13.8h0.3L44.2,10.1L44.2,10.1z"/>
<Path fill="#ff5942" d="M47,27.2h-0.2v-2.6H47h2.3v-3.4h-0.8H25.9h-0.5v3.4h0.5H42h0.4v2.6H42H24.2h0v3.3h0H42h0.4v1.6 c0,2-0.9,2.4-2.1,2.4c-5,0.2-7.9-3.4-14.5-2v3.4c4.1-0.6,7.7,0.8,10.7,1.8c3,0.9,6.4,0.5,7.6-0.1c1.2-0.6,2.4-1.5,2.6-3.5v-3.6H47 h2.7v-3.3H47L47,27.2z"/>
<Polygon fill="#ff5942" points="16.6,21.2 16.6,37.9 17.1,37.9 18.3,37.9 19.4,37.9 20.4,37.9 20.4,17.3 24.6,13.1 21.5,10.4 10.9,21.1 14,23.9 "/>
<Path fill="#ff5942" d="M127.3,23.1c-0.7-0.6-1.5-0.9-2.5-0.9h-15.1c-1,0-1.8,0.3-2.4,0.9c-0.6,0.7-0.9,1.4-0.9,2v9.4 c0,0.8,0.3,1.6,0.9,2.2c0.6,0.7,1.4,1,2.3,1l15.2,0c1.1,0,1.9-0.3,2.6-1c0.6-0.6,0.9-1.5,0.9-2.6v-8.6 C128.3,24.5,127.9,23.7,127.3,23.1z M124.8,32.9c0,0.5-0.1,0.9-0.4,1.1c-0.2,0.2-0.6,0.3-1.2,0.3H111c-0.8,0-1.2-0.4-1.2-1.3v-5.7 c0-0.5,0.1-0.8,0.4-1.1c0.2-0.2,0.4-0.3,0.7-0.3l0.6,0h11.7c1,0,1.6,0.4,1.6,1.3L124.8,32.9L124.8,32.9z"/>
<Polygon fill="#ff5942" points="118.8,16.3 127.9,16.3 127.9,19.9 106.1,19.9 106.1,16.3 115.3,16.3 115.3,11.4 105.7,11.4 105.7,7.8 115.3,7.8 115.3,5.1 118.8,5.1 118.8,7.8 128.3,7.8 128.3,11.4 118.8,11.4 "/>
<Path fill="#ff5942" d="M100.1,14.2h4.3l-7.2,12.9h6.7v3.6h-7.6c-1.3,0-2.2-0.2-2.7-0.5c-0.5-0.4-0.8-1-0.8-1.7 c0-0.8,0.5-2.2,1.6-4.1l2.9-5.1h-2.2c-0.8,0-1.4-0.2-1.8-0.7c-0.4-0.4-0.7-0.9-0.7-1.5c0-0.8,0.3-1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,0-1.9,0.3-2.5,1c-0.7,0.7-1,1.5-1,2.3v9.2 c0,0.7,0.3,1.5,1,2.2c0.6,0.6,1.6,0.9,3,0.9h11.5c1.3,0,2.3-0.6,2.8-1.7c0.3-0.7,0.5-1.3,0.5-1.9v-8.9C168,24.5,167.7,23.8,167,23.1 z M152.8,27c0-0.8,0.5-1.2,1.6-1.2h8.6c1.1,0,1.6,0.4,1.6,1.3v1.1h-11.8V27z M164.5,32.8c0,0.5-0.1,0.9-0.3,1.1 c-0.2,0.2-0.6,0.3-1.2,0.3h-8.8c-1.1,0-1.7-0.4-1.5-1.2c0-0.1,0-0.1,0-0.1l0-1.2h11.8L164.5,32.8z"/>
</G>
</Svg>
);
}
}
- Back.js返回按鈕
import React, { Component } from 'react';
import Svg, {
Circle,
G,
Path,
Polygon,
} from 'react-native-svg';
export default class Back extends Component {
render(){
return (
<Svg width={9} height={17}>
<G scale={0.34}>
<Path stroke="#ff5942" d="M24,3 L3,25 L24,47" strokeWidth={4} strokeCap="round" strokeJoin= "round" fill="none"/>
</G>
</Svg>
);
}
}