Skip to content

Commit

Permalink
Rename event 'onLoadError' to 'onError'
Browse files Browse the repository at this point in the history
  • Loading branch information
MasoudFallahpourbaee committed Dec 20, 2023
1 parent b355b6e commit 502ab4a
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 29 deletions.
4 changes: 2 additions & 2 deletions TestApp/src/standalonewebview/StandaloneWebViewScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ export default function StandaloneWebViewScreen() {
onLoad={(event: KlarnaWebViewNavigationEvent) => {
onEvent('onLoad', JSON.stringify(event));
}}
onLoadError={(event: KlarnaWebViewNavigationError) => {
onEvent('onLoadError', JSON.stringify(event));
onError={(event: KlarnaWebViewNavigationError) => {
onEvent('onError', JSON.stringify(event));
}}
onLoadProgress={(event: KlarnaWebViewProgressEvent) => {
onEvent('onLoadProgress', JSON.stringify(event));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum Event {
// This event is sent when loading a URL is done
ON_LOAD("onLoad"),
// This event is sent when loading a URL encounters an error
ON_LOAD_ERROR("onLoadError"),
ON_ERROR("onError"),
// This event is sent when the progress of loading a page changes
ON_LOAD_PROGRESS("onLoadProgress"),
// This event is sent when the Mobile SDK wants to send an event to the Web View
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ public class KlarnaStandaloneWebViewEventSender {
this.viewToDispatcher = viewToDispatcher;
}

public void sendProgressChangeEvent(@Nullable KlarnaStandaloneWebView view, int progress) {
public void sendLoadProgressEvent(@Nullable KlarnaStandaloneWebView view, int progress) {
ReadableMap webViewStateMap = (view == null) ? Arguments.createMap() : buildWebViewStateMap(view.getUrl(), view.getTitle(), progress);
WritableMap params = ArgumentsUtil.createMap(new HashMap<>() {{
put(PARAM_NAME_PROGRESS_EVENT, webViewStateMap);
}});
postEventForView(KlarnaStandaloneWebViewEvent.Event.ON_LOAD_PROGRESS, params, view);
}

public void sendLoadErrorEvent(@Nullable KlarnaStandaloneWebView view, String description) {
public void sendErrorEvent(@Nullable KlarnaStandaloneWebView view, String description) {
ReadableMap navigationErrorMap = ArgumentsUtil.createMap(new HashMap<>() {{
put(PARAM_NAME_ERROR_MESSAGE, description);
}});
WritableMap params = ArgumentsUtil.createMap(new HashMap<>() {{
put(PARAM_NAME_NAVIGATION_ERROR, navigationErrorMap);
}});
postEventForView(KlarnaStandaloneWebViewEvent.Event.ON_LOAD_ERROR, params, view);
postEventForView(KlarnaStandaloneWebViewEvent.Event.ON_ERROR, params, view);
}

public void sendNavigationEvent(@Nullable KlarnaStandaloneWebView view, KlarnaStandaloneWebViewEvent.Event event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ public void onPageFinished(@Nullable KlarnaStandaloneWebView view, @Nullable Str
@Override
public void onReceivedError(@Nullable KlarnaStandaloneWebView view, @Nullable WebResourceRequest request, @Nullable WebResourceError error) {
if (error != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
klarnaStandaloneWebViewEventSender.sendLoadErrorEvent(view, error.getDescription().toString());
klarnaStandaloneWebViewEventSender.sendErrorEvent(view, error.getDescription().toString());
}
}

@Override
public void onReceivedError(@Nullable KlarnaStandaloneWebView view, int errorCode, @Nullable String description, @Nullable String failingUrl) {
klarnaStandaloneWebViewEventSender.sendLoadErrorEvent(view, description);
klarnaStandaloneWebViewEventSender.sendErrorEvent(view, description);
}

@Override
public void onProgressChanged(@Nullable KlarnaStandaloneWebView view, int newProgress) {
klarnaStandaloneWebViewEventSender.sendProgressChangeEvent(view, newProgress);
klarnaStandaloneWebViewEventSender.sendLoadProgressEvent(view, newProgress);
}

@Override
Expand Down Expand Up @@ -175,7 +175,7 @@ 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_ERROR.name, MapBuilder.of("registrationName", KlarnaStandaloneWebViewEvent.Event.ON_LOAD_ERROR.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));
builder.put(KlarnaStandaloneWebViewEvent.Event.ON_RENDER_PROCESS_GONE.name, MapBuilder.of("registrationName", KlarnaStandaloneWebViewEvent.Event.ON_RENDER_PROCESS_GONE.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 @@ -18,7 +18,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(onLoadError, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onError, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLoadProgress, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onKlarnaMessage, RCTDirectEventBlock)

Expand Down
8 changes: 4 additions & 4 deletions ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ - (void)klarnaStandaloneWebView:(KlarnaStandaloneWebView * _Nonnull)webView didF

- (void)klarnaStandaloneWebView:(KlarnaStandaloneWebView * _Nonnull)webView didFailProvisionalNavigation:(WKNavigation * _Nonnull)navigation withError:(NSError * _Nonnull)error {
if (_eventEmitter) {
RCTLogInfo(@"Sending onLoadError event");
RCTLogInfo(@"Sending onError event");
std::dynamic_pointer_cast<const RNKlarnaStandaloneWebViewEventEmitter>(_eventEmitter)
->onLoadError(RNKlarnaStandaloneWebViewEventEmitter::OnLoadError{
->onError(RNKlarnaStandaloneWebViewEventEmitter::OnError{
.navigationError = {
.errorMessage = std::string([[error localizedDescription] UTF8String]),
}
Expand All @@ -201,9 +201,9 @@ - (void)klarnaStandaloneWebView:(KlarnaStandaloneWebView * _Nonnull)webView didF

- (void)klarnaStandaloneWebView:(KlarnaStandaloneWebView * _Nonnull)webView didFail:(WKNavigation * _Nonnull)navigation withError:(NSError * _Nonnull)error {
if (_eventEmitter) {
RCTLogInfo(@"Sending onLoadError event");
RCTLogInfo(@"Sending onError event");
std::dynamic_pointer_cast<const RNKlarnaStandaloneWebViewEventEmitter>(_eventEmitter)
->onLoadError(RNKlarnaStandaloneWebViewEventEmitter::OnLoadError{
->onError(RNKlarnaStandaloneWebViewEventEmitter::OnError{
.navigationError = {
.errorMessage = std::string([[error localizedDescription] 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 @@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, copy) RCTDirectEventBlock onLoadStart;
@property (nonatomic, copy) RCTDirectEventBlock onLoad;
@property (nonatomic, copy) RCTDirectEventBlock onLoadError;
@property (nonatomic, copy) RCTDirectEventBlock onError;
@property (nonatomic, copy) RCTDirectEventBlock onLoadProgress;
@property (nonatomic, copy) RCTDirectEventBlock onKlarnaMessage;

Expand Down
12 changes: 6 additions & 6 deletions ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,23 @@ - (void)klarnaStandaloneWebView:(KlarnaStandaloneWebView * _Nonnull)webView didF
}

- (void)klarnaStandaloneWebView:(KlarnaStandaloneWebView * _Nonnull)webView didFailProvisionalNavigation:(WKNavigation * _Nonnull)navigation withError:(NSError * _Nonnull)error {
if (!self.onLoadError) {
RCTLog(@"Missing 'onLoadError' callback prop.");
if (!self.onError) {
RCTLog(@"Missing 'onError' callback prop.");
return;
}
self.onLoadError(@{
self.onError(@{
@"navigationError": @{
@"errorMessage": error.description,
}
});
}

- (void)klarnaStandaloneWebView:(KlarnaStandaloneWebView * _Nonnull)webView didFail:(WKNavigation * _Nonnull)navigation withError:(NSError * _Nonnull)error {
if (!self.onLoadError) {
RCTLog(@"Missing 'onLoadError' callback prop.");
if (!self.onError) {
RCTLog(@"Missing 'onError' callback prop.");
return;
}
self.onLoadError(@{
self.onError(@{
@"navigationError": @{
@"errorMessage": error.description,
}
Expand Down
10 changes: 4 additions & 6 deletions src/KlarnaStandaloneWebView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ export interface KlarnaWebViewProps {
navigationEvent: KlarnaWebViewNavigationEvent
) => void;
readonly onLoad?: (navigationEvent: KlarnaWebViewNavigationEvent) => void;
readonly onLoadError?: (
navigationError: KlarnaWebViewNavigationError
) => void;
readonly onError?: (navigationError: KlarnaWebViewNavigationError) => void;
readonly onLoadProgress?: (progressEvent: KlarnaWebViewProgressEvent) => void;
readonly onKlarnaMessage?: (
klarnaMessageEvent: KlarnaWebViewKlarnaMessageEvent
Expand Down Expand Up @@ -89,7 +87,7 @@ export class KlarnaStandaloneWebView extends Component<
this.props.onLoad(event.nativeEvent.navigationEvent);
}
}}
onLoadError={(
onError={(
event: NativeSyntheticEvent<
Readonly<{
readonly navigationError: Readonly<{
Expand All @@ -98,8 +96,8 @@ export class KlarnaStandaloneWebView extends Component<
}>
>
) => {
if (this.props.onLoadError != null) {
this.props.onLoadError(event.nativeEvent.navigationError);
if (this.props.onError != null) {
this.props.onError(event.nativeEvent.navigationError);
}
}}
onLoadProgress={(
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 @@ export interface RNKlarnaStandaloneWebViewProps extends ViewProps {
returnUrl: string;
onLoadStart: DirectEventHandler<KlarnaWebViewNavigationEvent>;
onLoad: DirectEventHandler<KlarnaWebViewNavigationEvent>;
onLoadError: DirectEventHandler<KlarnaWebViewNavigationError>;
onError: DirectEventHandler<KlarnaWebViewNavigationError>;
onLoadProgress: DirectEventHandler<KlarnaWebViewProgressEvent>;
onKlarnaMessage: DirectEventHandler<KlarnaWebViewKlarnaMessageEvent>;
/* Android only */
Expand Down

0 comments on commit 502ab4a

Please sign in to comment.