react-native-ota-hot-update 2.3.4 → 2.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -146,9 +146,14 @@ Open `MainApplication.kt` and add these codes bellow:
146
146
  ```bash
147
147
  import com.otahotupdate.OtaHotUpdate
148
148
  ...
149
- override fun getJSBundleFile(): String? {
150
- return OtaHotUpdate.bundleJS(this@MainApplication)
151
- }
149
+ override val reactNativeHost: ReactNativeHost =
150
+ object : DefaultReactNativeHost(this) {
151
+ ...
152
+ override fun getJSBundleFile(): String? {
153
+ return OtaHotUpdate.bundleJS(this@MainApplication)
154
+ }
155
+ ...
156
+ }
152
157
 
153
158
  ```
154
159
 
@@ -161,6 +166,22 @@ MainApplication.java:
161
166
  }
162
167
  ```
163
168
 
169
+ ### Android in react native 0.82 or above:
170
+
171
+ ```bash
172
+ override val reactHost: ReactHost by lazy {
173
+ getDefaultReactHost(
174
+ context = applicationContext,
175
+ packageList =
176
+ PackageList(this).packages.apply {
177
+ // Packages that cannot be autolinked yet can be added manually here, for example:
178
+ // add(MyReactNativePackage())
179
+ },
180
+ jsBundleFilePath = OtaHotUpdate.bundleJS(applicationContext)
181
+ )
182
+ }
183
+ ```
184
+
164
185
  For java it maybe can be like: `OtaHotUpdate.Companion.getBundleJS(this)` depend on kotlin / jdk version on your project, you can use android studio to get the correct format coding.
165
186
 
166
187
  If want to remove bundle wrong handler, pass false param in getBundleJS like this:
@@ -3,6 +3,7 @@ package com.otahotupdate
3
3
  import android.content.Context
4
4
  import android.content.pm.PackageManager
5
5
  import android.os.Build
6
+ import java.io.File
6
7
  import com.facebook.react.BaseReactPackage
7
8
  import com.facebook.react.bridge.NativeModule
8
9
  import com.facebook.react.bridge.ReactApplicationContext
@@ -66,7 +67,11 @@ class OtaHotUpdate : BaseReactPackage() {
66
67
  val pathBundle = sharedPrefs.getString(PATH)
67
68
  val version = sharedPrefs.getString(VERSION)
68
69
  val currentVersionName = sharedPrefs.getString(CURRENT_VERSION_CODE)
69
- if (pathBundle == "" || (currentVersionName != context.getVersionCode())) {
70
+ val hasBundlePath = !pathBundle.isNullOrBlank()
71
+ val isSameAppVersion = currentVersionName == context.getVersionCode()
72
+ val bundleFileExists = hasBundlePath && File(pathBundle!!).isFile
73
+
74
+ if (!hasBundlePath || !isSameAppVersion || !bundleFileExists) {
70
75
  if (pathBundle != "") {
71
76
  sharedPrefs.putString(PATH, "")
72
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ota-hot-update",
3
- "version": "2.3.4",
3
+ "version": "2.3.6",
4
4
  "description": "Hot update for react native",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",
@@ -3,17 +3,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const config_plugins_1 = require("@expo/config-plugins");
4
4
  const withAndroidAction = (config) => {
5
5
  return (0, config_plugins_1.withMainApplication)(config, (config) => {
6
- if (!config.modResults.contents.includes('override fun getJSBundleFile(): String = OtaHotUpdate.bundleJS(this@MainApplication)')) {
7
- config.modResults.contents = config.modResults.contents.replace(/override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED/g, `
8
- override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
6
+ let content = config.modResults.contents;
7
+ const isNewReactHost = content.includes('context = applicationContext');
8
+ if (!content.includes('import com.otahotupdate.OtaHotUpdate')) {
9
+ content = content.replace(/import android.app.Application/g, `
10
+ import android.app.Application
11
+ import com.otahotupdate.OtaHotUpdate`);
12
+ }
13
+ if (isNewReactHost) {
14
+ if (!content.includes('OtaHotUpdate.bundleJS')) {
15
+ content = content.replace(/context = applicationContext,/, `context = applicationContext,
16
+ jsBundleFilePath = OtaHotUpdate.bundleJS(applicationContext),
17
+ `);
18
+ }
19
+ config.modResults.contents = content;
20
+ return config;
21
+ }
22
+ if (!content.includes('OtaHotUpdate.bundleJS(this@MainApplication)')) {
23
+ content = content.replace(/DefaultReactNativeHost\s*\(this\)\s*\{/, `
24
+ DefaultReactNativeHost(this) {
9
25
 
10
26
  override fun getJSBundleFile(): String = OtaHotUpdate.bundleJS(this@MainApplication)`);
11
27
  }
12
- if (!config.modResults.contents.includes('import com.otahotupdate.OtaHotUpdate')) {
13
- config.modResults.contents = config.modResults.contents.replace(/import expo.modules.ReactNativeHostWrapper/g, `
14
- import expo.modules.ReactNativeHostWrapper
15
- import com.otahotupdate.OtaHotUpdate`);
16
- }
28
+ config.modResults.contents = content;
17
29
  return config;
18
30
  });
19
31
  };
@@ -6,24 +6,42 @@ import {
6
6
 
7
7
  const withAndroidAction: any = (config: any) => {
8
8
  return withMainApplication(config, (config) => {
9
- if (!config.modResults.contents.includes('override fun getJSBundleFile(): String = OtaHotUpdate.bundleJS(this@MainApplication)')) {
10
- config.modResults.contents = config.modResults.contents.replace(
11
- /override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED/g,
12
- `
13
- override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
9
+ let content = config.modResults.contents;
14
10
 
15
- override fun getJSBundleFile(): String = OtaHotUpdate.bundleJS(this@MainApplication)`
11
+ const isNewReactHost = content.includes('context = applicationContext');
12
+
13
+ if (!content.includes('import com.otahotupdate.OtaHotUpdate')) {
14
+ content = content.replace(
15
+ /import android.app.Application/g,
16
+ `
17
+ import android.app.Application
18
+ import com.otahotupdate.OtaHotUpdate`
16
19
  );
17
20
  }
21
+ if (isNewReactHost) {
22
+ if (!content.includes('OtaHotUpdate.bundleJS')) {
23
+ content = content.replace(
24
+ /context = applicationContext,/,
25
+ `context = applicationContext,
26
+ jsBundleFilePath = OtaHotUpdate.bundleJS(applicationContext),`
27
+ );
28
+ }
18
29
 
19
- if (!config.modResults.contents.includes('import com.otahotupdate.OtaHotUpdate')) {
20
- config.modResults.contents = config.modResults.contents.replace(
21
- /import expo.modules.ReactNativeHostWrapper/g,
30
+ config.modResults.contents = content;
31
+ return config;
32
+ }
33
+
34
+ if (!content.includes('OtaHotUpdate.bundleJS(this@MainApplication)')) {
35
+ content = content.replace(
36
+ /DefaultReactNativeHost\s*\(this\)\s*\{/,
22
37
  `
23
- import expo.modules.ReactNativeHostWrapper
24
- import com.otahotupdate.OtaHotUpdate`
38
+ DefaultReactNativeHost(this) {
39
+
40
+ override fun getJSBundleFile(): String = OtaHotUpdate.bundleJS(this@MainApplication)`
25
41
  );
26
42
  }
43
+
44
+ config.modResults.contents = content;
27
45
  return config;
28
46
  });
29
47
  };