mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-10 07:10:36 +08:00
Merge pull request #526 from Microsoft/fix-unsupported-events
Fix usage of NativeEventEmitter
This commit is contained in:
@@ -26,6 +26,9 @@ RCT_EXPORT_MODULE()
|
||||
|
||||
#pragma mark - Private constants
|
||||
|
||||
// These constants represent emitted events
|
||||
static NSString *const DownloadProgressEvent = @"CodePushDownloadProgress";
|
||||
|
||||
// These constants represent valid deployment statuses
|
||||
static NSString *const DeploymentFailed = @"DeploymentFailed";
|
||||
static NSString *const DeploymentSucceeded = @"DeploymentSucceeded";
|
||||
@@ -296,7 +299,7 @@ static NSString *bundleResourceSubdirectory = nil;
|
||||
|
||||
- (void)dispatchDownloadProgressEvent {
|
||||
// Notify the script-side about the progress
|
||||
[self sendEventWithName:@"CodePushDownloadProgress"
|
||||
[self sendEventWithName:DownloadProgressEvent
|
||||
body:@{
|
||||
@"totalBytes" : [NSNumber
|
||||
numberWithLongLong:_latestExpectedContentLength],
|
||||
@@ -537,6 +540,10 @@ static NSString *bundleResourceSubdirectory = nil;
|
||||
[preferences synchronize];
|
||||
}
|
||||
|
||||
- (NSArray<NSString *> *)supportedEvents {
|
||||
return @[DownloadProgressEvent];
|
||||
}
|
||||
|
||||
#pragma mark - Application lifecycle event handlers
|
||||
|
||||
// These two handlers will only be registered when there is
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { AcquisitionManager as Sdk } from "code-push/script/acquisition-sdk";
|
||||
import { DeviceEventEmitter } from "react-native";
|
||||
import { NativeEventEmitter } from "react-native";
|
||||
import RestartManager from "./RestartManager";
|
||||
|
||||
// This function is used to augment remote and local
|
||||
@@ -15,8 +15,9 @@ module.exports = (NativeCodePush) => {
|
||||
|
||||
let downloadProgressSubscription;
|
||||
if (downloadProgressCallback) {
|
||||
const codePushEventEmitter = new NativeEventEmitter(NativeCodePush);
|
||||
// Use event subscription to obtain download progress.
|
||||
downloadProgressSubscription = DeviceEventEmitter.addListener(
|
||||
downloadProgressSubscription = codePushEventEmitter.addListener(
|
||||
"CodePushDownloadProgress",
|
||||
downloadProgressCallback
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user