Skip to content

Commit

Permalink
Update the iOS skeleton code
Browse files Browse the repository at this point in the history
  • Loading branch information
MasoudFallahpourbaee committed Oct 3, 2023
1 parent ad75a83 commit c9db334
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 28 deletions.
1 change: 0 additions & 1 deletion ios/Sources/KlarnaPaymentViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#import <React/RCTUIManager.h>
#import <React/RCTLog.h>


#ifdef RCT_NEW_ARCH_ENABLED
#import "view/newarch/PaymentViewWrapper.h"
#else
Expand Down
17 changes: 0 additions & 17 deletions ios/Sources/KlarnaStandaloneWebViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#import <React/RCTUIManager.h>
#import <React/RCTLog.h>


#ifdef RCT_NEW_ARCH_ENABLED
#import "view/newarch/KlarnaStandaloneWebViewWrapper.h"
#else
Expand All @@ -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<NSNumber *,UIView *> *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
3 changes: 0 additions & 3 deletions ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, weak) RCTUIManager* uiManager;

- (void)initializeStandaloneWebViewWithReturnUrl:(NSString*)returnUrl;

@end

NS_ASSUME_NONNULL_END

#endif

54 changes: 53 additions & 1 deletion ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<const RNKlarnaStandaloneWebViewProps>();
_props = defaultProps;
}

return self;
}

+ (ComponentDescriptorProvider)componentDescriptorProvider
{
return concreteComponentDescriptorProvider<RNKlarnaStandaloneWebViewComponentDescriptor>();
}

Class<RCTComponentViewProtocol> RNKlarnaStandaloneWebViewCls(void)
{
return KlarnaStandaloneWebViewWrapper.class;
}

@end

#endif
Expand Down
5 changes: 3 additions & 2 deletions ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ 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

NS_ASSUME_NONNULL_END

#endif


29 changes: 26 additions & 3 deletions ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#import "KlarnaStandaloneWebViewWrapper.h"

#import <KlarnaMobileSDK/KlarnaMobileSDK-Swift.h>
#import <React/RCTLog.h>

@interface KlarnaStandaloneWebViewWrapper ()

Expand All @@ -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

1 change: 0 additions & 1 deletion ios/Sources/view/oldarch/PaymentViewWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ @interface PaymentViewWrapper () <KlarnaPaymentEventListener>

@property (nonatomic, strong) KlarnaPaymentView* actualPaymentView;


@end


Expand Down

0 comments on commit c9db334

Please sign in to comment.