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

Compare commits

...

5 Commits

13 changed files with 94 additions and 20 deletions

View File

@@ -12,7 +12,7 @@
"react-native-paper": "^5.14.5",
"react-native-safe-area-context": "^5.6.1",
"react-native-svg": "^15.13.0",
"react-native-update": "^10.34.4",
"react-native-update": "^10.35.6",
"react-native-vector-icons": "^10.3.0",
},
"devDependencies": {
@@ -1430,7 +1430,7 @@
"react-native-svg": ["react-native-svg@15.13.0", "", { "dependencies": { "css-select": "^5.1.0", "css-tree": "^1.1.3", "warn-once": "0.1.1" }, "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-/YPK+PAAXg4T0x2d2vYPvqqAhOYid2bRKxUVT7STIyd1p2JxWmsGQkfZxXCkEFN7TwLfIyVlT5RimT91Pj/qXw=="],
"react-native-update": ["react-native-update@10.34.4", "", { "dependencies": { "nanoid": "^3.3.3", "react-native-url-polyfill": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-native": ">=0.59.0" } }, "sha512-yuXlff7EMUDyp1js2NylOw9jT0sVXoc5rpaRhzoYYcwfQTQq1Qp53qpyupDuUj43MEv5ikfJ6xBd/iRpXuanNg=="],
"react-native-update": ["react-native-update@10.35.6", "", { "dependencies": { "nanoid": "^3.3.3", "react-native-url-polyfill": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-native": ">=0.59.0" } }, "sha512-2k16I1QdI4wVbepaXjf+Ej9vSpnL7hpzTknitK0s4dI+hVah+cKVntnIexW4DdIpyTk7abCLVJH4MUFGjlaUSQ=="],
"react-native-url-polyfill": ["react-native-url-polyfill@2.0.0", "", { "dependencies": { "whatwg-url-without-unicode": "8.0.0-3" }, "peerDependencies": { "react-native": "*" } }, "sha512-My330Do7/DvKnEvwQc0WdcBnFPploYKp9CYlefDXzIdEaA+PAhDYllkvGeEroEzvc4Kzzj2O4yVdz8v6fjRvhA=="],

View File

@@ -1835,7 +1835,7 @@ PODS:
- ReactCommon/turbomodule/core
- SocketRocket
- Yoga
- react-native-update (10.34.4):
- react-native-update (10.35.6):
- boost
- DoubleConversion
- fast_float
@@ -1854,7 +1854,7 @@ PODS:
- React-graphics
- React-ImageManager
- React-jsi
- react-native-update/RCTPushy (= 10.34.4)
- react-native-update/RCTPushy (= 10.35.6)
- React-NativeModulesApple
- React-RCTFabric
- React-renderercss
@@ -1866,7 +1866,7 @@ PODS:
- SocketRocket
- SSZipArchive
- Yoga
- react-native-update/RCTPushy (10.34.4):
- react-native-update/RCTPushy (10.35.6):
- boost
- DoubleConversion
- fast_float
@@ -2800,7 +2800,7 @@ SPEC CHECKSUMS:
React-Mapbuffer: 9d2434a42701d6144ca18f0ca1c4507808ca7696
React-microtasksnativemodule: 75b6604b667d297292345302cc5bfb6b6aeccc1b
react-native-safe-area-context: c6e2edd1c1da07bdce287fa9d9e60c5f7b514616
react-native-update: 822780a6d3c8482d47ba50b5801ed295c0dfcaff
react-native-update: 5e2274c66e654b001fae360600f5a9314c1c67e1
React-NativeModulesApple: 879fbdc5dcff7136abceb7880fe8a2022a1bd7c3
React-oscompat: 93b5535ea7f7dff46aaee4f78309a70979bdde9d
React-perflogger: 5536d2df3d18fe0920263466f7b46a56351c0510

View File

@@ -21,7 +21,7 @@
"react-native-paper": "^5.14.5",
"react-native-safe-area-context": "^5.6.1",
"react-native-svg": "^15.13.0",
"react-native-update": "^10.34.4",
"react-native-update": "^10.35.6",
"react-native-vector-icons": "^10.3.0"
},
"devDependencies": {

View File

@@ -19,6 +19,33 @@
7. meta 信息及开放 API提供更高扩展性。
8. 提供付费的专人技术支持。
### 与其他热更新库对比
| 对比维度 | react-native-update | expo-update | react-native-code-push |
|---------|---------------------|-------------|------------------------|
| **价格/成本** | 提供免费额度,多级梯度付费(最低约 66 元/月),流量不单独计费 | 提供免费额度,多级梯度付费(最低约 136 元/月),超出流量额外计费 | ❌ **已停运**Microsoft App Center 已于 2025 年 3 月 31 日停止服务) |
| **更新包大小** | ⭐⭐⭐⭐⭐ 几十 KB增量更新 | ⭐⭐⭐ 全量更新(通常几十 MB | ❌ **已停运** |
| **中国地区访问速度** | ⭐⭐⭐⭐⭐ 阿里云 CDN速度极快 | ⭐⭐ 国外服务器,可能较慢 | ❌ **已停运** |
| **iOS 支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
| **Android 支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
| **鸿蒙支持** | ✅ 支持 | ❌ 不支持 | ❌ **已停运** |
| **Expo 支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
| **RN 版本支持** | ⭐⭐⭐⭐⭐ 第一时间支持最新版本 | ⭐⭐⭐⭐ 跟随 Expo SDK | ❌ **已停运** |
| **新架构支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
| **Hermes 支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
| **崩溃回滚** | ✅ 自动回滚机制 | ✅ 支持 | ❌ **已停运** |
| **管理界面** | ✅ 命令行工具 + Web 管理界面 | ✅ Expo Dashboard | ❌ **已停运** |
| **CI/CD 集成** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
| **API 扩展性** | ✅ Meta 信息 + 开放 API | ⚠️ 有限 | ❌ **已停运** |
| **中文文档/支持** | ⭐⭐⭐⭐⭐ 完整中文文档,中文社区支持 | ⭐⭐ 英文为主 | ❌ **已停运** |
| **技术支持** | ✅ 付费专人技术支持 | ⚠️ 社区支持 | ❌ **已停运** |
| **服务器部署** | ✅ 可托管也可付费私有部署 | ✅ Expo 托管EAS Update | ❌ **已停运** |
| **更新策略** | 灵活配置(静默/提示/立即/延迟) | 相对固定 | ❌ **已停运** |
| **流量消耗** | ⭐⭐⭐⭐⭐ 极低(增量更新) | ⭐⭐⭐ 较高(全量更新) | ❌ **已停运** |
| **更新成功率** | ⭐⭐⭐⭐⭐ 极高(国内 CDN 优势) | ⭐⭐⭐ 中等 | ❌ **已停运** |
### 本地开发
```

View File

@@ -22,6 +22,10 @@ public class UpdateContext {
public static boolean DEBUG = false;
private static ReactInstanceManager mReactInstanceManager;
private static boolean isUsingBundleUrl = false;
// Singleton instance
private static UpdateContext sInstance;
private static final Object sLock = new Object();
public UpdateContext(Context context) {
this.context = context;
@@ -54,13 +58,17 @@ public class UpdateContext {
boolean buildTimeChanged = !buildTime.equals(storedBuildTime);
if (packageVersionChanged || buildTimeChanged) {
// Execute cleanUp before clearing SharedPreferences to avoid race condition
this.cleanUp();
SharedPreferences.Editor editor = sp.edit();
editor.clear();
editor.putString("packageVersion", packageVersion);
editor.putString("buildTime", buildTime);
editor.apply();
this.cleanUp();
// Use commit() instead of apply() to ensure synchronous write completion
// This prevents race condition where getBundleUrl() might read null values
// if called before apply() completes
editor.commit();
}
}
@@ -227,12 +235,26 @@ public class UpdateContext {
return mReactInstanceManager;
}
/**
* Get singleton instance of UpdateContext
*/
public static UpdateContext getInstance(Context context) {
if (sInstance == null) {
synchronized (sLock) {
if (sInstance == null) {
sInstance = new UpdateContext(context.getApplicationContext());
}
}
}
return sInstance;
}
public static String getBundleUrl(Context context) {
return new UpdateContext(context.getApplicationContext()).getBundleUrl();
return getInstance(context).getBundleUrl();
}
public static String getBundleUrl(Context context, String defaultAssetsUrl) {
return new UpdateContext(context.getApplicationContext()).getBundleUrl(defaultAssetsUrl);
return getInstance(context).getBundleUrl(defaultAssetsUrl);
}
public String getBundleUrl() {

View File

@@ -27,7 +27,7 @@ public class UpdateModule extends NativePushySpec {
}
public UpdateModule(ReactApplicationContext reactContext) {
this(reactContext, new UpdateContext(reactContext.getApplicationContext()));
this(reactContext, UpdateContext.getInstance(reactContext));
}
@Override

View File

@@ -40,7 +40,7 @@ public class UpdateModule extends ReactContextBaseJavaModule {
}
public UpdateModule(ReactApplicationContext reactContext) {
this(reactContext, new UpdateContext(reactContext.getApplicationContext()));
this(reactContext, UpdateContext.getInstance(reactContext));
}
@Override

View File

@@ -37,10 +37,10 @@ export class UpdateContext {
this.preferences.putSync('packageVersion', packageVersion);
this.preferences.flush();
} else if (storedVersion && packageVersion !== storedVersion) {
this.cleanUp();
this.preferences.clear();
this.preferences.putSync('packageVersion', packageVersion);
this.preferences.flush();
this.cleanUp();
}
} catch (e) {
console.error('Failed to init preferences:', e);

View File

@@ -1,6 +1,6 @@
{
"name": "react-native-update",
"version": "10.35.6",
"version": "10.35.8",
"description": "react-native hot update",
"main": "src/index",
"scripts": {

View File

@@ -1,6 +1,7 @@
import { createContext, useContext } from 'react';
import { CheckResult, ProgressData } from './type';
import { Pushy, Cresc } from './client';
import i18n from './i18n';
const noop = () => {};
const asyncNoop = () => Promise.resolve();
@@ -50,7 +51,16 @@ export const UpdateContext = createContext<{
lastError?: Error;
}>(defaultContext);
export const useUpdate = () => useContext(UpdateContext);
export const useUpdate = __DEV__ ? () => {
const context = useContext(UpdateContext);
// 检查是否在 UpdateProvider 内部使用
if (!context.client) {
throw new Error(i18n.t('error_use_update_outside_provider'));
}
return context;
} : () => useContext(UpdateContext);
/** @deprecated Please use `useUpdate` instead */
export const usePushy = useUpdate;

View File

@@ -71,4 +71,8 @@ export default {
// Development environment messages
dev_incremental_update_disabled:
'Currently in development environment, incremental hot update cannot be executed and restart will not take effect. If you need to test effective full hot update in development environment (but will reconnect to metro after restart), please enable "ignore timestamp" switch and retry.',
// Context error messages
error_use_update_outside_provider:
'useUpdate must be used within an UpdateProvider. Please wrap your component tree with <UpdateProvider client={...}>.',
};

View File

@@ -68,4 +68,8 @@ export default {
// Development environment messages
dev_incremental_update_disabled:
'当前是开发环境,无法执行增量式热更新,重启不会生效。如果需要在开发环境中测试可生效的全量热更新(但也会在再次重启后重新连接 metro请打开"忽略时间戳"开关再重试。',
// Context error messages
error_use_update_outside_provider:
'useUpdate 必须在 UpdateProvider 内部使用。请使用 <UpdateProvider client={...}> 包裹您的组件树。',
};

View File

@@ -13,7 +13,12 @@ import {
Linking,
} from 'react-native';
import { Pushy, Cresc, sharedState } from './client';
import { currentVersion, packageVersion, getCurrentVersionInfo, currentVersionInfo } from './core';
import {
currentVersion,
packageVersion,
getCurrentVersionInfo,
currentVersionInfo,
} from './core';
import {
CheckResult,
ProgressData,
@@ -165,7 +170,7 @@ export const UpdateProvider = ({
lastChecking.current = now;
let rootInfo: CheckResult | undefined;
try {
rootInfo = await client.checkUpdate(extra);
rootInfo = { ...(await client.checkUpdate(extra)) };
} catch (e: any) {
setLastError(e);
alertError(client.t('error_update_check_failed'), e.message);
@@ -175,7 +180,9 @@ export const UpdateProvider = ({
if (!rootInfo) {
return;
}
const versions = [rootInfo.expVersion, rootInfo].filter(Boolean) as VersionInfo[];
const versions = [rootInfo.expVersion, rootInfo].filter(
Boolean,
) as VersionInfo[];
delete rootInfo.expVersion;
for (const versionInfo of versions) {
const info: CheckResult = {