From b355b6e3d55eee147eed09f619ec8a6881d5a048 Mon Sep 17 00:00:00 2001 From: Masoud Fallahpourbaee Date: Wed, 20 Dec 2023 14:42:14 +0100 Subject: [PATCH] Rename event 'onBeforeLoad' to 'onLoadStart' and event 'onProgressChange' to 'onLoadProgress' --- .../StandaloneWebViewScreen.tsx | 8 ++++---- .../KlarnaStandaloneWebViewEvent.java | 4 ++-- .../KlarnaStandaloneWebViewEventSender.java | 4 ++-- .../KlarnaStandaloneWebViewManager.java | 6 +++--- ios/Sources/KlarnaStandaloneWebViewManager.mm | 4 ++-- .../newarch/KlarnaStandaloneWebViewWrapper.mm | 10 +++++----- .../oldarch/KlarnaStandaloneWebViewWrapper.h | 4 ++-- .../oldarch/KlarnaStandaloneWebViewWrapper.mm | 8 ++++---- src/KlarnaStandaloneWebView.tsx | 20 +++++++++---------- .../KlarnaStandaloneWebViewNativeComponent.ts | 6 +++--- 10 files changed, 36 insertions(+), 38 deletions(-) diff --git a/TestApp/src/standalonewebview/StandaloneWebViewScreen.tsx b/TestApp/src/standalonewebview/StandaloneWebViewScreen.tsx index 9e278044..37289aa6 100644 --- a/TestApp/src/standalonewebview/StandaloneWebViewScreen.tsx +++ b/TestApp/src/standalonewebview/StandaloneWebViewScreen.tsx @@ -119,8 +119,8 @@ export default function StandaloneWebViewScreen() { flex: 1, }} returnUrl={'returnUrl://'} - onBeforeLoad={(event: KlarnaWebViewNavigationEvent) => { - onEvent('onBeforeLoad', JSON.stringify(event)); + onLoadStart={(event: KlarnaWebViewNavigationEvent) => { + onEvent('onLoadStart', JSON.stringify(event)); }} onLoad={(event: KlarnaWebViewNavigationEvent) => { onEvent('onLoad', JSON.stringify(event)); @@ -128,8 +128,8 @@ export default function StandaloneWebViewScreen() { onLoadError={(event: KlarnaWebViewNavigationError) => { onEvent('onLoadError', JSON.stringify(event)); }} - onProgressChange={(event: KlarnaWebViewProgressEvent) => { - onEvent('onProgressChange', JSON.stringify(event)); + onLoadProgress={(event: KlarnaWebViewProgressEvent) => { + onEvent('onLoadProgress', JSON.stringify(event)); }} onKlarnaMessage={(event: KlarnaWebViewKlarnaMessageEvent) => { onEvent('onKlarnaMessage', JSON.stringify(event)); diff --git a/android/src/main/java/com/klarna/mobile/sdk/reactnative/standalonewebview/KlarnaStandaloneWebViewEvent.java b/android/src/main/java/com/klarna/mobile/sdk/reactnative/standalonewebview/KlarnaStandaloneWebViewEvent.java index b4a6829e..6990e73e 100644 --- a/android/src/main/java/com/klarna/mobile/sdk/reactnative/standalonewebview/KlarnaStandaloneWebViewEvent.java +++ b/android/src/main/java/com/klarna/mobile/sdk/reactnative/standalonewebview/KlarnaStandaloneWebViewEvent.java @@ -19,13 +19,13 @@ public class KlarnaStandaloneWebViewEvent extends Event() {{ put(PARAM_NAME_PROGRESS_EVENT, webViewStateMap); }}); - postEventForView(KlarnaStandaloneWebViewEvent.Event.ON_PROGRESS_CHANGE, params, view); + postEventForView(KlarnaStandaloneWebViewEvent.Event.ON_LOAD_PROGRESS, params, view); } public void sendLoadErrorEvent(@Nullable KlarnaStandaloneWebView view, String description) { @@ -132,7 +132,7 @@ private ReadableMap buildNavigationEventMap(@Nullable KlarnaStandaloneWebView vi } else { return ArgumentsUtil.createMap(new HashMap<>() {{ // Possible values for 'event' are 'willLoad', 'loadStarted', and 'loadEnded' - put(PARAM_NAME_EVENT, event == KlarnaStandaloneWebViewEvent.Event.ON_BEFORE_LOAD ? "loadStarted" : "loadEnded"); + put(PARAM_NAME_EVENT, event == KlarnaStandaloneWebViewEvent.Event.ON_LOAD_START ? "loadStarted" : "loadEnded"); put(PARAM_NAME_NEW_URL, view.getUrl()); put(PARAM_NAME_WEB_VIEW_STATE, buildWebViewStateMap(view.getUrl(), view.getTitle(), view.getProgress())); }}); diff --git a/android/src/main/java/com/klarna/mobile/sdk/reactnative/standalonewebview/KlarnaStandaloneWebViewManager.java b/android/src/main/java/com/klarna/mobile/sdk/reactnative/standalonewebview/KlarnaStandaloneWebViewManager.java index 1b9b8e1b..7cee7aca 100644 --- a/android/src/main/java/com/klarna/mobile/sdk/reactnative/standalonewebview/KlarnaStandaloneWebViewManager.java +++ b/android/src/main/java/com/klarna/mobile/sdk/reactnative/standalonewebview/KlarnaStandaloneWebViewManager.java @@ -60,7 +60,7 @@ public void onError(@NonNull KlarnaComponent klarnaComponent, @NonNull KlarnaMob private final KlarnaStandaloneWebViewClient klarnaStandaloneWebViewClient = new KlarnaStandaloneWebViewClient() { @Override public void onPageStarted(@Nullable KlarnaStandaloneWebView view, @Nullable String url, @Nullable Bitmap favicon) { - klarnaStandaloneWebViewEventSender.sendNavigationEvent(view, KlarnaStandaloneWebViewEvent.Event.ON_BEFORE_LOAD); + klarnaStandaloneWebViewEventSender.sendNavigationEvent(view, KlarnaStandaloneWebViewEvent.Event.ON_LOAD_START); } @Override @@ -173,10 +173,10 @@ public void reload(KlarnaStandaloneWebView view) { @Override public Map getExportedCustomDirectEventTypeConstants() { MapBuilder.Builder builder = MapBuilder.builder(); - builder.put(KlarnaStandaloneWebViewEvent.Event.ON_BEFORE_LOAD.name, MapBuilder.of("registrationName", KlarnaStandaloneWebViewEvent.Event.ON_BEFORE_LOAD.name)); + builder.put(KlarnaStandaloneWebViewEvent.Event.ON_LOAD_START.name, MapBuilder.of("registrationName", KlarnaStandaloneWebViewEvent.Event.ON_LOAD_START.name)); builder.put(KlarnaStandaloneWebViewEvent.Event.ON_LOAD.name, MapBuilder.of("registrationName", KlarnaStandaloneWebViewEvent.Event.ON_LOAD.name)); builder.put(KlarnaStandaloneWebViewEvent.Event.ON_LOAD_ERROR.name, MapBuilder.of("registrationName", KlarnaStandaloneWebViewEvent.Event.ON_LOAD_ERROR.name)); - builder.put(KlarnaStandaloneWebViewEvent.Event.ON_PROGRESS_CHANGE.name, MapBuilder.of("registrationName", KlarnaStandaloneWebViewEvent.Event.ON_PROGRESS_CHANGE.name)); + builder.put(KlarnaStandaloneWebViewEvent.Event.ON_LOAD_PROGRESS.name, MapBuilder.of("registrationName", KlarnaStandaloneWebViewEvent.Event.ON_LOAD_PROGRESS.name)); builder.put(KlarnaStandaloneWebViewEvent.Event.ON_KLARNA_MESSAGE.name, MapBuilder.of("registrationName", KlarnaStandaloneWebViewEvent.Event.ON_KLARNA_MESSAGE.name)); builder.put(KlarnaStandaloneWebViewEvent.Event.ON_RENDER_PROCESS_GONE.name, MapBuilder.of("registrationName", KlarnaStandaloneWebViewEvent.Event.ON_RENDER_PROCESS_GONE.name)); return builder.build(); diff --git a/ios/Sources/KlarnaStandaloneWebViewManager.mm b/ios/Sources/KlarnaStandaloneWebViewManager.mm index 636a0eb2..f5b74866 100644 --- a/ios/Sources/KlarnaStandaloneWebViewManager.mm +++ b/ios/Sources/KlarnaStandaloneWebViewManager.mm @@ -16,10 +16,10 @@ @implementation KlarnaStandaloneWebViewManager #pragma mark - View RCT_EXPORT_VIEW_PROPERTY(returnUrl, NSString) -RCT_EXPORT_VIEW_PROPERTY(onBeforeLoad, RCTDirectEventBlock) +RCT_EXPORT_VIEW_PROPERTY(onLoadStart, RCTDirectEventBlock) RCT_EXPORT_VIEW_PROPERTY(onLoad, RCTDirectEventBlock) RCT_EXPORT_VIEW_PROPERTY(onLoadError, RCTDirectEventBlock) -RCT_EXPORT_VIEW_PROPERTY(onProgressChange, RCTDirectEventBlock) +RCT_EXPORT_VIEW_PROPERTY(onLoadProgress, RCTDirectEventBlock) RCT_EXPORT_VIEW_PROPERTY(onKlarnaMessage, RCTDirectEventBlock) - (UIView *)view { diff --git a/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.mm b/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.mm index bf563cbb..b07775df 100644 --- a/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.mm +++ b/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.mm @@ -54,11 +54,11 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N - (void)sendProgressChangeEvent:(int)progress { if (_eventEmitter) { - RCTLogInfo(@"Sending onProgressChange event"); + RCTLogInfo(@"Sending onLoadProgress event"); NSString * url = self.klarnaStandaloneWebView.url == nil ? @"" : self.klarnaStandaloneWebView.url.absoluteString; NSString * title = self.klarnaStandaloneWebView.title == nil ? @"" : self.klarnaStandaloneWebView.title; std::dynamic_pointer_cast(_eventEmitter) - ->onProgressChange(RNKlarnaStandaloneWebViewEventEmitter::OnProgressChange{ + ->onLoadProgress(RNKlarnaStandaloneWebViewEventEmitter::OnLoadProgress{ .progressEvent = { .webViewState = { .url = std::string([url UTF8String]), @@ -139,14 +139,14 @@ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args { - (void)klarnaStandaloneWebView:(KlarnaStandaloneWebView * _Nonnull)webView didCommit:(WKNavigation * _Nonnull)navigation { if (_eventEmitter) { - RCTLogInfo(@"Sending onBeforeLoad event"); + RCTLogInfo(@"Sending onLoadStart event"); // 'estimatedProgress' is a double value in range [0..1]. // We need to convert it to an int value in range [0..100]. int progress = (int) (self.klarnaStandaloneWebView.estimatedProgress * 100); std::dynamic_pointer_cast(_eventEmitter) - ->onBeforeLoad(RNKlarnaStandaloneWebViewEventEmitter::OnBeforeLoad{ + ->onLoadStart(RNKlarnaStandaloneWebViewEventEmitter::OnLoadStart{ .navigationEvent = { - .event = facebook::react::RNKlarnaStandaloneWebViewEventEmitter::OnBeforeLoadNavigationEventEvent::LoadStarted, + .event = facebook::react::RNKlarnaStandaloneWebViewEventEmitter::OnLoadStartNavigationEventEvent::LoadStarted, .newUrl = std::string([webView.url.absoluteString UTF8String]), .webViewState = { .url = std::string([webView.url.absoluteString UTF8String]), diff --git a/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.h b/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.h index 986613fc..80e039c5 100644 --- a/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.h +++ b/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.h @@ -11,10 +11,10 @@ NS_ASSUME_NONNULL_BEGIN @interface KlarnaStandaloneWebViewWrapper : UIView -@property (nonatomic, copy) RCTDirectEventBlock onBeforeLoad; +@property (nonatomic, copy) RCTDirectEventBlock onLoadStart; @property (nonatomic, copy) RCTDirectEventBlock onLoad; @property (nonatomic, copy) RCTDirectEventBlock onLoadError; -@property (nonatomic, copy) RCTDirectEventBlock onProgressChange; +@property (nonatomic, copy) RCTDirectEventBlock onLoadProgress; @property (nonatomic, copy) RCTDirectEventBlock onKlarnaMessage; @property (nonatomic, strong) NSString* returnUrl; diff --git a/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.mm b/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.mm index 54a1bf5a..3f515ff8 100644 --- a/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.mm +++ b/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.mm @@ -42,11 +42,11 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N } - (void)sendProgressChangeEvent:(int)progress { - if (!self.onProgressChange) { + if (!self.onLoadProgress) { RCTLog(@"Missing 'onProgressChange' callback prop."); return; } - self.onProgressChange(@{ + self.onLoadProgress(@{ @"progressEvent": @{ @"webViewState": @{ @"url": self.klarnaStandaloneWebView.url == nil ? @"" : self.klarnaStandaloneWebView.url.absoluteString, @@ -120,12 +120,12 @@ - (void)reload { #pragma mark - KlarnaStandaloneWebViewDelegate methods - (void)klarnaStandaloneWebView:(KlarnaStandaloneWebView * _Nonnull)webView didCommit:(WKNavigation * _Nonnull)navigation { - if (!self.onBeforeLoad) { + if (!self.onLoadStart) { RCTLog(@"Missing 'onBeforeLoad' callback prop."); return; } int progress = (int) (webView.estimatedProgress * 100); - self.onBeforeLoad(@{ + self.onLoadStart(@{ @"navigationEvent": @{ @"event": @"loadStarted", @"newUrl": webView.url.absoluteString, diff --git a/src/KlarnaStandaloneWebView.tsx b/src/KlarnaStandaloneWebView.tsx index ed0c6f83..4130eb02 100644 --- a/src/KlarnaStandaloneWebView.tsx +++ b/src/KlarnaStandaloneWebView.tsx @@ -12,16 +12,14 @@ import RNKlarnaStandaloneWebView, { export interface KlarnaWebViewProps { style?: ViewStyle; readonly returnUrl: string; - readonly onBeforeLoad?: ( + readonly onLoadStart?: ( navigationEvent: KlarnaWebViewNavigationEvent ) => void; readonly onLoad?: (navigationEvent: KlarnaWebViewNavigationEvent) => void; readonly onLoadError?: ( navigationError: KlarnaWebViewNavigationError ) => void; - readonly onProgressChange?: ( - progressEvent: KlarnaWebViewProgressEvent - ) => void; + readonly onLoadProgress?: (progressEvent: KlarnaWebViewProgressEvent) => void; readonly onKlarnaMessage?: ( klarnaMessageEvent: KlarnaWebViewKlarnaMessageEvent ) => void; @@ -51,7 +49,7 @@ export class KlarnaStandaloneWebView extends Component< ref={this.standaloneWebViewRef} style={this.props.style} returnUrl={this.props.returnUrl || ''} - onBeforeLoad={( + onLoadStart={( event: NativeSyntheticEvent< Readonly<{ readonly navigationEvent: Readonly<{ @@ -67,8 +65,8 @@ export class KlarnaStandaloneWebView extends Component< }> > ) => { - if (this.props.onBeforeLoad != null) { - this.props.onBeforeLoad(event.nativeEvent.navigationEvent); + if (this.props.onLoadStart != null) { + this.props.onLoadStart(event.nativeEvent.navigationEvent); } }} onLoad={( @@ -104,7 +102,7 @@ export class KlarnaStandaloneWebView extends Component< this.props.onLoadError(event.nativeEvent.navigationError); } }} - onProgressChange={( + onLoadProgress={( event: NativeSyntheticEvent< Readonly<{ readonly progressEvent: Readonly<{ @@ -118,8 +116,8 @@ export class KlarnaStandaloneWebView extends Component< }> > ) => { - if (this.props.onProgressChange != null) { - this.props.onProgressChange(event.nativeEvent.progressEvent); + if (this.props.onLoadProgress != null) { + this.props.onLoadProgress(event.nativeEvent.progressEvent); } }} onKlarnaMessage={( @@ -211,7 +209,7 @@ export interface KlarnaWebViewProgressEvent { export interface KlarnaWebViewKlarnaMessageEvent { readonly action: string; - // Dictionary is not support for events + // Dictionary is not supported for events // readonly params: { [key: string]: any }; // TODO What is a KlarnaWebViewComponent? // readonly component: KlarnaWebViewComponent; diff --git a/src/specs/KlarnaStandaloneWebViewNativeComponent.ts b/src/specs/KlarnaStandaloneWebViewNativeComponent.ts index c8793892..c47e1003 100644 --- a/src/specs/KlarnaStandaloneWebViewNativeComponent.ts +++ b/src/specs/KlarnaStandaloneWebViewNativeComponent.ts @@ -7,10 +7,10 @@ import React from 'react'; export interface RNKlarnaStandaloneWebViewProps extends ViewProps { returnUrl: string; - onBeforeLoad: DirectEventHandler; + onLoadStart: DirectEventHandler; onLoad: DirectEventHandler; onLoadError: DirectEventHandler; - onProgressChange: DirectEventHandler; + onLoadProgress: DirectEventHandler; onKlarnaMessage: DirectEventHandler; /* Android only */ onRenderProcessGone: DirectEventHandler; @@ -53,7 +53,7 @@ type KlarnaWebViewProgressEvent = Readonly<{ type KlarnaWebViewKlarnaMessageEvent = Readonly<{ klarnaMessageEvent: Readonly<{ action: string; - // Dictionary is not support for events + // Dictionary is not supported for events // params: { [key: string]: any }; // TODO What is a KlarnaWebViewComponent? // component: KlarnaWebViewComponent;