Skip to content

Commit 018b426

Browse files
author
徐远翔
committed
refactor: remove package: umi-plugin-antd-react-native
Some **peer dependencies** of `@ant-design/react-native` were **excluded** after **4.0.0**. BREAKING CHANGE: You need to follow the [installation document](https://github.com/ant-design/ant-design-mobile-rn#install--usage) to install `@ant-design/react-native` directly.
1 parent ce32efd commit 018b426

File tree

27 files changed

+213
-340
lines changed

27 files changed

+213
-340
lines changed

README.md

+118-78
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,38 @@
44

55
针对 [react-native](https://reactnative.dev/) 应用的 [umi](https://umijs.org/) 插件集。
66

7-
**零配置**,添加[dva](https://dvajs.com/)[@ant-design/react-native](https://rn.mobile.ant.design/index-cn)... 依赖后开箱即用
8-
9-
默认使用[react-router](https://reacttraining.com/react-router/),可选[react-navigation](https://reactnavigation.org/)
7+
- **零配置**,添加[DvaJS](https://dvajs.com/)[@ant-design/react-native](https://rn.mobile.ant.design/index-cn)... 依赖后开箱即用,只需专注于业务代码;
8+
- 路由方案默认使用 umi 内置的[react-router](https://reacttraining.com/react-router/),可平滑替换为[react-navigation](https://reactnavigation.org/)
9+
- 支持切分多 bundle,运行时按需加载 bundle,降低内存开销,提升首屏加载速度;
1010

1111
[发布日志](/CHANGELOG.md)
1212

1313
## 目录
1414

1515
- [必备](#%E5%BF%85%E5%A4%87)
1616
- [安装](#%E5%AE%89%E8%A3%85)
17-
- [集成 dva](#%E9%9B%86%E6%88%90-dva)
17+
- [集成 DvaJS](#%E9%9B%86%E6%88%90-dvajs)
1818
- [集成 @ant-design/react-native](#%E9%9B%86%E6%88%90-ant-designreact-native)
1919
- [使用](#%E4%BD%BF%E7%94%A8)
2020
- [配置](#%E9%85%8D%E7%BD%AE)
2121
- [目前支持的 umi 配置项](#%E7%9B%AE%E5%89%8D%E6%94%AF%E6%8C%81%E7%9A%84-umi-%E9%85%8D%E7%BD%AE%E9%A1%B9)
2222
- [umi-preset-react-native 扩展配置](#umi-preset-react-native-%E6%89%A9%E5%B1%95%E9%85%8D%E7%BD%AE)
23-
- [路由](#%E8%B7%AF%E7%94%B1)
24-
- [react-router](#react-router)
25-
- [`Link`组件在 RN 和 DOM 中存在差异](#link%E7%BB%84%E4%BB%B6%E5%9C%A8-rn-%E5%92%8C-dom-%E4%B8%AD%E5%AD%98%E5%9C%A8%E5%B7%AE%E5%BC%82)
26-
- [没有`NavLink`组件](#%E6%B2%A1%E6%9C%89navlink%E7%BB%84%E4%BB%B6)
27-
- [新增`BackButton``AndroidBackButton`组件](#%E6%96%B0%E5%A2%9Ebackbutton%E5%92%8Candroidbackbutton%E7%BB%84%E4%BB%B6)
28-
- [react-navigation](#react-navigation)
2923
- [开发](#%E5%BC%80%E5%8F%91)
3024
- [打包](#%E6%89%93%E5%8C%85)
25+
- [路由](#%E8%B7%AF%E7%94%B1)
26+
- [使用 umi 内置的 react-router](#%E4%BD%BF%E7%94%A8-umi-%E5%86%85%E7%BD%AE%E7%9A%84-react-router)
27+
- [`Link`组件在 RN 和 DOM 中存在差异](#link%E7%BB%84%E4%BB%B6%E5%9C%A8-rn-%E5%92%8C-dom-%E4%B8%AD%E5%AD%98%E5%9C%A8%E5%B7%AE%E5%BC%82)
28+
- [没有`NavLink`组件](#%E6%B2%A1%E6%9C%89navlink%E7%BB%84%E4%BB%B6)
29+
- [新增`BackButton``AndroidBackButton`组件](#%E6%96%B0%E5%A2%9Ebackbutton%E5%92%8Candroidbackbutton%E7%BB%84%E4%BB%B6)
30+
- [替换为 react-navigation](#%E6%9B%BF%E6%8D%A2%E4%B8%BA-react-navigation)
3131
- [示例](#%E7%A4%BA%E4%BE%8B)
3232
- [深入](#%E6%B7%B1%E5%85%A5)
3333
- [切分多 bundle](#%E5%88%87%E5%88%86%E5%A4%9A-bundle)
3434
- [FAQ](#faq)
35-
- [`hmrClient.send is not a function`](#hmrclientsend-is-not-a-function)
36-
- [`Live Reloading`, `Fast Refresh`, `Hot Replacement`无法使用](#live-reloading-fast-refresh-hot-replacement%E6%97%A0%E6%B3%95%E4%BD%BF%E7%94%A8)
35+
- [hmrClient.send is not a function](#hmrclientsend-is-not-a-function)
36+
- [Live Reloading, Fast Refresh, Hot Replacement... 无法使用](#live-reloading-fast-refresh-hot-replacement-%E6%97%A0%E6%B3%95%E4%BD%BF%E7%94%A8)
37+
- [@ant-design/react-native 组件没有工作(比如:弹窗打不开等等)](#ant-designreact-native-%E7%BB%84%E4%BB%B6%E6%B2%A1%E6%9C%89%E5%B7%A5%E4%BD%9C%E6%AF%94%E5%A6%82%E5%BC%B9%E7%AA%97%E6%89%93%E4%B8%8D%E5%BC%80%E7%AD%89%E7%AD%89)
38+
- [使用@ant-design/react-native 组件时,报错:Unrecognized font family 'antoutline'](#%E4%BD%BF%E7%94%A8ant-designreact-native-%E7%BB%84%E4%BB%B6%E6%97%B6%E6%8A%A5%E9%94%99unrecognized-font-family-antoutline)
3739

3840
## 必备
3941

@@ -70,22 +72,39 @@ npx react-native init UMIRNExample
7072
yarn add umi umi-preset-react-native --dev
7173
```
7274

73-
### 集成 dva
75+
### 集成 DvaJS
7476

7577
在 RN 工程根目录下使用 yarn 添加`@umijs/plugin-dva`依赖:
7678

7779
```npm
7880
yarn add @umijs/plugin-dva --dev
7981
```
8082

83+
_待 yarn 安装完成后开箱即用。_
84+
8185
### 集成 @ant-design/react-native
8286

83-
在 RN 工程根目录下使用 yarn 添加[umi-plugin-antd-react-native](/packages/umi-plugin-antd-react-native/README.md)依赖:
87+
在 RN 工程根目录下使用 yarn 添加`@ant-design/react-native``@ant-design/icons-react-native`依赖:
88+
89+
```npm
90+
yarn add @ant-design/react-native @ant-design/icons-react-native
91+
```
92+
93+
**RN`0.60.0`及以上版本**[自动链接](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md)`@ant-design/icons-react-native`,待 yarn 安装完成后,如果是 iOS 需要:
94+
95+
```shell
96+
cd ios && pod install
97+
```
98+
99+
**RN`0.50.x`版本**,待 yarn 安装完成,还需要使用`react-native link`**手动链接**`@ant-design/icons-react-native`:
84100

85101
```npm
86-
yarn add umi-plugin-antd-react-native --dev
102+
yarn react-native link @ant-design/icons-react-native
103+
# ./node_modules/.bin/react-native link @ant-design/icons-react-native
87104
```
88105

106+
**umi-preset-react-native**已经为`@ant-design/react-native`添加了[**按需加载**](https://rn.mobile.ant.design/docs/react/introduce-cn#%E6%8C%89%E9%9C%80%E5%8A%A0%E8%BD%BD)[babel-plugin-import](https://github.com/ant-design/babel-plugin-import))的配置。
107+
89108
## 使用
90109

91110
### 配置
@@ -123,7 +142,7 @@ _与 DOM 无关的[umi](https://umijs.org/)插件都是可以使用的,或者
123142
- [x] [routes](https://umijs.org/config#routes)
124143
- [x] [singular](https://umijs.org/config#singular)
125144

126-
_上文未列出的[umi 配置](https://umijs.org/config)**umi-preset-react-native** 不生效。RN 开发不同于 Web 开发,基本上无须在编译工具上做过多配置。_
145+
_上文未列出的[umi 配置](https://umijs.org/config)**umi-preset-react-native** 不生效。_
127146

128147
[haul](https://github.com/callstack/haul)使用的 devServer 是[hapi](https://hapi.dev/),目前还不支持扩展额外的 hapi 插件(中间件),暂时无法支持[mock](https://umijs.org/config#mock)[proxy](https://umijs.org/config#proxy)功能。
129148

@@ -146,22 +165,68 @@ export default {
146165
};
147166
```
148167

149-
- `reactNative`:选填,默认值:上面代码示例中的值
168+
- `reactNative`:选填,默认值:上面代码示例中的值
150169
- `haul`:选填,默认值:上面代码示例中的值,即[Project Configuration](https://github.com/callstack/haul/blob/master/docs/Configuration.md#project-configuration-reference)
151170

152-
**注意**:不需要使用 haul 提供的工具:`makeConfig``withPolyfills`。直接填入[Project Configuration](https://github.com/callstack/haul/blob/master/docs/Configuration.md#project-configuration-reference)的字段即可。
171+
### 开发
172+
173+
修改`package.json`文件,使用`umi`取代`react-native`
174+
175+
```diff
176+
{
177+
"scripts": {
178+
"android": "react-native run-android",
179+
"ios": "react-native run-ios",
180+
- "start": "react-native start",
181+
+ "start": "umi dev-rn",
182+
},
183+
}
184+
```
185+
186+
执行`yarn start`之后,再使用 `yarn android` 或者 `yarn ios`
187+
188+
### 打包
189+
190+
构建离线包(offline bundle):
191+
192+
```shell
193+
umi build-rn --platform <ios|android> --bundle-output <relative/to/output/path/filename> --assets-dest <relative/to/output/path>
194+
```
153195

154-
在做多 bundle 切分时,要保证主 bundle 中必须包含`./umi.ts`
196+
_`relative/to/output/path`: 表示相对于[outputPath](https://umijs.org/config#outputpath)的路径。_
155197

156-
### 路由
198+
package.json:
157199

158-
#### react-router
200+
```diff
201+
{
202+
"scripts": {
203+
"android": "react-native run-android",
204+
"ios": "react-native run-ios",
205+
"start": "umi dev-rn",
206+
+ "build:ios": "NODE_ENV=production umi build-rn --platform ios --bundle-output ios/main.jsbundle --assets-dest ios/assets",
207+
+ "build:android": "NODE_ENV=production umi build-rn --platform android --bundle-output android/index.android.bundle --assets-dest android/assets"
208+
},
209+
}
210+
```
211+
212+
- 执行`yarn build:ios`
213+
1. 构建生成`main.jsbundle`文件到`dist/ios/`目录;
214+
2. 拷贝静态资源到`dist/ios/assets/`目录。
215+
- 执行`yarn build:android`
216+
1. 构建生成`index.android.bundle`文件到`dist/anrdoid/`目录;
217+
2. 拷贝静态资源到`dist/android/assets/`目录。
218+
219+
_`dist`[outputPath](https://umijs.org/config#outputpath)配置项的缺省(默认)值,可在`.umirc.js`中配置其他目录。_
220+
221+
## 路由
222+
223+
### 使用 umi 内置的 react-router
159224

160225
[umi](https://umijs.org/)内置了`react-router-dom`**umi-preset-react-native**在运行时会将其替换为:`react-router-native`
161226

162227
二者都基于 [react-router](https://reacttraining.com/react-router/),但存在一些差异。
163228

164-
##### `Link`组件在 RN 和 DOM 中存在差异
229+
#### `Link`组件在 RN 和 DOM 中存在差异
165230

166231
以下是`react-router-native` `Link`组件的属性:
167232

@@ -196,7 +261,7 @@ function Index() {
196261
}
197262
```
198263

199-
##### 没有`NavLink`组件
264+
#### 没有`NavLink`组件
200265

201266
`react-router-native`没有`NavLink`组件,当你尝试引入时会得到`undefined`
202267

@@ -206,7 +271,7 @@ import { NavLink } from 'umi';
206271
typeof NavLink === 'undefined'; // true;
207272
```
208273

209-
##### 新增`BackButton``AndroidBackButton`组件
274+
#### 新增`BackButton``AndroidBackButton`组件
210275

211276
对于 RN 应用,需要在[全局 layout](https://umijs.org/docs/convention-routing#%E5%85%A8%E5%B1%80-layout)中使用`BackButton`作为根容器:
212277

@@ -230,61 +295,11 @@ export default Layout;
230295

231296
这样做,当用户使用**系统返回键**时会返回应用的上一个路由,而不是退出应用。
232297

233-
#### react-navigation
298+
### 替换为 react-navigation
234299

235300
[react-navigation](https://reactnavigation.org/)可作为 umi 默认[react-router](https://reacttraining.com/react-router/)**替代方案**
236301

237-
了解详情,请移步至:<a href="https://github.com/xuyuanxiang/umi-react-native/tree/master/packages/umi-plugin-react-navigation#readme" target="_blank">umi-plugin-react-navigation 文档</a>。
238-
239-
### 开发
240-
241-
修改`package.json`文件,使用`umi`取代`react-native`
242-
243-
```diff
244-
{
245-
"scripts": {
246-
"android": "react-native run-android",
247-
"ios": "react-native run-ios",
248-
- "start": "react-native start",
249-
+ "start": "umi dev-rn",
250-
},
251-
}
252-
```
253-
254-
执行`yarn start`之后,再使用 `yarn android` 或者 `yarn ios`
255-
256-
### 打包
257-
258-
构建离线包(offline bundle):
259-
260-
```shell
261-
umi build-rn --platform <ios|android> --bundle-output <relative/to/output/path/filename> --assets-dest <relative/to/output/path>
262-
```
263-
264-
_`relative/to/output/path`: 表示相对于[outputPath](https://umijs.org/config#outputpath)的路径。_
265-
266-
package.json:
267-
268-
```diff
269-
{
270-
"scripts": {
271-
"android": "react-native run-android",
272-
"ios": "react-native run-ios",
273-
"start": "umi dev-rn",
274-
+ "build:ios": "NODE_ENV=production umi build-rn --platform ios --bundle-output ios/main.jsbundle --assets-dest ios/assets",
275-
+ "build:android": "NODE_ENV=production umi build-rn --platform android --bundle-output android/index.android.bundle --assets-dest android/assets"
276-
},
277-
}
278-
```
279-
280-
- 执行`yarn build:ios`
281-
1. 构建生成`main.jsbundle`文件到`dist/ios/`目录;
282-
2. 拷贝静态资源到`dist/ios/assets/`目录。
283-
- 执行`yarn build:android`
284-
1. 构建生成`index.android.bundle`文件到`dist/anrdoid/`目录;
285-
2. 拷贝静态资源到`dist/android/assets/`目录。
286-
287-
_`dist`[outputPath](https://umijs.org/config#outputpath)配置项的缺省(默认)值,可在`.umirc.js`中配置其他目录。_
302+
了解详情,请移步至:<a href="https://github.com/xuyuanxiang/umi-react-native/tree/master/packages/umi-plugin-react-navigation#readme" target="_blank">umi-plugin-react-navigation</a>。
288303

289304
## 示例
290305

@@ -338,9 +353,14 @@ export default {
338353
};
339354
```
340355

356+
**注意**
357+
358+
- **不要**使用 haul 提供的工具:`makeConfig``withPolyfills`
359+
- ****保证主 bundle 中必须包含:`./umi.ts`
360+
341361
## FAQ
342362

343-
### `hmrClient.send is not a function`
363+
### hmrClient.send is not a function
344364

345365
当出现以下错误时需要升级`metro``^0.56.0`[react-native#issue-26958](https://github.com/facebook/react-native/issues/26958)
346366

@@ -356,6 +376,26 @@ _在 RN 工程`node_modules`目录中找到`metro`并查看版本:_
356376
cat ./node_modules/metro/package.json | grep version
357377
```
358378

359-
### `Live Reloading`, `Fast Refresh`, `Hot Replacement`无法使用
379+
### Live Reloading, Fast Refresh, Hot Replacement... 无法使用
360380

361381
[haul](https://github.com/callstack/haul)不支持:[haul#issue-682](https://github.com/callstack/haul/issues/682)
382+
383+
### @ant-design/react-native 组件没有工作(比如:弹窗打不开等等)
384+
385+
按照[@ant-design/react-native](https://rn.mobile.ant.design/docs/react/introduce-cn)文档示例使用组件时,未能达到预期效果,可能是因为没有使用`Provider`作为根节点:
386+
387+
```jsx
388+
// <projectRoot>/layouts/index.js
389+
import React from 'react';
390+
import { Provider } from '@ant-design/react-native';
391+
392+
function Layout({ children }) {
393+
return <Provider>{children}</Provider>;
394+
}
395+
396+
export default Layout;
397+
```
398+
399+
### 使用@ant-design/react-native 组件时,报错:Unrecognized font family 'antoutline'
400+
401+
[ant-design/ant-design-mobile-rn#issue-194](https://github.com/ant-design/ant-design-mobile-rn/issues/194)中有解决方案。

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"bootstrap": "lerna bootstrap",
66
"clean": "rimraf packages/*/lib",
77
"build": "cross-env NODE_ENV=production lerna run build",
8-
"watch": "cross-env NODE_ENV=development lerna run watch --parallel --concurrency 4",
8+
"watch": "cross-env NODE_ENV=development lerna run watch --parallel --concurrency 3",
99
"test": "cross-env NODE_ENV=test jest --coverage",
1010
"changelog": "node scripts/changelog",
1111
"prerelease": "yarn build",
@@ -18,8 +18,11 @@
1818
"devDependencies": {
1919
"@types/jest": "^25.2.1",
2020
"@types/node": "10.x",
21+
"@types/react": "^16.9.34",
22+
"@types/react-native": "^0.62.7",
2123
"@typescript-eslint/eslint-plugin": "^2.28.0",
2224
"@typescript-eslint/parser": "^2.28.0",
25+
"@umijs/types": "^3.0.0",
2326
"conventional-changelog": "^3.1.18",
2427
"cross-env": "^7.0.2",
2528
"eslint": "^6.8.0",

packages/umi-plugin-antd-react-native/README.md

-9
This file was deleted.

packages/umi-plugin-antd-react-native/package.json

-50
This file was deleted.

packages/umi-plugin-antd-react-native/src/index.ts

-12
This file was deleted.

0 commit comments

Comments
 (0)