Skip to content

Commit

Permalink
fix return url prop and simplify props on ios
Browse files Browse the repository at this point in the history
  • Loading branch information
NMGuner committed Sep 25, 2023
1 parent 5c3ba89 commit af02444
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
4 changes: 2 additions & 2 deletions TestApp/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions ios/Sources/view/newarch/PaymentViewWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
36 changes: 18 additions & 18 deletions ios/Sources/view/newarch/PaymentViewWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -193,14 +186,21 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
const auto &oldViewProps = *std::static_pointer_cast<RNKlarnaPaymentViewProps const>(_props);
const auto &newViewProps = *std::static_pointer_cast<RNKlarnaPaymentViewProps const>(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];
}
}


Expand Down
1 change: 1 addition & 0 deletions ios/Sources/view/oldarch/PaymentViewWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 12 additions & 1 deletion ios/Sources/view/oldarch/PaymentViewWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,25 @@ - (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];
}
}

- (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];
Expand Down

0 comments on commit af02444

Please sign in to comment.