react-native-klarna-inapp-sdk 2.2.5 → 2.3.0
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 +3 -2
- package/android/build.gradle +10 -10
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/KlarnaMobileSDKPackage.java +3 -1
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/checkout/KlarnaCheckoutViewEventHandler.java +32 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/checkout/KlarnaCheckoutViewEventSender.java +56 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/checkout/KlarnaCheckoutViewManager.java +147 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/WebViewResizeObserver.java +59 -19
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/event/ComponentEvent.java +37 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/event/ComponentEventSender.java +78 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/event/KlarnaEventHandlerEventsUtil.java +53 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/ui/ResizeObserverWrapperView.java +79 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/ui/WrapperView.java +32 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/{ArgumentsUtil.java → util/ArgumentsUtil.java} +1 -1
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/util/ParserUtil.java +36 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/payments/KlarnaPaymentViewManager.java +1 -1
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/payments/PaymentViewWrapper.java +1 -1
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/standalonewebview/KlarnaStandaloneWebViewEventSender.java +1 -1
- package/android/src/newarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaCheckoutViewSpec.java +31 -0
- package/android/src/oldarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaCheckoutViewSpec.java +20 -0
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/KlarnaMobileSDKPackageTest.java +3 -1
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/common/event/ComponentEventSenderTest.java +85 -0
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/common/event/ComponentEventTest.java +73 -0
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/common/event/KlarnaEventHandlerEventsUtilTest.java +61 -0
- package/ios/RNKlarnaMobileSDK.xcodeproj/project.pbxproj +32 -0
- package/ios/Sources/KlarnaCheckoutViewManager.h +5 -0
- package/ios/Sources/KlarnaCheckoutViewManager.mm +65 -0
- package/ios/Sources/common/RNMobileSDKUtils.h +6 -0
- package/ios/Sources/common/RNMobileSDKUtils.mm +22 -0
- package/ios/Sources/view/newarch/KlarnaCheckoutViewWrapper.h +26 -0
- package/ios/Sources/view/newarch/KlarnaCheckoutViewWrapper.mm +153 -0
- package/ios/Sources/view/oldarch/KlarnaCheckoutViewWrapper.h +37 -0
- package/ios/Sources/view/oldarch/KlarnaCheckoutViewWrapper.mm +116 -0
- package/lib/commonjs/KlarnaCheckoutView.js +84 -0
- package/lib/commonjs/KlarnaCheckoutView.js.map +1 -0
- package/lib/commonjs/index.js +11 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/KlarnaCheckoutViewNativeComponent.js +16 -0
- package/lib/commonjs/specs/KlarnaCheckoutViewNativeComponent.js.map +1 -0
- package/lib/commonjs/types/common/KlarnaMobileSDKError.js +2 -0
- package/lib/commonjs/types/common/KlarnaMobileSDKError.js.map +1 -0
- package/lib/commonjs/types/common/KlarnaProductEvent.js +2 -0
- package/lib/commonjs/types/common/KlarnaProductEvent.js.map +1 -0
- package/lib/module/KlarnaCheckoutView.js +74 -0
- package/lib/module/KlarnaCheckoutView.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/KlarnaCheckoutViewNativeComponent.js +7 -0
- package/lib/module/specs/KlarnaCheckoutViewNativeComponent.js.map +1 -0
- package/lib/module/types/common/KlarnaMobileSDKError.js +2 -0
- package/lib/module/types/common/KlarnaMobileSDKError.js.map +1 -0
- package/lib/module/types/common/KlarnaProductEvent.js +2 -0
- package/lib/module/types/common/KlarnaProductEvent.js.map +1 -0
- package/lib/typescript/KlarnaCheckoutView.d.ts +24 -0
- package/lib/typescript/KlarnaCheckoutView.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/KlarnaCheckoutViewNativeComponent.d.ts +33 -0
- package/lib/typescript/specs/KlarnaCheckoutViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/types/common/KlarnaMobileSDKError.d.ts +6 -0
- package/lib/typescript/types/common/KlarnaMobileSDKError.d.ts.map +1 -0
- package/lib/typescript/types/common/KlarnaProductEvent.d.ts +7 -0
- package/lib/typescript/types/common/KlarnaProductEvent.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/KlarnaCheckoutView.tsx +130 -0
- package/src/index.tsx +1 -0
- package/src/specs/KlarnaCheckoutViewNativeComponent.ts +58 -0
- package/src/types/common/KlarnaMobileSDKError.ts +5 -0
- package/src/types/common/KlarnaProductEvent.ts +4 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';
|
|
2
|
+
import type { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
|
+
import type { HostComponent } from 'react-native';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
export interface RNKlarnaCheckoutViewProps extends ViewProps {
|
|
6
|
+
readonly returnUrl: string;
|
|
7
|
+
readonly onEvent: DirectEventHandler<Readonly<{
|
|
8
|
+
readonly productEvent: Readonly<{
|
|
9
|
+
readonly action: string;
|
|
10
|
+
readonly params: string;
|
|
11
|
+
}>;
|
|
12
|
+
}>>;
|
|
13
|
+
readonly onError: DirectEventHandler<Readonly<{
|
|
14
|
+
readonly error: Readonly<{
|
|
15
|
+
readonly isFatal: boolean;
|
|
16
|
+
readonly message: string;
|
|
17
|
+
readonly name: string;
|
|
18
|
+
}>;
|
|
19
|
+
}>>;
|
|
20
|
+
readonly onResized: DirectEventHandler<Readonly<{
|
|
21
|
+
readonly height: string;
|
|
22
|
+
}>>;
|
|
23
|
+
}
|
|
24
|
+
type KlarnaCheckoutViewNativeComponentType = HostComponent<RNKlarnaCheckoutViewProps>;
|
|
25
|
+
interface RNKlarnaCheckoutViewNativeCommands {
|
|
26
|
+
setSnippet: (viewRef: React.ElementRef<KlarnaCheckoutViewNativeComponentType>, snippet: string) => void;
|
|
27
|
+
suspend: (viewRef: React.ElementRef<KlarnaCheckoutViewNativeComponentType>) => void;
|
|
28
|
+
resume: (viewRef: React.ElementRef<KlarnaCheckoutViewNativeComponentType>) => void;
|
|
29
|
+
}
|
|
30
|
+
export declare const RNKlarnaCheckoutViewCommands: RNKlarnaCheckoutViewNativeCommands;
|
|
31
|
+
declare const _default: KlarnaCheckoutViewNativeComponentType;
|
|
32
|
+
export default _default;
|
|
33
|
+
//# sourceMappingURL=KlarnaCheckoutViewNativeComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KlarnaCheckoutViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/specs/KlarnaCheckoutViewNativeComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sDAAsD,CAAC;AACtF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AACpF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,WAAW,yBAA0B,SAAQ,SAAS;IAC1D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,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OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KlarnaProductEvent.d.ts","sourceRoot":"","sources":["../../../../src/types/common/KlarnaProductEvent.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;CACzC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-klarna-inapp-sdk",
|
|
3
3
|
"title": "Klarna Mobile SDK React Native",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.3.0",
|
|
5
5
|
"description": "This library wraps Klarna Mobile SDK and exposes its functionality as React Native components.",
|
|
6
6
|
"main": "lib/commonjs/index",
|
|
7
7
|
"module": "lib/module/index",
|
|
@@ -86,10 +86,10 @@
|
|
|
86
86
|
"turbo": "^1.10.7",
|
|
87
87
|
"typescript": "^5.0.2"
|
|
88
88
|
},
|
|
89
|
-
"dependencies": {},
|
|
90
89
|
"engines": {
|
|
91
90
|
"node": ">=16"
|
|
92
91
|
},
|
|
92
|
+
"packageManager": "yarn@1.22.22",
|
|
93
93
|
"react-native-builder-bob": {
|
|
94
94
|
"source": "src",
|
|
95
95
|
"output": "lib",
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import React, { Component, type RefObject } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
NativeMethods,
|
|
4
|
+
NativeSyntheticEvent,
|
|
5
|
+
ViewStyle,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
import type { KlarnaProductEvent } from './types/common/KlarnaProductEvent';
|
|
8
|
+
import type { KlarnaMobileSDKError } from './types/common/KlarnaMobileSDKError';
|
|
9
|
+
import RNKlarnaCheckoutView, {
|
|
10
|
+
RNKlarnaCheckoutViewCommands,
|
|
11
|
+
type RNKlarnaCheckoutViewProps,
|
|
12
|
+
} from './specs/KlarnaCheckoutViewNativeComponent';
|
|
13
|
+
|
|
14
|
+
export interface KlarnaCheckoutViewProps {
|
|
15
|
+
style?: ViewStyle;
|
|
16
|
+
readonly returnUrl: string;
|
|
17
|
+
readonly onEvent?: (klarnaProductEvent: KlarnaProductEvent) => void;
|
|
18
|
+
readonly onError?: (error: KlarnaMobileSDKError) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface KlarnaCheckoutViewState {
|
|
22
|
+
nativeViewHeight: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class KlarnaCheckoutView extends Component<
|
|
26
|
+
KlarnaCheckoutViewProps,
|
|
27
|
+
KlarnaCheckoutViewState
|
|
28
|
+
> {
|
|
29
|
+
checkoutViewRef: RefObject<
|
|
30
|
+
Component<RNKlarnaCheckoutViewProps> & Readonly<NativeMethods>
|
|
31
|
+
>;
|
|
32
|
+
|
|
33
|
+
constructor(props: KlarnaCheckoutViewProps) {
|
|
34
|
+
super(props);
|
|
35
|
+
this.state = {
|
|
36
|
+
nativeViewHeight: 0,
|
|
37
|
+
};
|
|
38
|
+
this.checkoutViewRef = React.createRef();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
render() {
|
|
42
|
+
return (
|
|
43
|
+
<RNKlarnaCheckoutView
|
|
44
|
+
ref={this.checkoutViewRef}
|
|
45
|
+
/* eslint-disable-next-line react-native/no-inline-styles */
|
|
46
|
+
style={{
|
|
47
|
+
width: '100%',
|
|
48
|
+
height: this.state.nativeViewHeight,
|
|
49
|
+
}}
|
|
50
|
+
returnUrl={this.props.returnUrl || ''}
|
|
51
|
+
onEvent={(
|
|
52
|
+
event: NativeSyntheticEvent<
|
|
53
|
+
Readonly<{
|
|
54
|
+
readonly productEvent: Readonly<{
|
|
55
|
+
readonly action: string;
|
|
56
|
+
readonly params: string;
|
|
57
|
+
}>;
|
|
58
|
+
}>
|
|
59
|
+
>
|
|
60
|
+
) => {
|
|
61
|
+
let params = {};
|
|
62
|
+
try {
|
|
63
|
+
params = JSON.parse(event.nativeEvent.productEvent.params);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
console.error('Failed to parse productEvent.params', e);
|
|
66
|
+
}
|
|
67
|
+
const productEvent: KlarnaProductEvent = {
|
|
68
|
+
action: event.nativeEvent.productEvent.action,
|
|
69
|
+
params: params,
|
|
70
|
+
};
|
|
71
|
+
this.props.onEvent?.(productEvent);
|
|
72
|
+
}}
|
|
73
|
+
onError={(
|
|
74
|
+
event: NativeSyntheticEvent<
|
|
75
|
+
Readonly<{
|
|
76
|
+
readonly error: Readonly<{
|
|
77
|
+
readonly isFatal: boolean;
|
|
78
|
+
readonly message: string;
|
|
79
|
+
readonly name: string;
|
|
80
|
+
}>;
|
|
81
|
+
}>
|
|
82
|
+
>
|
|
83
|
+
) => {
|
|
84
|
+
const mobileSdkError: KlarnaMobileSDKError = {
|
|
85
|
+
isFatal: event.nativeEvent.error.isFatal,
|
|
86
|
+
message: event.nativeEvent.error.message,
|
|
87
|
+
name: event.nativeEvent.error.name,
|
|
88
|
+
};
|
|
89
|
+
this.props.onError?.(mobileSdkError);
|
|
90
|
+
}}
|
|
91
|
+
onResized={(
|
|
92
|
+
event: NativeSyntheticEvent<
|
|
93
|
+
Readonly<{
|
|
94
|
+
readonly height: string;
|
|
95
|
+
}>
|
|
96
|
+
>
|
|
97
|
+
) => {
|
|
98
|
+
const newHeight = Number(event.nativeEvent.height);
|
|
99
|
+
if (newHeight !== this.state.nativeViewHeight) {
|
|
100
|
+
console.log('onResized', newHeight);
|
|
101
|
+
this.setState({ nativeViewHeight: newHeight });
|
|
102
|
+
}
|
|
103
|
+
}}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
setSnippet = (snippet: string) => {
|
|
109
|
+
const view = this.checkoutViewRef.current;
|
|
110
|
+
if (view != null) {
|
|
111
|
+
RNKlarnaCheckoutViewCommands.setSnippet(view, snippet);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
suspend = () => {
|
|
116
|
+
const view = this.checkoutViewRef.current;
|
|
117
|
+
if (view != null) {
|
|
118
|
+
RNKlarnaCheckoutViewCommands.suspend(view);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
resume = () => {
|
|
123
|
+
const view = this.checkoutViewRef.current;
|
|
124
|
+
if (view != null) {
|
|
125
|
+
RNKlarnaCheckoutViewCommands.resume(view);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export default KlarnaCheckoutView;
|
package/src/index.tsx
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';
|
|
2
|
+
import type { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
|
+
import type { HostComponent } from 'react-native';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
|
|
6
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
7
|
+
|
|
8
|
+
export interface RNKlarnaCheckoutViewProps extends ViewProps {
|
|
9
|
+
readonly returnUrl: string;
|
|
10
|
+
readonly onEvent: DirectEventHandler<
|
|
11
|
+
Readonly<{
|
|
12
|
+
readonly productEvent: Readonly<{
|
|
13
|
+
readonly action: string;
|
|
14
|
+
readonly params: string;
|
|
15
|
+
}>;
|
|
16
|
+
}>
|
|
17
|
+
>;
|
|
18
|
+
readonly onError: DirectEventHandler<
|
|
19
|
+
Readonly<{
|
|
20
|
+
readonly error: Readonly<{
|
|
21
|
+
readonly isFatal: boolean;
|
|
22
|
+
readonly message: string;
|
|
23
|
+
readonly name: string;
|
|
24
|
+
}>;
|
|
25
|
+
}>
|
|
26
|
+
>;
|
|
27
|
+
readonly onResized: DirectEventHandler<
|
|
28
|
+
Readonly<{
|
|
29
|
+
// number not supported for events
|
|
30
|
+
readonly height: string;
|
|
31
|
+
}>
|
|
32
|
+
>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type KlarnaCheckoutViewNativeComponentType =
|
|
36
|
+
HostComponent<RNKlarnaCheckoutViewProps>;
|
|
37
|
+
|
|
38
|
+
interface RNKlarnaCheckoutViewNativeCommands {
|
|
39
|
+
setSnippet: (
|
|
40
|
+
viewRef: React.ElementRef<KlarnaCheckoutViewNativeComponentType>,
|
|
41
|
+
snippet: string
|
|
42
|
+
) => void;
|
|
43
|
+
suspend: (
|
|
44
|
+
viewRef: React.ElementRef<KlarnaCheckoutViewNativeComponentType>
|
|
45
|
+
) => void;
|
|
46
|
+
resume: (
|
|
47
|
+
viewRef: React.ElementRef<KlarnaCheckoutViewNativeComponentType>
|
|
48
|
+
) => void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const RNKlarnaCheckoutViewCommands: RNKlarnaCheckoutViewNativeCommands =
|
|
52
|
+
codegenNativeCommands<RNKlarnaCheckoutViewNativeCommands>({
|
|
53
|
+
supportedCommands: ['setSnippet', 'suspend', 'resume'],
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export default codegenNativeComponent<RNKlarnaCheckoutViewProps>(
|
|
57
|
+
'RNKlarnaCheckoutView'
|
|
58
|
+
) as KlarnaCheckoutViewNativeComponentType;
|