@bravemobile/react-native-code-push 12.4.0 → 12.4.1

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
@@ -8,7 +8,7 @@
8
8
 
9
9
  ### 🚀 New Architecture support
10
10
 
11
- Supports React Native 0.77 ~ 0.84.
11
+ Supports React Native 0.77 ~ 0.86.
12
12
 
13
13
  > [!NOTE]
14
14
  > If you are using React Native 0.76 or lower, please use version `12.0.2` of this library.
@@ -341,19 +341,28 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule {
341
341
  try {
342
342
  JSONObject mutableUpdatePackage = CodePushUtils.convertReadableToJsonObject(updatePackage);
343
343
  mUpdateManager.downloadPackage(mutableUpdatePackage, mCodePush.getAssetsBundleFileName(), new DownloadProgressCallback() {
344
- private boolean hasScheduledNextFrame = false;
345
- private DownloadProgress latestDownloadProgress = null;
344
+ private volatile boolean hasScheduledNextFrame = false;
345
+ private volatile DownloadProgress latestDownloadProgress = null;
346
+ private final DownloadProgressEventDispatcher progressEventDispatcher = new DownloadProgressEventDispatcher(
347
+ new DownloadProgressEventDispatcher.EventEmitter() {
348
+ @Override
349
+ public void emit(DownloadProgress downloadProgress) {
350
+ getReactApplicationContext()
351
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
352
+ .emit(CodePushConstants.DOWNLOAD_PROGRESS_EVENT_NAME, downloadProgress.createWritableMap());
353
+ }
354
+ });
346
355
 
347
356
  @Override
348
357
  public void call(DownloadProgress downloadProgress) {
349
- if (!notifyProgress) {
358
+ if (!notifyProgress || downloadProgress == null) {
350
359
  return;
351
360
  }
352
361
 
353
362
  latestDownloadProgress = downloadProgress;
354
363
  // If the download is completed, synchronously send the last event.
355
- if (latestDownloadProgress.isCompleted()) {
356
- dispatchDownloadProgressEvent();
364
+ if (downloadProgress.isCompleted()) {
365
+ progressEventDispatcher.dispatch(downloadProgress);
357
366
  return;
358
367
  }
359
368
 
@@ -368,22 +377,16 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule {
368
377
  ReactChoreographer.getInstance().postFrameCallback(ReactChoreographer.CallbackType.TIMERS_EVENTS, new Choreographer.FrameCallback() {
369
378
  @Override
370
379
  public void doFrame(long frameTimeNanos) {
371
- if (!latestDownloadProgress.isCompleted()) {
372
- dispatchDownloadProgressEvent();
380
+ try {
381
+ progressEventDispatcher.dispatch(latestDownloadProgress);
382
+ } finally {
383
+ hasScheduledNextFrame = false;
373
384
  }
374
-
375
- hasScheduledNextFrame = false;
376
385
  }
377
386
  });
378
387
  }
379
388
  });
380
389
  }
381
-
382
- public void dispatchDownloadProgressEvent() {
383
- getReactApplicationContext()
384
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
385
- .emit(CodePushConstants.DOWNLOAD_PROGRESS_EVENT_NAME, latestDownloadProgress.createWritableMap());
386
- }
387
390
  });
388
391
 
389
392
  JSONObject newPackage = mUpdateManager.getPackage(CodePushUtils.tryGetString(updatePackage, CodePushConstants.PACKAGE_HASH_KEY));
@@ -27,4 +27,8 @@ class DownloadProgress {
27
27
  public boolean isCompleted() {
28
28
  return mTotalBytes == mReceivedBytes;
29
29
  }
30
+
31
+ long getReceivedBytes() {
32
+ return mReceivedBytes;
33
+ }
30
34
  }
@@ -0,0 +1,23 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ class DownloadProgressEventDispatcher {
4
+ interface EventEmitter {
5
+ void emit(DownloadProgress downloadProgress);
6
+ }
7
+
8
+ private final EventEmitter mEventEmitter;
9
+ private long mLastDispatchedBytes = -1;
10
+
11
+ DownloadProgressEventDispatcher(EventEmitter eventEmitter) {
12
+ mEventEmitter = eventEmitter;
13
+ }
14
+
15
+ synchronized void dispatch(DownloadProgress downloadProgress) {
16
+ if (downloadProgress == null || downloadProgress.getReceivedBytes() <= mLastDispatchedBytes) {
17
+ return;
18
+ }
19
+
20
+ mEventEmitter.emit(downloadProgress);
21
+ mLastDispatchedBytes = downloadProgress.getReceivedBytes();
22
+ }
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bravemobile/react-native-code-push",
3
- "version": "12.4.0",
3
+ "version": "12.4.1",
4
4
  "description": "React Native plugin for the CodePush service",
5
5
  "main": "src/CodePush.js",
6
6
  "react-native": "src/CodePush.js",