react-native-ota-hot-update 2.1.7 → 2.1.8

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
@@ -143,7 +143,7 @@ Open `MainApplication.kt` and add these codes bellow:
143
143
  import com.otahotupdate.OtaHotUpdate
144
144
  ...
145
145
  override fun getJSBundleFile(): String? {
146
- return OtaHotUpdate.bundleJS
146
+ return OtaHotUpdate.bundleJS(this@MainApplication)
147
147
  }
148
148
 
149
149
  ```
@@ -153,11 +153,11 @@ MainApplication.java:
153
153
  @Nullable
154
154
  @Override
155
155
  protected String getJSBundleFile() {
156
- return OtaHotUpdate.getBundleJS();
156
+ return OtaHotUpdate.getBundleJS(this);
157
157
  }
158
158
  ```
159
159
 
160
- For jave it maybe can be like: `OtaHotUpdate.Companion.getBundleJS()` depend on kotlin / jdk version on your project, you can use android studio to get the correct format coding.
160
+ 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.
161
161
 
162
162
  Open `AndroidManifest.xml` :
163
163
 
@@ -4,7 +4,7 @@ import android.content.Context
4
4
  import android.content.pm.PackageInfo
5
5
  import android.content.pm.PackageManager
6
6
  import android.os.Build
7
- import com.facebook.react.TurboReactPackage
7
+ import com.facebook.react.BaseReactPackage
8
8
  import com.facebook.react.bridge.NativeModule
9
9
  import com.facebook.react.bridge.ReactApplicationContext
10
10
  import com.facebook.react.module.model.ReactModuleInfo
@@ -16,10 +16,7 @@ import com.rnhotupdate.Common.VERSION
16
16
  import com.rnhotupdate.SharedPrefs
17
17
 
18
18
 
19
- class OtaHotUpdate(context: Context?) : TurboReactPackage() {
20
- init {
21
- mContext = context
22
- }
19
+ class OtaHotUpdate : BaseReactPackage() {
23
20
  override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
24
21
  return if (name == OtaHotUpdateModule.NAME) {
25
22
  OtaHotUpdateModule(reactContext)
@@ -37,7 +34,6 @@ class OtaHotUpdate(context: Context?) : TurboReactPackage() {
37
34
  OtaHotUpdateModule.NAME,
38
35
  false, // canOverrideExistingModule
39
36
  false, // needsEagerInit
40
- true, // hasConstants
41
37
  false, // isCxxModule
42
38
  isTurboModule // isTurboModule
43
39
  )
@@ -53,24 +49,19 @@ class OtaHotUpdate(context: Context?) : TurboReactPackage() {
53
49
  packageManager.getPackageInfo(packageName, 0)
54
50
  }
55
51
  }
56
- private var mContext: Context? = null
57
- val bundleJS: String
58
- get() {
59
- if (mContext == null) {
60
- return DEFAULT_BUNDLE
61
- }
62
- val sharedPrefs = SharedPrefs(mContext!!)
63
- val pathBundle = sharedPrefs.getString(PATH)
64
- val version = sharedPrefs.getString(VERSION)
65
- val currentVersionName = sharedPrefs.getString(CURRENT_VERSION_NAME)
66
- if (pathBundle == "" || (currentVersionName != mContext?.getPackageInfo()?.versionName)) {
67
- if (version != "") {
68
- // reset version number because bundle is wrong version, need download from new version
69
- sharedPrefs.putString(VERSION, "")
70
- }
71
- return DEFAULT_BUNDLE
52
+ fun bundleJS(context: Context): String {
53
+ val sharedPrefs = SharedPrefs(context)
54
+ val pathBundle = sharedPrefs.getString(PATH)
55
+ val version = sharedPrefs.getString(VERSION)
56
+ val currentVersionName = sharedPrefs.getString(CURRENT_VERSION_NAME)
57
+ if (pathBundle == "" || (currentVersionName != context.getPackageInfo().versionName)) {
58
+ if (version != "") {
59
+ // reset version number because bundle is wrong version, need download from new version
60
+ sharedPrefs.putString(VERSION, "")
72
61
  }
73
- return pathBundle!!
62
+ return DEFAULT_BUNDLE
74
63
  }
64
+ return pathBundle!!
65
+ }
75
66
  }
76
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ota-hot-update",
3
- "version": "2.1.7",
3
+ "version": "2.1.8",
4
4
  "description": "Hot update for react native",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",
@@ -6,7 +6,7 @@ const withAndroidAction: any = (config: any) => {
6
6
  `
7
7
  override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
8
8
 
9
- override fun getJSBundleFile(): String = OtaHotUpdate.bundleJS`
9
+ override fun getJSBundleFile(): String = OtaHotUpdate.bundleJS(this@MainApplication)`
10
10
  );
11
11
  config.modResults.contents = config.modResults.contents.replace(
12
12
  /import expo.modules.ReactNativeHostWrapper/g,
@@ -6,7 +6,7 @@ module.exports = {
6
6
  platforms: {
7
7
  android: {
8
8
  cmakeListsPath: 'generated/jni/CMakeLists.txt',
9
- packageInstance: 'new OtaHotUpdate(getApplicationContext())',
9
+ packageInstance: 'new OtaHotUpdate()',
10
10
  },
11
11
  },
12
12
  },