diff --git a/ios/Sources/KlarnaPaymentViewManager.mm b/ios/Sources/KlarnaPaymentViewManager.mm index ce78ecbb..0d8ac79b 100644 --- a/ios/Sources/KlarnaPaymentViewManager.mm +++ b/ios/Sources/KlarnaPaymentViewManager.mm @@ -3,7 +3,6 @@ #import #import - #ifdef RCT_NEW_ARCH_ENABLED #import "view/newarch/PaymentViewWrapper.h" #else diff --git a/ios/Sources/KlarnaStandaloneWebViewManager.mm b/ios/Sources/KlarnaStandaloneWebViewManager.mm index 9ebac0b0..9d253323 100644 --- a/ios/Sources/KlarnaStandaloneWebViewManager.mm +++ b/ios/Sources/KlarnaStandaloneWebViewManager.mm @@ -3,7 +3,6 @@ #import #import - #ifdef RCT_NEW_ARCH_ENABLED #import "view/newarch/KlarnaStandaloneWebViewWrapper.h" #else @@ -25,20 +24,4 @@ - (UIView *)view return wrapper; } -#pragma mark - Exported Methods - -RCT_EXPORT_METHOD(initialize:(nonnull NSNumber*)reactTag returnUrl:(NSString*)returnUrl) { - - [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary *viewRegistry) { - KlarnaStandaloneWebViewWrapper* view = (KlarnaStandaloneWebViewWrapper*) viewRegistry[reactTag]; - if (!view || ![view isKindOfClass:KlarnaStandaloneWebViewWrapper.class]) { - RCTLogError(@"Can't find KlarnaStandaloneWebViewWrapper with tag #%@", reactTag); - return; - } - [view initializeStandaloneWebViewWithReturnUrl:returnUrl]; - }]; - - -} - @end diff --git a/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.h b/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.h index d60c134f..e85bd997 100644 --- a/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.h +++ b/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.h @@ -12,11 +12,10 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, weak) RCTUIManager* uiManager; -- (void)initializeStandaloneWebViewWithReturnUrl:(NSString*)returnUrl; +- (void) initializeKlarnaStandaloneWebView; @end NS_ASSUME_NONNULL_END #endif - diff --git a/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.mm b/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.mm index a79abcca..8de61aa3 100644 --- a/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.mm +++ b/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.mm @@ -15,12 +15,64 @@ using namespace facebook::react; -@interface KlarnaStandaloneWebViewWrapper () +@interface KlarnaStandaloneWebViewWrapper + +@property (nonatomic, strong) KlarnaStandaloneWebView* klarnaStandaloneWebView; @end @implementation KlarnaStandaloneWebViewWrapper +#pragma mark - React Native Overrides + +- (void) initializeKlarnaStandaloneWebView:(NSString*)returnUrl { + if (returnUrl.length > 0) { + self.klarnaStandaloneWebView = [[KlarnaStandaloneWebView alloc] initWithReturnURL:[NSURL URLWithString:returnUrl]]; + } else { + // TODO what should we do here? + } + self.klarnaStandaloneWebView.translatesAutoresizingMaskIntoConstraints = NO; + + + [self addSubview:self.klarnaStandaloneWebView]; + + [NSLayoutConstraint activateConstraints:[[NSArray alloc] initWithObjects: + [self.klarnaStandaloneWebView.topAnchor constraintEqualToAnchor:self.topAnchor], + [self.klarnaStandaloneWebView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor], + [self.klarnaStandaloneWebView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor], + [self.klarnaStandaloneWebView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor], nil + ]]; +} + +- (void) layoutSubviews { + [super layoutSubviews]; + self.klarnaStandaloneWebView.frame = self.bounds; + [self.klarnaStandaloneWebView layoutSubviews]; +} + +#pragma mark - Standalone Web View Methods + +- (instancetype) initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + static const auto defaultProps = std::make_shared(); + _props = defaultProps; + } + + return self; +} + ++ (ComponentDescriptorProvider)componentDescriptorProvider +{ + return concreteComponentDescriptorProvider(); +} + +Class RNKlarnaStandaloneWebViewCls(void) +{ + return KlarnaStandaloneWebViewWrapper.class; +} + @end #endif diff --git a/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.h b/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.h index 0d80991b..db7995b8 100644 --- a/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.h +++ b/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.h @@ -15,9 +15,9 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - React Native Overrides -@property (nonatomic, weak) RCTUIManager* uiManager; +- (void) initializeKlarnaStandaloneWebView; -- (void)initializeStandaloneWebViewWithReturnUrl:(NSString*)returnUrl; +@property (nonatomic, weak) RCTUIManager* uiManager; @end @@ -25,3 +25,4 @@ NS_ASSUME_NONNULL_END #endif + diff --git a/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.mm b/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.mm index 9a910480..c7a3aa21 100644 --- a/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.mm +++ b/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.mm @@ -3,7 +3,6 @@ #import "KlarnaStandaloneWebViewWrapper.h" #import -#import @interface KlarnaStandaloneWebViewWrapper () @@ -18,11 +17,35 @@ @implementation KlarnaStandaloneWebViewWrapper - (void) setReturnUrl:(NSString *)returnUrl { _returnUrl = returnUrl; if (returnUrl.length > 0) { - self.klarnaStandaloneWebView.returnUrl = [NSURL URLWithString:self.returnUrl]; + self.klarnaStandaloneWebView.returnURL = [NSURL URLWithString:self.returnUrl]; } } +- (void) initializeKlarnaStandaloneWebView { + if (self.returnUrl != nil && self.returnUrl.length > 0) { + self.klarnaStandaloneWebView = [[KlarnaStandaloneWebView alloc] initWithReturnURL:[NSURL URLWithString:self.returnUrl]]; + [self.klarnaStandaloneWebView loadURL:[NSURL URLWithString:@"https://google.com"]]; + } else { + // TODO what should we do here? + } + self.klarnaStandaloneWebView.translatesAutoresizingMaskIntoConstraints = NO; + + [self addSubview:self.klarnaStandaloneWebView]; + + [NSLayoutConstraint activateConstraints:[[NSArray alloc] initWithObjects: + [self.klarnaStandaloneWebView.topAnchor constraintEqualToAnchor:self.topAnchor], + [self.klarnaStandaloneWebView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor], + [self.klarnaStandaloneWebView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor], + [self.klarnaStandaloneWebView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor], nil + ]]; +} + +- (void) layoutSubviews { + [super layoutSubviews]; + self.klarnaStandaloneWebView.frame = self.bounds; + [self.klarnaStandaloneWebView layoutSubviews]; +} + @end #endif - diff --git a/ios/Sources/view/oldarch/PaymentViewWrapper.mm b/ios/Sources/view/oldarch/PaymentViewWrapper.mm index 7a6e99b1..dbebfb07 100644 --- a/ios/Sources/view/oldarch/PaymentViewWrapper.mm +++ b/ios/Sources/view/oldarch/PaymentViewWrapper.mm @@ -9,7 +9,6 @@ @interface PaymentViewWrapper () @property (nonatomic, strong) KlarnaPaymentView* actualPaymentView; - @end