|
| 1 | +#restackx-core/ react-native |
| 2 | +restackx-core是一个前端快速开发框架,目前支持react-native。 |
| 3 | + |
| 4 | +### 使用说明 |
| 5 | + |
| 6 | +>1. 创建自己的react-native工程(react-native init app)。[如何搭建RN工程](https://facebook.github.io/react-native/docs/getting-started.html) |
| 7 | +> |
| 8 | +>2. 安装依赖:`react-native-router-flux `, ` mobx, mobx-react` ` restackx-core`。 |
| 9 | +> |
| 10 | +>3. 配置入口文件(` index.js, routes.js, store,js`)。 |
| 11 | +> |
| 12 | +
|
| 13 | +##### index.js: |
| 14 | + |
| 15 | + import React from 'react' |
| 16 | + import {Routers} from './routes' |
| 17 | + import Store from './store' |
| 18 | + import {App} from "restackx-core/lib/native"; |
| 19 | + |
| 20 | + function setup() { |
| 21 | + class Root extends React.Component { |
| 22 | + render(){ |
| 23 | + return ( |
| 24 | + <App store={Store} routes={Routers()}/> |
| 25 | + ) |
| 26 | + } |
| 27 | + } |
| 28 | + return Root; |
| 29 | + } |
| 30 | + |
| 31 | +##### routes.js: |
| 32 | + |
| 33 | + /* |
| 34 | + * 添加指定组件路由 |
| 35 | + * */ |
| 36 | + import React from 'react'; |
| 37 | + import {Scene} from 'react-native-router-flux'; |
| 38 | + import LoginPage from './users/LoginPage'; |
| 39 | + export const Routers = () => { |
| 40 | + return ( |
| 41 | + <Scene overlay> |
| 42 | + <Scene key="box" leftButtonTextStyle={{color: '#9c28ff'}} |
| 43 | + rightButtonTextStyle={{color: '#9c28ff'}} |
| 44 | + backButtonTextStyle={{color: '#9c28ff'}} initial> |
| 45 | + <Scene key="loginModal" component={LoginPage} title="Login"initial/> |
| 46 | + </Scene> |
| 47 | + </Scene> |
| 48 | + ) |
| 49 | +}; |
| 50 | + |
| 51 | +##### store.js: |
| 52 | + |
| 53 | + import HomePageModel from './models/HomePage.model' |
| 54 | + //这里添加所要导入的xxx.model.js |
| 55 | + |
| 56 | + export default { |
| 57 | + "HomePage" : new HomePageModel(), |
| 58 | + } |
| 59 | + |
| 60 | +#### 注意: |
| 61 | +使用[MobX](https://mobx.js.org/)需要安装一些 babel 插件,以支持 ES7 的 decorator 特性: |
| 62 | + |
| 63 | + npm i babel-plugin-transform-decorators-legacy babel-preset-react-native-stage-0 --save-dev` |
| 64 | + |
| 65 | +在项目工程的 .babelrc 文件配置 babel 插件: |
| 66 | + |
| 67 | + { |
| 68 | + 'presets': ['react-native'], |
| 69 | + 'plugins': ['transform-decorators-legacy'] |
| 70 | + } |
| 71 | + |
0 commit comments