|
1 | | -### 快速上手 |
| 1 | +# React Native UIW Template |
2 | 2 |
|
| 3 | +一个基于 [uiw/react-native](https://github.com/uiwjs/react-native-uiw) 的 React Native 模板。 |
| 4 | + |
| 5 | +## 安装与使用 |
| 6 | + |
| 7 | +🚧 此模板仅适用于新的 CLI。 此模板适用于 >= 0.61 的 React Native 版本。 它没有用以前的版本进行测试。 |
| 8 | + |
| 9 | +**关于遗留 CLI 的注意事项** |
| 10 | + |
| 11 | +🚧 遗留的 CLI 似乎有些混乱。 此模板仅适用于新的 CLI。 确保您首先卸载了旧版 `react-native-cli (npm uninstall -g react-native-cli)`,以便下面的命令正常工作。 |
| 12 | + |
| 13 | +```bash |
| 14 | +npm uninstall -g react-native-cli |
| 15 | +``` |
| 16 | +更多信息可以在这里找到:[react-native-community/cli](https://github.com/react-native-community/cli#about) |
| 17 | + |
| 18 | +**🚧🚧 如果你不想使用 `react-native@0.70.0`或更高版本的[帮助](https://github.com/facebook/react-native/issues/34608#)** |
| 19 | + |
| 20 | +```bash |
| 21 | +Check whether your ruby version is higher than 2.7.5 |
| 22 | +``` |
| 23 | +```bash |
| 24 | +bundle install |
| 25 | +cd ios && bundle exec pod install |
| 26 | + |
| 27 | +``` |
| 28 | + |
| 29 | +**🚧🚧 配备 M1 的 MacBook Pro 🚧🚧** |
| 30 | + |
| 31 | +```bash |
| 32 | +# Install ffi |
| 33 | +sudo arch -x86_64 gem install ffi |
| 34 | +rm -rf Pods Podfile.lock |
| 35 | +# Clear pods. |
| 36 | +pod deintegrate |
| 37 | +# pod rm Podfile.lock |
| 38 | +arch -x86_64 pod install |
| 39 | +# Re-install pods |
| 40 | +arch -x86_64 pod install --repo-update --verbose |
| 41 | +yarn run ios # Run instructions for iOS |
| 42 | +yarn run api |
| 43 | +``` |
| 44 | + |
| 45 | +**`react-native@0.61.0` 或更高版本** |
| 46 | + |
| 47 | +```sh |
| 48 | +npx react-native init MyApp --template @uiw/react-native-template |
| 49 | +# npx react-native init MyApp --template @uiw/react-native-template@v1.0.0 |
| 50 | +``` |
| 51 | + |
| 52 | +**如果你不想使用 `npx`** |
| 53 | + |
| 54 | +您还可以全局安装新的 CLI(`npm i -g @react-native-community/cli` 或 `yarn global add @react-native-community/cli`) |
| 55 | + |
| 56 | +```bash |
| 57 | +npx react-native init MyApp --template @uiw/react-native-template |
| 58 | +cd MyApp/ios |
| 59 | +# Installing CocoaPods dependencies |
| 60 | +pod install |
| 61 | +``` |
| 62 | + |
| 63 | +```bash |
| 64 | +# This will initialize new project using template from TEMPLATE_NAME package |
| 65 | +npx react-native init ProjectName --template ${TEMPLATE_NAME} |
| 66 | +# This will initialize new project using init command from react-native@VERSION |
| 67 | +# but will use TEMPLATE_NAME custom template |
| 68 | +npx react-native@${VERSION} init ProjectName --template ${TEMPLATE_NAME} |
| 69 | +``` |
| 70 | + |
| 71 | +## 快速开始 |
| 72 | +```bash |
| 73 | +npx react-native init MyApp --template @uiw/react-native-template |
| 74 | +``` |
| 75 | +## 开发启动 |
| 76 | +```bash |
| 77 | +cd ios/ && pod install && cd ../ |
| 78 | + |
| 79 | +# Mocker API |
| 80 | +npm run api |
| 81 | + |
| 82 | +# Run the app with iOS. |
| 83 | +npm run ios |
| 84 | +``` |
| 85 | + |
| 86 | +## 默认账号密码 |
| 87 | + |
| 88 | +账号: admin |
| 89 | +密码: admin! |
| 90 | + |
| 91 | +## 目录结构 |
| 92 | + |
| 93 | +``` |
| 94 | +
|
| 95 | +├── mocker # mocker data |
| 96 | +├── android # native android code |
| 97 | +├── ios # native ios code |
| 98 | +├── src # code directory |
| 99 | +│ ├── components # react components |
| 100 | +│ ├── models # The models brings together state, reducers, async actions & action creators in one place |
| 101 | +│ ├── pages # route pages |
| 102 | +│ ├── routes # route configuration |
| 103 | +│ ├── services # api request |
| 104 | +│ ├── utils # public method |
| 105 | +│ ├── App.js # route entery page |
| 106 | +│ ├── config.js # app configuration |
| 107 | +│ └── global.js # Store some global objects for easy calling |
| 108 | +├── .eslintrc # eslint configuration |
| 109 | +├── index.js # app entry file |
| 110 | +└── package.json # This document is all you need to know about what’s required in your package.json file. |
| 111 | +``` |
| 112 | +## 新增页面 |
| 113 | + |
| 114 | +在 src / pages 下创建新的 js 文件。 如果有多个相关页面,您可以创建一个新文件夹来放置相关文件 |
| 115 | +```bash |
| 116 | +src |
| 117 | + models |
| 118 | + pages |
| 119 | ++ NewPage |
| 120 | ++ index.js |
| 121 | + ... |
| 122 | +... |
| 123 | +package.json |
| 124 | +``` |
| 125 | + |
| 126 | +为了更好的演示,我们初始化NewPage/index.js的内容如下: |
| 127 | +```jsx |
| 128 | +import React, {Component} from 'react'; |
| 129 | +import {View, Text, SafeAreaView} from 'react-native'; |
| 130 | + |
| 131 | +export default class MyNewPage extends Component { |
| 132 | + render() { |
| 133 | + return ( |
| 134 | + <SafeAreaView> |
| 135 | + <View> |
| 136 | + <Text>我的</Text> |
| 137 | + </View> |
| 138 | + </SafeAreaView> |
| 139 | + ); |
| 140 | + } |
| 141 | +} |
| 142 | +``` |
| 143 | +将文件加入菜单和路由 |
| 144 | +在 src / routes 下homeTab.js中使用 component 配置我们页面到路由中 |
| 145 | +```jsx |
| 146 | +import MyNewPage from '../pages/NewPage'; |
| 147 | + |
| 148 | +export const stackPageData = [ |
| 149 | + { |
| 150 | + name: 'MyNewPage', |
| 151 | + component: MyNewPage, |
| 152 | + options: { |
| 153 | + title: '我的', |
| 154 | + }, |
| 155 | + }, |
| 156 | +]; |
| 157 | +``` |
| 158 | +路由配置完成后,访问页面即可看到效果,如需要配置 `title`,`tabBarIcon`,`header`等更多设置可以在这里找到[React Navigation](https://reactnavigation.org/docs/stack-navigator/) |
| 159 | + |
| 160 | +如此回到之前新建的 NewPage.js,可以开始写业务代码了! |
0 commit comments