Skip to content

Commit

Permalink
Rename event 'onLoad' to 'onLoadEnd'
Browse files Browse the repository at this point in the history
  • Loading branch information
MasoudFallahpourbaee committed Dec 22, 2023
1 parent 4b5de26 commit aefac65
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions TestApp/src/standalonewebview/StandaloneWebViewScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, {useRef, useState} from 'react';
import {
KlarnaStandaloneWebView,
KlarnaWebViewKlarnaMessageEvent,
KlarnaWebViewNavigationError,
KlarnaWebViewError,
KlarnaWebViewNavigationEvent,
KlarnaWebViewProgressEvent,
KlarnaWebViewRenderProcessGoneEvent,
Expand Down Expand Up @@ -122,10 +122,10 @@ export default function StandaloneWebViewScreen() {
onLoadStart={(event: KlarnaWebViewNavigationEvent) => {
onEvent('onLoadStart', JSON.stringify(event));
}}
onLoad={(event: KlarnaWebViewNavigationEvent) => {
onEvent('onLoad', JSON.stringify(event));
onLoadEnd={(event: KlarnaWebViewNavigationEvent) => {
onEvent('onLoadEnd', JSON.stringify(event));
}}
onError={(event: KlarnaWebViewNavigationError) => {
onError={(event: KlarnaWebViewError) => {
onEvent('onError', JSON.stringify(event));
}}
onLoadProgress={(event: KlarnaWebViewProgressEvent) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum Event {
// This event is sent just before loading a URL
ON_LOAD_START("onLoadStart"),
// This event is sent when loading a URL is done
ON_LOAD("onLoad"),
ON_LOAD_END("onLoadEnd"),
// This event is sent when loading a URL encounters an error
ON_ERROR("onError"),
// This event is sent when the progress of loading a page changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void onPageStarted(@Nullable KlarnaStandaloneWebView view, @Nullable Stri

@Override
public void onPageFinished(@Nullable KlarnaStandaloneWebView view, @Nullable String url) {
klarnaStandaloneWebViewEventSender.sendNavigationEvent(view, KlarnaStandaloneWebViewEvent.Event.ON_LOAD, url);
klarnaStandaloneWebViewEventSender.sendNavigationEvent(view, KlarnaStandaloneWebViewEvent.Event.ON_LOAD_END, url);
}

@Override
Expand Down Expand Up @@ -174,7 +174,7 @@ public void reload(KlarnaStandaloneWebView view) {
public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
MapBuilder.Builder<String, Object> builder = MapBuilder.builder();
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_END.name, MapBuilder.of("registrationName", KlarnaStandaloneWebViewEvent.Event.ON_LOAD_END.name));
builder.put(KlarnaStandaloneWebViewEvent.Event.ON_ERROR.name, MapBuilder.of("registrationName", KlarnaStandaloneWebViewEvent.Event.ON_ERROR.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));
Expand Down
2 changes: 1 addition & 1 deletion ios/Sources/KlarnaStandaloneWebViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ @implementation KlarnaStandaloneWebViewManager

RCT_EXPORT_VIEW_PROPERTY(returnUrl, NSString)
RCT_EXPORT_VIEW_PROPERTY(onLoadStart, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLoad, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLoadEnd, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onError, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLoadProgress, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onKlarnaMessage, RCTDirectEventBlock)
Expand Down
4 changes: 2 additions & 2 deletions ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ - (void)klarnaStandaloneWebView:(KlarnaStandaloneWebView * _Nonnull)webView didC

- (void)klarnaStandaloneWebView:(KlarnaStandaloneWebView * _Nonnull)webView didFinish:(WKNavigation * _Nonnull)navigation {
if (_eventEmitter) {
RCTLogInfo(@"Sending onLoad event");
RCTLogInfo(@"Sending onLoadEnd event");
// 'estimatedProgress' is a double value in range [0..1].
// We need to convert it to an int value in range [0..100].
std::dynamic_pointer_cast<const RNKlarnaStandaloneWebViewEventEmitter>(_eventEmitter)
->onLoad(RNKlarnaStandaloneWebViewEventEmitter::OnLoad{
->onLoadEnd(RNKlarnaStandaloneWebViewEventEmitter::OnLoadEnd{
.navigationEvent = {
.url = std::string([webView.url.absoluteString UTF8String]),
.title = std::string([webView.title UTF8String]),
Expand Down
2 changes: 1 addition & 1 deletion ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface KlarnaStandaloneWebViewWrapper : UIView

@property (nonatomic, copy) RCTDirectEventBlock onLoadStart;
@property (nonatomic, copy) RCTDirectEventBlock onLoad;
@property (nonatomic, copy) RCTDirectEventBlock onLoadEnd;
@property (nonatomic, copy) RCTDirectEventBlock onError;
@property (nonatomic, copy) RCTDirectEventBlock onLoadProgress;
@property (nonatomic, copy) RCTDirectEventBlock onKlarnaMessage;
Expand Down
6 changes: 3 additions & 3 deletions ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ - (void)klarnaStandaloneWebView:(KlarnaStandaloneWebView * _Nonnull)webView didC
}

- (void)klarnaStandaloneWebView:(KlarnaStandaloneWebView * _Nonnull)webView didFinish:(WKNavigation * _Nonnull)navigation {
if (!self.onLoad) {
RCTLog(@"Missing 'onLoad' callback prop.");
if (!self.onLoadEnd) {
RCTLog(@"Missing 'onLoadEnd' callback prop.");
return;
}
NSMutableDictionary<NSString *, id> *event = [self webViewDict:webView];
self.onLoad(@{@"navigationEvent": event});
self.onLoadEnd(@{@"navigationEvent": event});
}

- (void)klarnaStandaloneWebView:(KlarnaStandaloneWebView * _Nonnull)webView didFailProvisionalNavigation:(WKNavigation * _Nonnull)navigation withError:(NSError * _Nonnull)error {
Expand Down
8 changes: 4 additions & 4 deletions src/KlarnaStandaloneWebView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface KlarnaWebViewProps {
readonly onLoadStart?: (
navigationEvent: KlarnaWebViewNavigationEvent
) => void;
readonly onLoad?: (navigationEvent: KlarnaWebViewNavigationEvent) => void;
readonly onLoadEnd?: (navigationEvent: KlarnaWebViewNavigationEvent) => void;
readonly onError?: (navigationError: KlarnaWebViewError) => void;
readonly onLoadProgress?: (progressEvent: KlarnaWebViewProgressEvent) => void;
readonly onKlarnaMessage?: (
Expand Down Expand Up @@ -65,7 +65,7 @@ export class KlarnaStandaloneWebView extends Component<
this.props.onLoadStart(event.nativeEvent.navigationEvent);
}
}}
onLoad={(
onLoadEnd={(
event: NativeSyntheticEvent<
Readonly<{
readonly navigationEvent: Readonly<{
Expand All @@ -78,8 +78,8 @@ export class KlarnaStandaloneWebView extends Component<
}>
>
) => {
if (this.props.onLoad != null) {
this.props.onLoad(event.nativeEvent.navigationEvent);
if (this.props.onLoadEnd != null) {
this.props.onLoadEnd(event.nativeEvent.navigationEvent);
}
}}
onError={(
Expand Down
2 changes: 1 addition & 1 deletion src/specs/KlarnaStandaloneWebViewNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { Double, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
export interface RNKlarnaStandaloneWebViewProps extends ViewProps {
returnUrl: string;
onLoadStart: DirectEventHandler<KlarnaWebViewNavigationEvent>;
onLoad: DirectEventHandler<KlarnaWebViewNavigationEvent>;
onLoadEnd: DirectEventHandler<KlarnaWebViewNavigationEvent>;
onError: DirectEventHandler<KlarnaWebViewError>;
onLoadProgress: DirectEventHandler<KlarnaWebViewProgressEvent>;
onKlarnaMessage: DirectEventHandler<KlarnaWebViewKlarnaMessageEvent>;
Expand Down

0 comments on commit aefac65

Please sign in to comment.