react-native-klarna-inapp-sdk 2.4.10 → 2.5.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 +2 -1
- package/android/build.gradle +3 -1
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/KlarnaMobileSDKPackage.java +5 -1
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/checkout/KlarnaCheckoutViewManager.java +4 -10
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/WebViewResizeObserver.java +28 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/event/ComponentEventSender.java +5 -1
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/ui/ResizeObserverWrapperView.java +2 -2
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/ui/WrapperView.java +2 -2
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/ui/YogaLayoutHelper.java +39 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/expresscheckout/KlarnaExpressCheckoutViewCallback.kt +30 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/expresscheckout/KlarnaExpressCheckoutViewEventSender.kt +80 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/expresscheckout/KlarnaExpressCheckoutViewManager.java +544 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/osm/KlarnaOSMViewEventHandler.java +30 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/osm/KlarnaOSMViewEventSender.java +64 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/osm/KlarnaOSMViewManager.java +356 -0
- package/android/src/newarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaExpressCheckoutViewSpec.java +31 -0
- package/android/src/newarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaOSMViewSpec.java +31 -0
- package/android/src/oldarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaExpressCheckoutViewSpec.java +36 -0
- package/android/src/oldarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaOSMViewSpec.java +32 -0
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/KlarnaMobileSDKPackageTest.java +5 -1
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/common/ui/YogaLayoutHelperTest.java +79 -0
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/expresscheckout/KlarnaExpressCheckoutViewManagerTest.java +259 -0
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/osm/KlarnaOSMViewEventHandlerTest.java +136 -0
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/osm/KlarnaOSMViewEventSenderTest.java +184 -0
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/osm/KlarnaOSMViewManagerTest.java +385 -0
- package/ios/RNKlarnaMobileSDK.xcodeproj/project.pbxproj +55 -1
- package/ios/Sources/KlarnaExpressCheckoutViewManager.h +5 -0
- package/ios/Sources/KlarnaExpressCheckoutViewManager.mm +39 -0
- package/ios/Sources/KlarnaOSMViewManager.h +5 -0
- package/ios/Sources/KlarnaOSMViewManager.mm +59 -0
- package/ios/Sources/view/KlarnaExpressCheckoutButtonDelegateProxy.swift +145 -0
- package/ios/Sources/view/KlarnaExpressCheckoutViewWrapper.h +41 -0
- package/ios/Sources/view/KlarnaOSMViewWrapper.h +48 -0
- package/ios/Sources/view/newarch/KlarnaExpressCheckoutViewWrapper.mm +228 -0
- package/ios/Sources/view/newarch/KlarnaOSMViewWrapper.mm +294 -0
- package/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.mm +20 -13
- package/ios/Sources/view/oldarch/KlarnaExpressCheckoutViewWrapper.mm +222 -0
- package/ios/Sources/view/oldarch/KlarnaOSMViewWrapper.mm +273 -0
- package/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.mm +11 -13
- package/ios/Tests/KlarnaExpressCheckoutViewWrapperTests.m +391 -0
- package/ios/Tests/KlarnaOSMViewWrapperTests.m +450 -0
- package/ios/Tests/KlarnaStandaloneWebViewWrapperTests.m +105 -0
- package/lib/commonjs/KlarnaExpressCheckoutView.js +75 -0
- package/lib/commonjs/KlarnaExpressCheckoutView.js.map +1 -0
- package/lib/commonjs/KlarnaOSMView.js +94 -0
- package/lib/commonjs/KlarnaOSMView.js.map +1 -0
- package/lib/commonjs/index.js +99 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/KlarnaExpressCheckoutViewNativeComponent.js +11 -0
- package/lib/commonjs/specs/KlarnaExpressCheckoutViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/KlarnaOSMViewNativeComponent.js +16 -0
- package/lib/commonjs/specs/KlarnaOSMViewNativeComponent.js.map +1 -0
- package/lib/commonjs/types/button/KlarnaButtonShape.js +14 -0
- package/lib/commonjs/types/button/KlarnaButtonShape.js.map +1 -0
- package/lib/commonjs/types/button/KlarnaButtonStyle.js +13 -0
- package/lib/commonjs/types/button/KlarnaButtonStyle.js.map +1 -0
- package/lib/commonjs/types/button/KlarnaButtonTheme.js +14 -0
- package/lib/commonjs/types/button/KlarnaButtonTheme.js.map +1 -0
- package/lib/commonjs/types/common/KlarnaExpressCheckoutSessionOptions.js +9 -0
- package/lib/commonjs/types/common/KlarnaExpressCheckoutSessionOptions.js.map +1 -0
- package/lib/commonjs/types/common/KlarnaOSMPlacementKey.js +2 -0
- package/lib/commonjs/types/common/KlarnaOSMPlacementKey.js.map +1 -0
- package/lib/commonjs/types/common/KlarnaTheme.js +14 -0
- package/lib/commonjs/types/common/KlarnaTheme.js.map +1 -0
- package/lib/module/KlarnaExpressCheckoutView.js +64 -0
- package/lib/module/KlarnaExpressCheckoutView.js.map +1 -0
- package/lib/module/KlarnaOSMView.js +84 -0
- package/lib/module/KlarnaOSMView.js.map +1 -0
- package/lib/module/index.js +9 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/KlarnaExpressCheckoutViewNativeComponent.js +3 -0
- package/lib/module/specs/KlarnaExpressCheckoutViewNativeComponent.js.map +1 -0
- package/lib/module/specs/KlarnaOSMViewNativeComponent.js +7 -0
- package/lib/module/specs/KlarnaOSMViewNativeComponent.js.map +1 -0
- package/lib/module/types/button/KlarnaButtonShape.js +7 -0
- package/lib/module/types/button/KlarnaButtonShape.js.map +1 -0
- package/lib/module/types/button/KlarnaButtonStyle.js +6 -0
- package/lib/module/types/button/KlarnaButtonStyle.js.map +1 -0
- package/lib/module/types/button/KlarnaButtonTheme.js +7 -0
- package/lib/module/types/button/KlarnaButtonTheme.js.map +1 -0
- package/lib/module/types/common/KlarnaExpressCheckoutSessionOptions.js +2 -0
- package/lib/module/types/common/KlarnaExpressCheckoutSessionOptions.js.map +1 -0
- package/lib/module/types/common/KlarnaOSMPlacementKey.js +2 -0
- package/lib/module/types/common/KlarnaOSMPlacementKey.js.map +1 -0
- package/lib/module/types/common/KlarnaTheme.js +7 -0
- package/lib/module/types/common/KlarnaTheme.js.map +1 -0
- package/lib/typescript/KlarnaExpressCheckoutView.d.ts +47 -0
- package/lib/typescript/KlarnaExpressCheckoutView.d.ts.map +1 -0
- package/lib/typescript/KlarnaOSMView.d.ts +36 -0
- package/lib/typescript/KlarnaOSMView.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +9 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/KlarnaExpressCheckoutViewNativeComponent.d.ts +45 -0
- package/lib/typescript/specs/KlarnaExpressCheckoutViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/specs/KlarnaOSMViewNativeComponent.d.ts +35 -0
- package/lib/typescript/specs/KlarnaOSMViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/types/button/KlarnaButtonShape.d.ts +6 -0
- package/lib/typescript/types/button/KlarnaButtonShape.d.ts.map +1 -0
- package/lib/typescript/types/button/KlarnaButtonStyle.d.ts +5 -0
- package/lib/typescript/types/button/KlarnaButtonStyle.d.ts.map +1 -0
- package/lib/typescript/types/button/KlarnaButtonTheme.d.ts +6 -0
- package/lib/typescript/types/button/KlarnaButtonTheme.d.ts.map +1 -0
- package/lib/typescript/types/common/KlarnaExpressCheckoutSessionOptions.d.ts +10 -0
- package/lib/typescript/types/common/KlarnaExpressCheckoutSessionOptions.d.ts.map +1 -0
- package/lib/typescript/types/common/KlarnaOSMPlacementKey.d.ts +2 -0
- package/lib/typescript/types/common/KlarnaOSMPlacementKey.d.ts.map +1 -0
- package/lib/typescript/types/common/KlarnaTheme.d.ts +6 -0
- package/lib/typescript/types/common/KlarnaTheme.d.ts.map +1 -0
- package/package.json +5 -3
- package/react-native-klarna-inapp-sdk.podspec +2 -1
- package/src/KlarnaExpressCheckoutView.tsx +169 -0
- package/src/KlarnaOSMView.tsx +157 -0
- package/src/index.tsx +9 -0
- package/src/specs/KlarnaExpressCheckoutViewNativeComponent.ts +66 -0
- package/src/specs/KlarnaOSMViewNativeComponent.ts +50 -0
- package/src/types/button/KlarnaButtonShape.ts +5 -0
- package/src/types/button/KlarnaButtonStyle.ts +4 -0
- package/src/types/button/KlarnaButtonTheme.ts +5 -0
- package/src/types/common/KlarnaExpressCheckoutSessionOptions.ts +13 -0
- package/src/types/common/KlarnaOSMPlacementKey.ts +3 -0
- package/src/types/common/KlarnaTheme.ts +5 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
#if !RCT_NEW_ARCH_ENABLED
|
|
2
|
+
|
|
3
|
+
#import <React/RCTLog.h>
|
|
4
|
+
#import "../KlarnaOSMViewWrapper.h"
|
|
5
|
+
#import "../../common/RNMobileSDKUtils.h"
|
|
6
|
+
#import <KlarnaMobileSDK/KlarnaMobileSDK.h>
|
|
7
|
+
#import <KlarnaMobileSDK/KlarnaMobileSDK-Swift.h>
|
|
8
|
+
|
|
9
|
+
@interface KlarnaOSMViewWrapper () <KlarnaEventHandler, KlarnaSizingDelegate>
|
|
10
|
+
|
|
11
|
+
@property (nonatomic, strong) KlarnaOSMView* klarnaOSMView;
|
|
12
|
+
@property (nonatomic, assign) BOOL isOSMViewReadyEventSent;
|
|
13
|
+
|
|
14
|
+
@end
|
|
15
|
+
|
|
16
|
+
@implementation KlarnaOSMViewWrapper
|
|
17
|
+
|
|
18
|
+
#pragma mark - Initialization
|
|
19
|
+
|
|
20
|
+
- (instancetype)initWithFrame:(CGRect)frame
|
|
21
|
+
{
|
|
22
|
+
self = [super initWithFrame:frame];
|
|
23
|
+
if (self) {
|
|
24
|
+
self.isOSMViewReadyEventSent = NO;
|
|
25
|
+
self.backgroundColor = [UIColor clearColor];
|
|
26
|
+
[self initializeActualOSMView];
|
|
27
|
+
}
|
|
28
|
+
return self;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
#pragma mark - React Native Property Setters
|
|
32
|
+
|
|
33
|
+
- (void)setClientId:(NSString *)clientId {
|
|
34
|
+
_clientId = clientId;
|
|
35
|
+
self.klarnaOSMView.clientId = clientId;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
- (void)setPlacementKey:(NSString *)placementKey {
|
|
39
|
+
_placementKey = placementKey;
|
|
40
|
+
self.klarnaOSMView.placementKey = placementKey;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
- (void)setLocale:(NSString *)locale {
|
|
44
|
+
_locale = locale;
|
|
45
|
+
if (locale.length > 0) {
|
|
46
|
+
self.klarnaOSMView.locale = locale;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
- (void)setPurchaseAmount:(NSString *)purchaseAmount {
|
|
51
|
+
_purchaseAmount = purchaseAmount;
|
|
52
|
+
if (purchaseAmount.length > 0) {
|
|
53
|
+
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
|
|
54
|
+
formatter.numberStyle = NSNumberFormatterDecimalStyle;
|
|
55
|
+
NSNumber *amount = [formatter numberFromString:purchaseAmount];
|
|
56
|
+
if (amount != nil) {
|
|
57
|
+
[self.klarnaOSMView setPurchaseAmount:amount];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
- (void)setEnvironment:(NSString *)environment {
|
|
63
|
+
_environment = environment;
|
|
64
|
+
if (environment.length > 0) {
|
|
65
|
+
if ([environment isEqualToString:@"playground"]) {
|
|
66
|
+
self.klarnaOSMView.environment = KlarnaEnvironment.playground;
|
|
67
|
+
} else if ([environment isEqualToString:@"production"]) {
|
|
68
|
+
self.klarnaOSMView.environment = KlarnaEnvironment.production;
|
|
69
|
+
} else if ([environment isEqualToString:@"staging"]) {
|
|
70
|
+
self.klarnaOSMView.environment = KlarnaEnvironment.staging;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
- (void)setRegion:(NSString *)region {
|
|
76
|
+
_region = region;
|
|
77
|
+
if (region.length > 0) {
|
|
78
|
+
if ([region isEqualToString:@"eu"]) {
|
|
79
|
+
self.klarnaOSMView.region = KlarnaRegion.eu;
|
|
80
|
+
} else if ([region isEqualToString:@"na"]) {
|
|
81
|
+
self.klarnaOSMView.region = KlarnaRegion.na;
|
|
82
|
+
} else if ([region isEqualToString:@"oc"]) {
|
|
83
|
+
self.klarnaOSMView.region = KlarnaRegion.oc;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
- (void)setTheme:(NSString *)theme {
|
|
89
|
+
_theme = theme;
|
|
90
|
+
if (theme.length > 0) {
|
|
91
|
+
if ([theme isEqualToString:@"light"]) {
|
|
92
|
+
self.klarnaOSMView.theme = KlarnaThemeLight;
|
|
93
|
+
} else if ([theme isEqualToString:@"dark"]) {
|
|
94
|
+
self.klarnaOSMView.theme = KlarnaThemeDark;
|
|
95
|
+
} else if ([theme isEqualToString:@"automatic"]) {
|
|
96
|
+
self.klarnaOSMView.theme = KlarnaThemeAutomatic;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
- (void)setOsmBackgroundColor:(NSString *)osmBackgroundColor {
|
|
102
|
+
_osmBackgroundColor = osmBackgroundColor;
|
|
103
|
+
[self updateStyleConfiguration];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
- (void)setTextColor:(NSString *)textColor {
|
|
107
|
+
_textColor = textColor;
|
|
108
|
+
[self updateStyleConfiguration];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
- (void)setReturnUrl:(NSString *)returnUrl {
|
|
112
|
+
// KlarnaOSMView ignores the return URL set by merchant and uses an internally created return URL.
|
|
113
|
+
_returnUrl = returnUrl;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#pragma mark - Style Configuration
|
|
117
|
+
|
|
118
|
+
- (void)updateStyleConfiguration {
|
|
119
|
+
UIColor *bgColor = [self colorFromHexString:self.osmBackgroundColor];
|
|
120
|
+
UIColor *txtColor = [self colorFromHexString:self.textColor];
|
|
121
|
+
|
|
122
|
+
if (bgColor || txtColor) {
|
|
123
|
+
KlarnaOSMStyleBuilder *builder = [[KlarnaOSMStyleBuilder alloc] init];
|
|
124
|
+
if (bgColor) {
|
|
125
|
+
[builder setBackgroundColor:bgColor];
|
|
126
|
+
}
|
|
127
|
+
if (txtColor) {
|
|
128
|
+
KlarnaTextStyleBuilder *textStyleBuilder = [[KlarnaTextStyleBuilder alloc] init];
|
|
129
|
+
[textStyleBuilder setTextColor:txtColor];
|
|
130
|
+
[builder setTextStyleConfiguration:[textStyleBuilder build]];
|
|
131
|
+
}
|
|
132
|
+
self.klarnaOSMView.styleConfiguration = [builder build];
|
|
133
|
+
} else {
|
|
134
|
+
self.klarnaOSMView.styleConfiguration = nil;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
- (UIColor *)colorFromHexString:(NSString *)hexString {
|
|
139
|
+
if (!hexString || hexString.length == 0) {
|
|
140
|
+
return nil;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
NSString *cleanString = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""];
|
|
144
|
+
if (cleanString.length != 6 && cleanString.length != 8) {
|
|
145
|
+
return nil;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
unsigned int rgbValue = 0;
|
|
149
|
+
NSScanner *scanner = [NSScanner scannerWithString:cleanString];
|
|
150
|
+
[scanner scanHexInt:&rgbValue];
|
|
151
|
+
|
|
152
|
+
if (cleanString.length == 8) {
|
|
153
|
+
return [UIColor colorWithRed:((rgbValue & 0xFF000000) >> 24) / 255.0
|
|
154
|
+
green:((rgbValue & 0x00FF0000) >> 16) / 255.0
|
|
155
|
+
blue:((rgbValue & 0x0000FF00) >> 8) / 255.0
|
|
156
|
+
alpha:(rgbValue & 0x000000FF) / 255.0];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0
|
|
160
|
+
green:((rgbValue & 0x00FF00) >> 8) / 255.0
|
|
161
|
+
blue:(rgbValue & 0x0000FF) / 255.0
|
|
162
|
+
alpha:1.0];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
#pragma mark - KlarnaOSMView Setup
|
|
166
|
+
|
|
167
|
+
- (void)initializeActualOSMView {
|
|
168
|
+
self.isOSMViewReadyEventSent = NO;
|
|
169
|
+
self.klarnaOSMView = [[KlarnaOSMView alloc] init];
|
|
170
|
+
self.klarnaOSMView.eventHandler = self;
|
|
171
|
+
self.klarnaOSMView.sizingDelegate = self;
|
|
172
|
+
self.klarnaOSMView.backgroundColor = [UIColor clearColor];
|
|
173
|
+
|
|
174
|
+
self.klarnaOSMView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
175
|
+
|
|
176
|
+
[self addSubview:self.klarnaOSMView];
|
|
177
|
+
|
|
178
|
+
[NSLayoutConstraint activateConstraints:[[NSArray alloc] initWithObjects:
|
|
179
|
+
[self.klarnaOSMView.topAnchor constraintEqualToAnchor:self.topAnchor],
|
|
180
|
+
[self.klarnaOSMView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor],
|
|
181
|
+
[self.klarnaOSMView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
|
|
182
|
+
[self.klarnaOSMView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor], nil
|
|
183
|
+
]];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
#pragma mark - Layout
|
|
187
|
+
|
|
188
|
+
- (void)layoutSubviews {
|
|
189
|
+
[super layoutSubviews];
|
|
190
|
+
self.klarnaOSMView.frame = self.bounds;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
#pragma mark - UIView Lifecycle
|
|
194
|
+
|
|
195
|
+
- (void)didMoveToWindow {
|
|
196
|
+
[super didMoveToWindow];
|
|
197
|
+
if (!self.window) {
|
|
198
|
+
self.isOSMViewReadyEventSent = NO;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
#pragma mark - React Native Lifecycle
|
|
203
|
+
|
|
204
|
+
- (void)didSetProps:(NSArray<NSString *> *)changedProps {
|
|
205
|
+
[super didSetProps:changedProps];
|
|
206
|
+
[self sendOSMViewReadyEvent];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
- (void)sendOSMViewReadyEvent {
|
|
210
|
+
if (self.klarnaOSMView && self.onOSMViewReady && !self.isOSMViewReadyEventSent) {
|
|
211
|
+
self.isOSMViewReadyEventSent = YES;
|
|
212
|
+
self.onOSMViewReady(@{});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
#pragma mark - Methods Exposed to React Native
|
|
217
|
+
|
|
218
|
+
- (void)render {
|
|
219
|
+
UIViewController *hostVC = [self reactViewController];
|
|
220
|
+
if (hostVC) {
|
|
221
|
+
self.klarnaOSMView.hostViewController = hostVC;
|
|
222
|
+
}
|
|
223
|
+
[self.klarnaOSMView render];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
- (UIViewController *)reactViewController {
|
|
227
|
+
UIResponder *responder = self;
|
|
228
|
+
while (responder) {
|
|
229
|
+
if ([responder isKindOfClass:[UIViewController class]]) {
|
|
230
|
+
return (UIViewController *)responder;
|
|
231
|
+
}
|
|
232
|
+
responder = [responder nextResponder];
|
|
233
|
+
}
|
|
234
|
+
return nil;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
#pragma mark - KlarnaEventHandler
|
|
238
|
+
|
|
239
|
+
- (void)klarnaComponent:(id<KlarnaComponent>)klarnaComponent dispatchedEvent:(KlarnaProductEvent *)event {
|
|
240
|
+
// OSM view does not emit product events, but handle for completeness
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
- (void)klarnaComponent:(id<KlarnaComponent>)klarnaComponent encounteredError:(KlarnaError *)error {
|
|
244
|
+
if (!self.onError) {
|
|
245
|
+
RCTLog(@"Missing 'onError' callback prop.");
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
self.onError(@{
|
|
250
|
+
@"error": @{
|
|
251
|
+
@"name": error.name,
|
|
252
|
+
@"message": error.message,
|
|
253
|
+
@"isFatal": [NSNumber numberWithBool:error.isFatal],
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
#pragma mark - KlarnaSizingDelegate
|
|
259
|
+
|
|
260
|
+
- (void)klarnaComponent:(id<KlarnaComponent>)klarnaComponent resizedToHeight:(CGFloat)height {
|
|
261
|
+
if (!self.onResized) {
|
|
262
|
+
RCTLog(@"Missing 'onResized' callback prop.");
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
self.onResized(@{
|
|
267
|
+
@"height": [[NSNumber numberWithFloat:height] stringValue]
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
@end
|
|
272
|
+
|
|
273
|
+
#endif
|
|
@@ -21,10 +21,6 @@ NSString * const PROPERTY_NAME_ESTIMATED_PROGRESS = @"estimatedProgress";
|
|
|
21
21
|
|
|
22
22
|
- (id)init {
|
|
23
23
|
self = [super init];
|
|
24
|
-
[self initializeKlarnaStandaloneWebView];
|
|
25
|
-
self.klarnaStandaloneWebView.delegate = self;
|
|
26
|
-
self.klarnaStandaloneWebView.eventHandler = self;
|
|
27
|
-
[self.klarnaStandaloneWebView addObserver:self forKeyPath:PROPERTY_NAME_ESTIMATED_PROGRESS options:NSKeyValueObservingOptionNew context:nil];
|
|
28
24
|
return self;
|
|
29
25
|
}
|
|
30
26
|
|
|
@@ -67,7 +63,11 @@ NSString * const PROPERTY_NAME_ESTIMATED_PROGRESS = @"estimatedProgress";
|
|
|
67
63
|
- (void)setReturnUrl:(NSString *)returnUrl {
|
|
68
64
|
_returnUrl = returnUrl;
|
|
69
65
|
if (returnUrl.length > 0) {
|
|
70
|
-
self.klarnaStandaloneWebView
|
|
66
|
+
if (self.klarnaStandaloneWebView == nil) {
|
|
67
|
+
[self initializeKlarnaStandaloneWebView];
|
|
68
|
+
} else {
|
|
69
|
+
self.klarnaStandaloneWebView.returnURL = [NSURL URLWithString:self.returnUrl];
|
|
70
|
+
}
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
@@ -79,18 +79,16 @@ NSString * const PROPERTY_NAME_ESTIMATED_PROGRESS = @"estimatedProgress";
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
- (void)initializeKlarnaStandaloneWebView {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
82
|
+
self.klarnaStandaloneWebView = [[KlarnaStandaloneWebView alloc] initWithReturnURL:[NSURL URLWithString:self.returnUrl]];
|
|
83
|
+
self.klarnaStandaloneWebView.delegate = self;
|
|
84
|
+
self.klarnaStandaloneWebView.eventHandler = self;
|
|
85
|
+
[self.klarnaStandaloneWebView addObserver:self forKeyPath:PROPERTY_NAME_ESTIMATED_PROGRESS options:NSKeyValueObservingOptionNew context:nil];
|
|
86
|
+
|
|
89
87
|
self.klarnaStandaloneWebView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
90
88
|
|
|
91
89
|
[self addSubview:self.klarnaStandaloneWebView];
|
|
92
90
|
[self setWebViewBackgroundToTransparent];
|
|
93
|
-
|
|
91
|
+
|
|
94
92
|
[NSLayoutConstraint activateConstraints:[[NSArray alloc] initWithObjects:
|
|
95
93
|
[self.klarnaStandaloneWebView.topAnchor constraintEqualToAnchor:self.topAnchor],
|
|
96
94
|
[self.klarnaStandaloneWebView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor],
|