diff --git a/TestApp/ios/Podfile.lock b/TestApp/ios/Podfile.lock index 50a50512..d6aa0e3a 100644 --- a/TestApp/ios/Podfile.lock +++ b/TestApp/ios/Podfile.lock @@ -378,7 +378,7 @@ PODS: - React-jsinspector (0.72.4) - React-logger (0.72.4): - glog - - react-native-klarna-inapp-sdk (2.1.12): + - react-native-klarna-inapp-sdk (2.1.13): - KlarnaMobileSDK (= 2.6.10) - RCT-Folly (= 2021.07.22.00) - React-Core @@ -710,7 +710,7 @@ SPEC CHECKSUMS: React-jsiexecutor: c7f826e40fa9cab5d37cab6130b1af237332b594 React-jsinspector: aaed4cf551c4a1c98092436518c2d267b13a673f React-logger: da1ebe05ae06eb6db4b162202faeafac4b435e77 - react-native-klarna-inapp-sdk: 1515cee1268a110de81bbc323eb59b39a4b97ba1 + react-native-klarna-inapp-sdk: 6f46082682784d325c34c853fe9c42a111c1e31e react-native-safe-area-context: 7aa8e6d9d0f3100a820efb1a98af68aa747f9284 React-NativeModulesApple: edb5ace14f73f4969df6e7b1f3e41bef0012740f React-perflogger: 496a1a3dc6737f964107cb3ddae7f9e265ddda58 diff --git a/ios/Sources/view/newarch/PaymentViewWrapper.h b/ios/Sources/view/newarch/PaymentViewWrapper.h index 0522f562..04a5e421 100644 --- a/ios/Sources/view/newarch/PaymentViewWrapper.h +++ b/ios/Sources/view/newarch/PaymentViewWrapper.h @@ -8,12 +8,8 @@ NS_ASSUME_NONNULL_BEGIN @interface PaymentViewWrapper : RCTViewComponentView -@property (nonatomic, strong) NSString* category; - #pragma mark - React Native Overrides -- (void) setCategory:(NSString *)category; -- (void) evaluateProps; -- (void) initializeActualPaymentView; +- (void) initializeActualPaymentView:(NSString*)category withReturnUrl:(NSString*)returnUrl; @property (nonatomic, weak) RCTUIManager* uiManager; diff --git a/ios/Sources/view/newarch/PaymentViewWrapper.mm b/ios/Sources/view/newarch/PaymentViewWrapper.mm index 686a686a..52f181ca 100644 --- a/ios/Sources/view/newarch/PaymentViewWrapper.mm +++ b/ios/Sources/view/newarch/PaymentViewWrapper.mm @@ -27,19 +27,12 @@ @implementation PaymentViewWrapper #pragma mark - React Native Overrides -- (void) setCategory:(NSString *)category { - _category = category; - [self evaluateProps]; -} - -- (void) evaluateProps { - if (self.category != nil) { - [self initializeActualPaymentView]; +- (void) initializeActualPaymentView:(NSString*)category withReturnUrl:(NSString*)returnUrl { + if (returnUrl.length > 0) { + self.actualPaymentView = [[KlarnaPaymentView alloc] initWithCategory:category returnUrl:[NSURL URLWithString:returnUrl] eventListener:self]; + } else { + self.actualPaymentView = [[KlarnaPaymentView alloc] initWithCategory:category eventListener:self]; } -} - -- (void) initializeActualPaymentView { - self.actualPaymentView = [[KlarnaPaymentView alloc] initWithCategory:self.category eventListener:self]; self.actualPaymentView.translatesAutoresizingMaskIntoConstraints = NO; @@ -193,14 +186,21 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & const auto &oldViewProps = *std::static_pointer_cast(_props); const auto &newViewProps = *std::static_pointer_cast(props); - if (oldViewProps.category != newViewProps.category) { + if (self.actualPaymentView == nil && newViewProps.category.length() > 0) { NSString * categoryConver = [[NSString alloc] initWithUTF8String: newViewProps.category.c_str()]; - [self setCategory: categoryConver]; - } - - if (oldViewProps.returnUrl != newViewProps.returnUrl) { NSString * returnUrlConver = [[NSString alloc] initWithUTF8String: newViewProps.returnUrl.c_str()]; - self.actualPaymentView.returnURL = [NSURL URLWithString:returnUrlConver]; + [self initializeActualPaymentView:categoryConver withReturnUrl:returnUrlConver]; + } else { + if (oldViewProps.category != newViewProps.category) { + NSString * categoryConver = [[NSString alloc] initWithUTF8String: newViewProps.category.c_str()]; + // not supported + // self.actualPaymentView.category = newViewProps.category + } + + if (oldViewProps.returnUrl != newViewProps.returnUrl) { + NSString * returnUrlConver = [[NSString alloc] initWithUTF8String: newViewProps.returnUrl.c_str()]; + self.actualPaymentView.returnURL = [NSURL URLWithString:returnUrlConver]; + } } diff --git a/ios/Sources/view/oldarch/PaymentViewWrapper.h b/ios/Sources/view/oldarch/PaymentViewWrapper.h index c516578a..a5476f15 100644 --- a/ios/Sources/view/oldarch/PaymentViewWrapper.h +++ b/ios/Sources/view/oldarch/PaymentViewWrapper.h @@ -21,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy) RCTDirectEventBlock onResized; @property (nonatomic, strong) NSString* category; +@property (nonatomic, strong) NSString* returnUrl; #pragma mark - React Native Overrides - (void) setCategory:(NSString *)category; diff --git a/ios/Sources/view/oldarch/PaymentViewWrapper.mm b/ios/Sources/view/oldarch/PaymentViewWrapper.mm index 5de6f084..7a6e99b1 100644 --- a/ios/Sources/view/oldarch/PaymentViewWrapper.mm +++ b/ios/Sources/view/oldarch/PaymentViewWrapper.mm @@ -22,6 +22,13 @@ - (void) setCategory:(NSString *)category { [self evaluateProps]; } +- (void) setReturnUrl:(NSString *)returnUrl { + _returnUrl = returnUrl; + if (returnUrl.length > 0) { + self.actualPaymentView.returnURL = [NSURL URLWithString:self.returnUrl]; + } +} + - (void) evaluateProps { if (self.category != nil) { [self initializeActualPaymentView]; @@ -29,7 +36,11 @@ - (void) evaluateProps { } - (void) initializeActualPaymentView { - self.actualPaymentView = [[KlarnaPaymentView alloc] initWithCategory:self.category eventListener:self]; + if (self.returnUrl != nil && self.returnUrl.length > 0) { + self.actualPaymentView = [[KlarnaPaymentView alloc] initWithCategory:self.category returnUrl:[NSURL URLWithString:self.returnUrl] eventListener:self]; + } else { + self.actualPaymentView = [[KlarnaPaymentView alloc] initWithCategory:self.category eventListener:self]; + } self.actualPaymentView.translatesAutoresizingMaskIntoConstraints = NO; [self addSubview:self.actualPaymentView];