@klarna/react-native-klarna-network-messaging 0.0.1 → 2.7.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 +80 -28
- package/android/build.gradle +97 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/klarnanetwork/messaging/KlarnaMessagingPlacementErrorEvent.kt +25 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/klarnanetwork/messaging/KlarnaMessagingPlacementResizedEvent.kt +20 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/klarnanetwork/messaging/KlarnaMessagingPlacementViewManager.kt +251 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/klarnanetwork/messaging/KlarnaMessagingViewManagerHelpers.kt +52 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/klarnanetwork/messaging/KlarnaNetworkMessagingPackage.kt +19 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/klarnanetwork/messaging/RNKlarnaMessagingPlacementViewSpec.kt +22 -0
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/klarnanetwork/messaging/KlarnaMessagingPlacementEventsTest.kt +39 -0
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/klarnanetwork/messaging/KlarnaMessagingPlacementViewManagerTest.kt +76 -0
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/klarnanetwork/messaging/KlarnaMessagingViewManagerHelpersTest.kt +200 -0
- package/ios/Sources/KlarnaMessagingPlacementViewFactory.swift +101 -0
- package/ios/Sources/KlarnaMessagingPlacementViewHelper.swift +171 -0
- package/ios/Sources/KlarnaMessagingPlacementViewManager.h +5 -0
- package/ios/Sources/KlarnaMessagingPlacementViewManager.mm +37 -0
- package/ios/Sources/view/KlarnaMessagingPlacementViewWrapper.h +7 -0
- package/ios/Sources/view/KlarnaMessagingPlacementViewWrapper.mm +183 -0
- package/ios/Tests/KlarnaMessagingHeightObserverTests.swift +204 -0
- package/ios/Tests/KlarnaMessagingPlacementViewFactoryTests.swift +167 -0
- package/ios/Tests/KlarnaMessagingPlacementViewHelperTests.swift +118 -0
- package/lib/commonjs/KlarnaMessagingPlacementView.js +102 -0
- package/lib/commonjs/KlarnaMessagingPlacementView.js.map +1 -0
- package/lib/commonjs/Specs/KlarnaMessagingPlacementViewNativeComponent.js +10 -0
- package/lib/commonjs/Specs/KlarnaMessagingPlacementViewNativeComponent.js.map +1 -0
- package/lib/commonjs/index.js +27 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/internal.js +45 -0
- package/lib/commonjs/internal.js.map +1 -0
- package/lib/commonjs/types/KlarnaMessagingError.js +2 -0
- package/lib/commonjs/types/KlarnaMessagingError.js.map +1 -0
- package/lib/commonjs/types/KlarnaMessagingPlacementConfiguration.js +6 -0
- package/lib/commonjs/types/KlarnaMessagingPlacementConfiguration.js.map +1 -0
- package/lib/commonjs/types/KlarnaMessagingPlacementType.js +15 -0
- package/lib/commonjs/types/KlarnaMessagingPlacementType.js.map +1 -0
- package/lib/module/KlarnaMessagingPlacementView.js +94 -0
- package/lib/module/KlarnaMessagingPlacementView.js.map +1 -0
- package/lib/module/Specs/KlarnaMessagingPlacementViewNativeComponent.js +3 -0
- package/lib/module/Specs/KlarnaMessagingPlacementViewNativeComponent.js.map +1 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/internal.js +38 -0
- package/lib/module/internal.js.map +1 -0
- package/lib/module/types/KlarnaMessagingError.js +2 -0
- package/lib/module/types/KlarnaMessagingError.js.map +1 -0
- package/lib/module/types/KlarnaMessagingPlacementConfiguration.js +2 -0
- package/lib/module/types/KlarnaMessagingPlacementConfiguration.js.map +1 -0
- package/lib/module/types/KlarnaMessagingPlacementType.js +9 -0
- package/lib/module/types/KlarnaMessagingPlacementType.js.map +1 -0
- package/lib/typescript/KlarnaMessagingPlacementView.d.ts +39 -0
- package/lib/typescript/KlarnaMessagingPlacementView.d.ts.map +1 -0
- package/lib/typescript/Specs/KlarnaMessagingPlacementViewNativeComponent.d.ts +23 -0
- package/lib/typescript/Specs/KlarnaMessagingPlacementViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +6 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/internal.d.ts +25 -0
- package/lib/typescript/internal.d.ts.map +1 -0
- package/lib/typescript/types/KlarnaMessagingError.d.ts +8 -0
- package/lib/typescript/types/KlarnaMessagingError.d.ts.map +1 -0
- package/lib/typescript/types/KlarnaMessagingPlacementConfiguration.d.ts +25 -0
- package/lib/typescript/types/KlarnaMessagingPlacementConfiguration.d.ts.map +1 -0
- package/lib/typescript/types/KlarnaMessagingPlacementType.d.ts +8 -0
- package/lib/typescript/types/KlarnaMessagingPlacementType.d.ts.map +1 -0
- package/package.json +122 -6
- package/react-native-klarna-network-messaging.podspec +28 -0
- package/src/KlarnaMessagingPlacementView.tsx +139 -0
- package/src/Specs/KlarnaMessagingPlacementViewNativeComponent.ts +32 -0
- package/src/index.tsx +12 -0
- package/src/internal.ts +48 -0
- package/src/types/KlarnaMessagingError.ts +7 -0
- package/src/types/KlarnaMessagingPlacementConfiguration.ts +29 -0
- package/src/types/KlarnaMessagingPlacementType.ts +7 -0
package/package.json
CHANGED
|
@@ -1,10 +1,126 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@klarna/react-native-klarna-network-messaging",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.7.0",
|
|
4
|
+
"description": "React Native module for Klarna Network Messaging placements",
|
|
5
|
+
"main": "./src/index.tsx",
|
|
6
|
+
"codegenConfig": {
|
|
7
|
+
"name": "KlarnaNetworkMessagingSpec",
|
|
8
|
+
"type": "components",
|
|
9
|
+
"jsSrcsDir": "src",
|
|
10
|
+
"android": {
|
|
11
|
+
"javaPackageName": "com.klarna.mobile.sdk.reactnative.klarnanetwork.messaging"
|
|
12
|
+
},
|
|
13
|
+
"ios": {
|
|
14
|
+
"componentProvider": {
|
|
15
|
+
"RNKlarnaMessagingPlacementView": "KlarnaMessagingPlacementViewWrapper"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
5
19
|
"keywords": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
20
|
+
"react-native",
|
|
21
|
+
"klarna",
|
|
22
|
+
"sdk",
|
|
23
|
+
"messaging"
|
|
24
|
+
],
|
|
25
|
+
"repository": "https://github.com/klarna/react-native-klarna-inapp-sdk",
|
|
26
|
+
"author": "Mobile SDK <mobile.sdk@klarna.com>",
|
|
27
|
+
"license": "Apache-2.0",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/klarna/react-native-klarna-inapp-sdk/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/klarna/react-native-klarna-inapp-sdk#readme",
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"registry": "https://registry.npmjs.org/"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"src",
|
|
37
|
+
"lib",
|
|
38
|
+
"android",
|
|
39
|
+
"ios",
|
|
40
|
+
"*.podspec",
|
|
41
|
+
"!ios/build",
|
|
42
|
+
"!ios/Pods",
|
|
43
|
+
"!android/build",
|
|
44
|
+
"!android/gradle",
|
|
45
|
+
"!android/gradlew",
|
|
46
|
+
"!android/gradlew.bat",
|
|
47
|
+
"!android/local.properties",
|
|
48
|
+
"!**/__tests__",
|
|
49
|
+
"!**/__fixtures__",
|
|
50
|
+
"!**/__mocks__",
|
|
51
|
+
"!**/.*"
|
|
52
|
+
],
|
|
53
|
+
"create-react-native-library": {
|
|
54
|
+
"type": "fabric-view",
|
|
55
|
+
"languages": "kotlin-objc",
|
|
56
|
+
"tools": [
|
|
57
|
+
"eslint"
|
|
58
|
+
],
|
|
59
|
+
"version": "0.62.0"
|
|
60
|
+
},
|
|
61
|
+
"types": "./src/index.tsx",
|
|
62
|
+
"react-native": "./src/index.tsx",
|
|
63
|
+
"source": "./src/index.tsx",
|
|
64
|
+
"exports": {
|
|
65
|
+
".": {
|
|
66
|
+
"source": "./src/index.tsx",
|
|
67
|
+
"types": "./src/index.tsx",
|
|
68
|
+
"react-native": "./src/index.tsx",
|
|
69
|
+
"default": "./src/index.tsx"
|
|
70
|
+
},
|
|
71
|
+
"./package.json": "./package.json"
|
|
72
|
+
},
|
|
73
|
+
"packageManager": "yarn@4.4.0",
|
|
74
|
+
"scripts": {
|
|
75
|
+
"prepack": "bob build",
|
|
76
|
+
"test": "jest",
|
|
77
|
+
"test:ios": "xcodebuild test -workspace ../../TestApp/ios/TestApp.xcworkspace -scheme 'react-native-klarna-network-messaging-Unit-Tests' -destination 'platform=iOS Simulator,name=iPhone 17 Pro' -derivedDataPath build/DerivedData",
|
|
78
|
+
"lint": "eslint \"src/**/*.{js,ts,tsx}\"",
|
|
79
|
+
"lint:fix": "eslint \"src/**/*.{js,ts,tsx}\" --fix",
|
|
80
|
+
"prettier": "prettier --check \"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}\"",
|
|
81
|
+
"prettier:fix": "prettier --write \"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}\"",
|
|
82
|
+
"typecheck": "tsc --noEmit"
|
|
83
|
+
},
|
|
84
|
+
"devDependencies": {
|
|
85
|
+
"@klarna/react-native-klarna-network-core": "workspace:*",
|
|
86
|
+
"@types/jest": "^29.5.4",
|
|
87
|
+
"@types/react": "^18.0.24",
|
|
88
|
+
"@types/react-native": "^0.72.2",
|
|
89
|
+
"jest": "^29.2.1",
|
|
90
|
+
"metro-react-native-babel-preset": "0.76.8",
|
|
91
|
+
"react": "18.2.0",
|
|
92
|
+
"react-native": "0.76.0",
|
|
93
|
+
"react-native-builder-bob": "^0.20.0",
|
|
94
|
+
"typescript": "^5.0.2"
|
|
95
|
+
},
|
|
96
|
+
"peerDependencies": {
|
|
97
|
+
"@klarna/react-native-klarna-network-core": "2.7.0",
|
|
98
|
+
"react": ">=18.2.0",
|
|
99
|
+
"react-native": ">=0.76.0 <1.0.x"
|
|
100
|
+
},
|
|
101
|
+
"engines": {
|
|
102
|
+
"node": ">=16"
|
|
103
|
+
},
|
|
104
|
+
"react-native-builder-bob": {
|
|
105
|
+
"source": "src",
|
|
106
|
+
"output": "lib",
|
|
107
|
+
"targets": [
|
|
108
|
+
"commonjs",
|
|
109
|
+
"module",
|
|
110
|
+
"typescript"
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
"jest": {
|
|
114
|
+
"preset": "react-native",
|
|
115
|
+
"testPathIgnorePatterns": [
|
|
116
|
+
"/node_modules/",
|
|
117
|
+
"/lib/"
|
|
118
|
+
],
|
|
119
|
+
"transformIgnorePatterns": [
|
|
120
|
+
"node_modules/(?!(react-native|@react-native)/)"
|
|
121
|
+
],
|
|
122
|
+
"moduleNameMapper": {
|
|
123
|
+
"^@klarna/react-native-klarna-network-core$": "<rootDir>/../klarna-network-core/src/index.tsx"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
10
126
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "react-native-klarna-network-messaging"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
+
s.source = { :git => "https://github.com/klarna/react-native-klarna-inapp-sdk.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/Sources/**/*.{h,m,mm,swift,cpp}"
|
|
17
|
+
s.private_header_files = "ios/Sources/**/*.h"
|
|
18
|
+
s.swift_version = '5.0'
|
|
19
|
+
|
|
20
|
+
install_modules_dependencies(s)
|
|
21
|
+
|
|
22
|
+
s.dependency 'KlarnaMobileSDK/KlarnaNetworkMessaging', '2.11.7'
|
|
23
|
+
s.dependency 'react-native-klarna-network-core', s.version.to_s
|
|
24
|
+
|
|
25
|
+
s.test_spec 'Tests' do |ts|
|
|
26
|
+
ts.source_files = 'ios/Tests/**/*.swift'
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
type NativeSyntheticEvent,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
type ViewStyle,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
import type { KlarnaMessagingError } from './types/KlarnaMessagingError';
|
|
8
|
+
import type { KlarnaMessagingPlacementConfiguration } from './types/KlarnaMessagingPlacementConfiguration';
|
|
9
|
+
import { Klarna } from '@klarna/react-native-klarna-network-core';
|
|
10
|
+
import RNKlarnaMessagingPlacementView from './Specs/KlarnaMessagingPlacementViewNativeComponent';
|
|
11
|
+
import { errorFromNativeEvent, nextHeightOnResize } from './internal';
|
|
12
|
+
|
|
13
|
+
/** Props accepted by {@link KlarnaMessagingPlacementView}. */
|
|
14
|
+
export interface KlarnaMessagingPlacementViewProps {
|
|
15
|
+
/** Optional custom styles applied to the placement container. */
|
|
16
|
+
style?: ViewStyle;
|
|
17
|
+
/** The Klarna SDK instance obtained from {@link Klarna.initialize}. */
|
|
18
|
+
readonly instance: Klarna;
|
|
19
|
+
/** Placement type, amount, currency and theme for the messaging view. */
|
|
20
|
+
readonly configuration: KlarnaMessagingPlacementConfiguration;
|
|
21
|
+
/** Called when the native placement encounters an error. */
|
|
22
|
+
readonly onError?: (error: KlarnaMessagingError) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface KlarnaMessagingPlacementViewState {
|
|
26
|
+
nativeViewHeight: number;
|
|
27
|
+
hasReceivedResize: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Renders a Klarna messaging placement (e.g. credit-promotion banner or badge).
|
|
32
|
+
*
|
|
33
|
+
* The view automatically adjusts its height to match the content reported by the
|
|
34
|
+
* native SDK. Shows a minimum-height fallback while waiting for the first resize
|
|
35
|
+
* event, then collapses to zero when the native side reports height 0 (no content).
|
|
36
|
+
*/
|
|
37
|
+
export class KlarnaMessagingPlacementView extends Component<
|
|
38
|
+
KlarnaMessagingPlacementViewProps,
|
|
39
|
+
KlarnaMessagingPlacementViewState
|
|
40
|
+
> {
|
|
41
|
+
private hasError = false;
|
|
42
|
+
|
|
43
|
+
constructor(props: KlarnaMessagingPlacementViewProps) {
|
|
44
|
+
super(props);
|
|
45
|
+
this.state = {
|
|
46
|
+
nativeViewHeight: 0,
|
|
47
|
+
hasReceivedResize: false,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Resets the error latch when any configuration prop changes so the view
|
|
53
|
+
* can accept new height reports from the native side after a recovery.
|
|
54
|
+
*/
|
|
55
|
+
componentDidUpdate(prevProps: KlarnaMessagingPlacementViewProps) {
|
|
56
|
+
const prev = prevProps.configuration;
|
|
57
|
+
const next = this.props.configuration;
|
|
58
|
+
if (
|
|
59
|
+
prevProps.instance !== this.props.instance ||
|
|
60
|
+
prev.type !== next.type ||
|
|
61
|
+
prev.theme !== next.theme ||
|
|
62
|
+
prev.amount !== next.amount ||
|
|
63
|
+
prev.currency !== next.currency
|
|
64
|
+
) {
|
|
65
|
+
this.hasError = false;
|
|
66
|
+
if (this.state.hasReceivedResize) {
|
|
67
|
+
this.setState({ hasReceivedResize: false });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
render() {
|
|
73
|
+
const { configuration } = this.props;
|
|
74
|
+
return (
|
|
75
|
+
<RNKlarnaMessagingPlacementView
|
|
76
|
+
style={[
|
|
77
|
+
styles.container,
|
|
78
|
+
this.props.style,
|
|
79
|
+
this.state.nativeViewHeight > 0
|
|
80
|
+
? { height: this.state.nativeViewHeight }
|
|
81
|
+
: this.state.hasReceivedResize
|
|
82
|
+
? styles.collapsed
|
|
83
|
+
: styles.minHeightFallback,
|
|
84
|
+
]}
|
|
85
|
+
instanceId={this.props.instance.instanceId}
|
|
86
|
+
placementType={configuration.type}
|
|
87
|
+
theme={configuration.theme ?? ''}
|
|
88
|
+
amount={String(configuration.amount)}
|
|
89
|
+
currency={configuration.currency}
|
|
90
|
+
onError={(
|
|
91
|
+
event: NativeSyntheticEvent<
|
|
92
|
+
Readonly<{
|
|
93
|
+
readonly error: Readonly<{
|
|
94
|
+
readonly message: string;
|
|
95
|
+
readonly name: string;
|
|
96
|
+
}>;
|
|
97
|
+
}>
|
|
98
|
+
>
|
|
99
|
+
) => {
|
|
100
|
+
const error = errorFromNativeEvent(event.nativeEvent);
|
|
101
|
+
this.hasError = true;
|
|
102
|
+
this.setState({ nativeViewHeight: 0, hasReceivedResize: true });
|
|
103
|
+
this.props.onError?.(error);
|
|
104
|
+
}}
|
|
105
|
+
onResized={(
|
|
106
|
+
event: NativeSyntheticEvent<
|
|
107
|
+
Readonly<{
|
|
108
|
+
readonly height: string;
|
|
109
|
+
}>
|
|
110
|
+
>
|
|
111
|
+
) => {
|
|
112
|
+
const next = nextHeightOnResize({
|
|
113
|
+
rawHeight: event.nativeEvent.height,
|
|
114
|
+
prevHeight: this.state.nativeViewHeight,
|
|
115
|
+
hasError: this.hasError,
|
|
116
|
+
isFirstResize: !this.state.hasReceivedResize,
|
|
117
|
+
});
|
|
118
|
+
if (next !== null) {
|
|
119
|
+
this.setState({ nativeViewHeight: next, hasReceivedResize: true });
|
|
120
|
+
}
|
|
121
|
+
}}
|
|
122
|
+
/>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const styles = StyleSheet.create({
|
|
128
|
+
container: {
|
|
129
|
+
width: '100%',
|
|
130
|
+
overflow: 'hidden',
|
|
131
|
+
},
|
|
132
|
+
minHeightFallback: {
|
|
133
|
+
minHeight: 60,
|
|
134
|
+
},
|
|
135
|
+
collapsed: {
|
|
136
|
+
height: 0,
|
|
137
|
+
minHeight: 0,
|
|
138
|
+
},
|
|
139
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
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 codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
5
|
+
|
|
6
|
+
export interface RNKlarnaMessagingPlacementViewProps extends ViewProps {
|
|
7
|
+
readonly instanceId: string;
|
|
8
|
+
readonly placementType: string;
|
|
9
|
+
readonly theme: string;
|
|
10
|
+
readonly amount: string;
|
|
11
|
+
readonly currency: string;
|
|
12
|
+
readonly onError: DirectEventHandler<
|
|
13
|
+
Readonly<{
|
|
14
|
+
readonly error: Readonly<{
|
|
15
|
+
readonly message: string;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
}>;
|
|
18
|
+
}>
|
|
19
|
+
>;
|
|
20
|
+
readonly onResized: DirectEventHandler<
|
|
21
|
+
Readonly<{
|
|
22
|
+
readonly height: string;
|
|
23
|
+
}>
|
|
24
|
+
>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type KlarnaMessagingPlacementViewNativeComponentType =
|
|
28
|
+
HostComponent<RNKlarnaMessagingPlacementViewProps>;
|
|
29
|
+
|
|
30
|
+
export default codegenNativeComponent<RNKlarnaMessagingPlacementViewProps>(
|
|
31
|
+
'RNKlarnaMessagingPlacementView'
|
|
32
|
+
) as KlarnaMessagingPlacementViewNativeComponentType;
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export {
|
|
2
|
+
KlarnaMessagingPlacementView,
|
|
3
|
+
type KlarnaMessagingPlacementViewProps,
|
|
4
|
+
} from './KlarnaMessagingPlacementView';
|
|
5
|
+
export { KlarnaMessagingPlacementType } from './types/KlarnaMessagingPlacementType';
|
|
6
|
+
export type {
|
|
7
|
+
KlarnaMessagingPlacementConfiguration,
|
|
8
|
+
KlarnaMessagingCreditPromotionAutoSizeConfiguration,
|
|
9
|
+
KlarnaMessagingCreditPromotionBadgeConfiguration,
|
|
10
|
+
} from './types/KlarnaMessagingPlacementConfiguration';
|
|
11
|
+
export { KlarnaTheme } from '@klarna/react-native-klarna-network-core';
|
|
12
|
+
export type { KlarnaMessagingError } from './types/KlarnaMessagingError';
|
package/src/internal.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { KlarnaMessagingError } from './types/KlarnaMessagingError';
|
|
2
|
+
|
|
3
|
+
interface NextHeightInput {
|
|
4
|
+
readonly rawHeight: string;
|
|
5
|
+
readonly prevHeight: number;
|
|
6
|
+
readonly hasError: boolean;
|
|
7
|
+
readonly isFirstResize?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Derives the next view height from a native `onResized` event. Returns
|
|
12
|
+
* `null` (skip update) when the view is in an error state, the raw value
|
|
13
|
+
* is empty/non-finite/negative, or the height hasn't actually changed.
|
|
14
|
+
*
|
|
15
|
+
* On the first resize, height 0 is accepted so the view can collapse when
|
|
16
|
+
* native reports no content. Subsequent 0→0 duplicates are still skipped.
|
|
17
|
+
*/
|
|
18
|
+
export function nextHeightOnResize({
|
|
19
|
+
rawHeight,
|
|
20
|
+
prevHeight,
|
|
21
|
+
hasError,
|
|
22
|
+
isFirstResize,
|
|
23
|
+
}: NextHeightInput): number | null {
|
|
24
|
+
if (hasError) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
if (rawHeight.trim() === '') {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const parsed = Number(rawHeight);
|
|
31
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (parsed === prevHeight && !isFirstResize) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return parsed;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Extracts a `KlarnaMessagingError` from the nested native event payload. */
|
|
41
|
+
export function errorFromNativeEvent(event: {
|
|
42
|
+
readonly error: { readonly message: string; readonly name: string };
|
|
43
|
+
}): KlarnaMessagingError {
|
|
44
|
+
return {
|
|
45
|
+
message: event.error.message,
|
|
46
|
+
name: event.error.name,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { KlarnaTheme } from '@klarna/react-native-klarna-network-core';
|
|
2
|
+
import type { KlarnaMessagingPlacementType } from './KlarnaMessagingPlacementType';
|
|
3
|
+
|
|
4
|
+
/** Base configuration shared by all messaging placement types. */
|
|
5
|
+
interface KlarnaMessagingPlacementConfigurationBase {
|
|
6
|
+
/** The visual theme for the placement. Defaults to the system theme when omitted. */
|
|
7
|
+
readonly theme?: KlarnaTheme;
|
|
8
|
+
/** The purchase amount in minor units (e.g. cents). */
|
|
9
|
+
readonly amount: number;
|
|
10
|
+
/** The ISO 4217 currency code (e.g. "USD", "SEK"). */
|
|
11
|
+
readonly currency: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Configuration for a credit-promotion placement that automatically sizes itself to fit its content. */
|
|
15
|
+
export interface KlarnaMessagingCreditPromotionAutoSizeConfiguration extends KlarnaMessagingPlacementConfigurationBase {
|
|
16
|
+
/** Discriminator identifying this as a credit-promotion auto-size placement. */
|
|
17
|
+
readonly type: KlarnaMessagingPlacementType.CreditPromotionAutoSize;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Configuration for a credit-promotion placement rendered as a compact badge. */
|
|
21
|
+
export interface KlarnaMessagingCreditPromotionBadgeConfiguration extends KlarnaMessagingPlacementConfigurationBase {
|
|
22
|
+
/** Discriminator identifying this as a credit-promotion badge placement. */
|
|
23
|
+
readonly type: KlarnaMessagingPlacementType.CreditPromotionBadge;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Union of all supported messaging placement configurations. */
|
|
27
|
+
export type KlarnaMessagingPlacementConfiguration =
|
|
28
|
+
| KlarnaMessagingCreditPromotionAutoSizeConfiguration
|
|
29
|
+
| KlarnaMessagingCreditPromotionBadgeConfiguration;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The visual layout style of a Klarna messaging placement. */
|
|
2
|
+
export enum KlarnaMessagingPlacementType {
|
|
3
|
+
/** A placement that automatically adjusts its size to fit the content. */
|
|
4
|
+
CreditPromotionAutoSize = 'CreditPromotionAutoSize',
|
|
5
|
+
/** A compact badge-style placement. */
|
|
6
|
+
CreditPromotionBadge = 'CreditPromotionBadge',
|
|
7
|
+
}
|