1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-09-18 00:46:10 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Compare commits

..

8 Commits

Author SHA1 Message Date
sunnylqm
3939607f49 v5.5.4 2020-01-13 22:23:10 +08:00
sunnylqm
8d06235ea3 Check android bundle file before reload 2020-01-13 21:58:33 +08:00
sunnylqm
fa754ef8a2 Check bundlejs before switch 2020-01-09 17:45:44 +08:00
sunnylqm
5a5884c8fa Fix doc link 2019-12-29 12:42:05 +08:00
sunnylqm
8bd92f2c0e Fix doc home page 2019-12-29 12:39:45 +08:00
sunnylqm
3ac2e3ef05 文档优化 2019-12-29 12:36:08 +08:00
Sunny Luo
523cbdd7e1 Update README.md 2019-12-23 10:28:02 +08:00
sunnylqm
dece044a54 Bump 5.5.3 2019-12-18 18:06:08 +08:00
10 changed files with 121 additions and 56 deletions

View File

@@ -1,31 +1,10 @@
# react-native-update [![npm version](https://badge.fury.io/js/react-native-update.svg)](http://badge.fury.io/js/react-native-update)
本组件是面向 React Native 提供热更新功能的组件,建议结合[Update 服务](https://update.reactnative.cn/)使用。
本组件是面向 React Native 提供热更新功能的组件,结合[Update 服务](https://update.reactnative.cn/)使用。
注意,在 iOS 上使用热更新有被拒的可能。被拒之后可以按以下步骤单独屏蔽 iOS 端(`react-native-update`版本需 >= 5.3.2)
### 快速开始
1. 如果 RN 版本>=0.60,在项目根目录下编辑或创建 react-native.config.js添加如下内容
```js
// react-native.config.js
module.exports = {
dependencies: {
'react-native-update': {
platforms: {
ios: null, // 阻止ios模块自动链接
},
},
},
};
```
2. 如果在原生代码端尚未配置,则跳过下面文档中的 ios 端的配置。如果已经配置,则按文档的步骤反向操作(添加的 ios 代码删去)。
3. 如果是 0.60 以上版本或使用了 cocoapods在 ios 目录中再次运行 pod install确保 Podfile 和 Podfile.lock 中都没有'react-native-update'。如果 RN 版本<0.60则运行`react-native unlink react-native-update`
4. js 代码里调用 checkUpdate()方法前判断 Platform.OS如果是 ios 平台则直接 return 跳过
### 最近更新
请查阅[最近更新文档](CHANGELOG.md)
请查看[文档](https://reactnativecn.github.io/react-native-pushy)
### 优势
@@ -35,26 +14,6 @@ module.exports = {
4. meta 信息及开放 API提供更高扩展性。
5. 跨越多个版本进行更新时,只需要下载**一个更新包**,不需要逐版本依次更新。
### 安装与快速入门
请查阅
- [文档-快速入门-准备工作](docs/guide.md)
- [文档-快速入门-添加热更新功能](docs/guide2.md)
- [文档-快速入门-发布版本](docs/guide3.md)
- [文档-常见问题与高级指南](docs/faq_advance.md)
### 命令行工具
请查阅[文档-命令行工具](docs/cli.md)
### API 接口
请查阅[文档-API 接口](docs/api.md)
### 本地开发
```

View File

@@ -4,6 +4,8 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@@ -106,8 +108,8 @@ public class UpdateContext {
private SharedPreferences sp;
public void switchVersion(String hashName) {
if (!new File(rootDir, hashName).exists()) {
throw new Error("Hash name not found, must download first.");
if (!new File(rootDir, hashName+"/index.bundlejs").exists()) {
throw new Error("Bundle version " + hashName + " not found.");
}
String lastVersion = getCurrentVersion();
SharedPreferences.Editor editor = sp.edit();
@@ -182,10 +184,18 @@ public class UpdateContext {
currentVersion = this.rollBack();
}
}
if (currentVersion == null) {
return defaultAssetsUrl;
while (currentVersion != null) {
File bundleFile = new File(rootDir, currentVersion+"/index.bundlejs");
if (!bundleFile.exists()) {
Log.e("getBundleUrl", "Bundle version " + currentVersion + " not found.");
currentVersion = this.rollBack();
continue;
}
return (new File(rootDir, currentVersion+"/index.bundlejs").toString());
return bundleFile.toString();
}
return defaultAssetsUrl;
}
private String rollBack() {

View File

@@ -123,8 +123,8 @@ public class UpdateModule extends ReactContextBaseJavaModule{
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
updateContext.switchVersion(hash);
try {
updateContext.switchVersion(hash);
Activity activity = getCurrentActivity();
Application application = activity.getApplication();
ReactInstanceManager instanceManager = ((ReactApplication) application).getReactNativeHost().getReactInstanceManager();
@@ -147,7 +147,7 @@ public class UpdateModule extends ReactContextBaseJavaModule{
}
} catch (Throwable err) {
Log.e("pushy", "Failed to restart application", err);
Log.e("pushy", "switchVersion failed", err);
}
}
});
@@ -160,7 +160,11 @@ public class UpdateModule extends ReactContextBaseJavaModule{
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
updateContext.switchVersion(hash);
} catch (Throwable err) {
Log.e("pushy", "switchVersionLater failed", err);
}
}
});
}

0
docs/.nojekyll Normal file
View File

53
docs/README.md Normal file
View File

@@ -0,0 +1,53 @@
# react-native-update [![npm version](https://badge.fury.io/js/react-native-update.svg)](http://badge.fury.io/js/react-native-update)
本组件是面向 React Native 提供热更新功能的组件,请结合[Update 服务](https://update.reactnative.cn/)使用。
<details>
<summary>
注意,在 iOS 上使用热更新有被拒的可能。被拒之后可以按此步骤单独屏蔽 iOS 端(`react-native-update`版本需 >= 5.3.2)
</summary>
1. 如果 RN 版本>=0.60,在项目根目录下编辑或创建 react-native.config.js添加如下内容
```js
// react-native.config.js
module.exports = {
dependencies: {
'react-native-update': {
platforms: {
ios: null, // 阻止ios模块自动链接
},
},
},
};
```
2. 如果在原生代码端尚未配置,则跳过下面文档中的 ios 端的配置。如果已经配置,则按文档的步骤反向操作(添加的 ios 代码删去)。
3. 如果是 0.60 以上版本或使用了 cocoapods在 ios 目录中再次运行 pod install确保 Podfile 和 Podfile.lock 中都没有'react-native-update'。如果 RN 版本<0.60则运行`react-native unlink react-native-update`
4. js 代码里调用 checkUpdate()方法前判断 Platform.OS如果是 ios 平台则直接 return 跳过
</details>
### 优势
1. 命令行工具&网页双端管理,版本发布过程简单便捷,完全可以集成 CI。
2. 基于 bsdiff 算法创建的**超小更新包**,通常版本迭代后在 1-10KB 之间,避免数百 KB 的流量消耗。
3. 支持崩溃回滚,安全可靠。
4. meta 信息及开放 API提供更高扩展性。
5. 跨越多个版本进行更新时,只需要下载**一个更新包**,不需要逐版本依次更新。
### 本地开发
```
$ git clone git@github.com:reactnativecn/react-native-pushy.git
$ cd react-native-pushy/Example/testHotUpdate
$ yarn
$ yarn start
```
本地库文件使用 yarn link 链接,因此可直接在源文件中修改,在 testHotUpdate 项目中调试。
### 关于我们
本组件由[React Native 中文网](https://reactnative.cn/)独家发布,如有定制需求可以[联系我们](https://reactnative.cn/about.html#content)。
关于此插件发现任何问题,可以前往[Issues](https://github.com/reactnativecn/react-native-pushy/issues)或者[中文社区](http://bbs.reactnative.cn/category/7)发帖提问。

10
docs/_sidebar.md Normal file
View File

@@ -0,0 +1,10 @@
- 安装与快速入门
- [准备工作](guide.md)
- [添加热更新功能](guide2.md)
- [发布版本](guide3.md)
- [常见问题与高级指南](faq_advance.md)
- [API接口](api.md)
- [命令行工具](cli.md)
- [最近更新](changelog.md)

View File

@@ -1,5 +1,9 @@
### 最近更新
## 5.5.3 (2019-12-18)
1. 忽略hermes的输出避免buffer溢出
## 5.5.2 (2019-12-06)
1. 修复使用use_frameworks时无法读取时间戳的问题

View File

@@ -52,7 +52,7 @@ npm i react-native-update@4.x
请记得一定要重新编译react-native run-ios或run-android命令编译或在Xcode/Android Studio中重新编译
## 一、手动link
## 手动link
如果RN版本 >= 0.60则可以跳过此步骤
@@ -112,7 +112,7 @@ date +%s > "$DEST/pushy_build_time.txt"
- 在`getPackages()` 方法中增加 `new UpdatePackage()`(注意上一行可能要增加一个逗号)
</details>
## 二、配置Bundle URL
## 配置Bundle URL
注意此步骤无论任何版本,目前都需要手动配置。
@@ -174,7 +174,7 @@ public class MainApplication extends Application implements ReactApplication {
}
```
## 三、登录与创建应用
## 登录与创建应用
首先请在<https://update.reactnative.cn>注册帐号,然后在你的项目根目录下运行以下命令:

25
docs/index.html Normal file
View File

@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>react-native-update - react-native hot update</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="react-native hot update">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify/lib/themes/vue.css">
</head>
<body>
<div id="app"></div>
<script>
window.$docsify = {
name: 'react-native-update',
repo: 'https://github.com/reactnativecn/react-native-pushy',
formatUpdated: '{MM}/{DD} {HH}:{mm}',
loadSidebar: true,
subMaxLevel: 2,
auto2top: true
}
</script>
<script src="//cdn.jsdelivr.net/npm/docsify/lib/docsify.min.js"></script>
</body>
</html>

View File

@@ -1,6 +1,6 @@
{
"name": "react-native-update",
"version": "5.5.3",
"version": "5.5.4",
"description": "react-native hot update",
"main": "lib/index.js",
"scripts": {