Skip to content

Commit

Permalink
Add the iOS skeleton code for exposing native KlarnaStandaloneWebView…
Browse files Browse the repository at this point in the history
… as a React Native component.
  • Loading branch information
MasoudFallahpourbaee committed Sep 28, 2023
1 parent ee78d35 commit c5dbfe4
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ios/RNKlarnaMobileSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
42BC05FF2AC57E110044A9FE /* KlarnaStandaloneWebViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 42BC05FE2AC57E110044A9FE /* KlarnaStandaloneWebViewManager.m */; };
42BC06032AC586C50044A9FE /* KlarnaStandaloneWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 42BC06022AC586C50044A9FE /* KlarnaStandaloneWebView.m */; };
42BC06052AC588180044A9FE /* KlarnaStandaloneWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 42BC06042AC588180044A9FE /* KlarnaStandaloneWebView.m */; };
7917D755255C45FB00E16799 /* PaymentViewWrapperTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7917D754255C45FB00E16799 /* PaymentViewWrapperTests.m */; };
7917D757255C45FB00E16799 /* libRNKlarnaMobileSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 134814201AA4EA6300B7C361 /* libRNKlarnaMobileSDK.a */; };
792F67C02AB8AD7D00675E18 /* PaymentViewWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 792F67BB2AB8AD7D00675E18 /* PaymentViewWrapper.mm */; };
Expand Down Expand Up @@ -42,6 +45,12 @@
134814201AA4EA6300B7C361 /* libRNKlarnaMobileSDK.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNKlarnaMobileSDK.a; sourceTree = BUILT_PRODUCTS_DIR; };
19C9876CD048B49EB4361DB8 /* Pods-RNKlarnaMobileSDK-RNKlarnaMobileSDKTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNKlarnaMobileSDK-RNKlarnaMobileSDKTests.release.xcconfig"; path = "Target Support Files/Pods-RNKlarnaMobileSDK-RNKlarnaMobileSDKTests/Pods-RNKlarnaMobileSDK-RNKlarnaMobileSDKTests.release.xcconfig"; sourceTree = "<group>"; };
3FC0A2F5614F1B06C1249CA3 /* Pods-RNKlarnaMobileSDK-RNKlarnaMobileSDKTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNKlarnaMobileSDK-RNKlarnaMobileSDKTests.debug.xcconfig"; path = "Target Support Files/Pods-RNKlarnaMobileSDK-RNKlarnaMobileSDKTests/Pods-RNKlarnaMobileSDK-RNKlarnaMobileSDKTests.debug.xcconfig"; sourceTree = "<group>"; };
42BC05FD2AC57D950044A9FE /* KlarnaStandaloneWebViewManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KlarnaStandaloneWebViewManager.h; sourceTree = "<group>"; };
42BC05FE2AC57E110044A9FE /* KlarnaStandaloneWebViewManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KlarnaStandaloneWebViewManager.m; sourceTree = "<group>"; };
42BC06002AC585950044A9FE /* KlarnaStandaloneWebView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KlarnaStandaloneWebView.h; sourceTree = "<group>"; };
42BC06012AC5866B0044A9FE /* KlarnaStandaloneWebView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KlarnaStandaloneWebView.h; sourceTree = "<group>"; };
42BC06022AC586C50044A9FE /* KlarnaStandaloneWebView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KlarnaStandaloneWebView.m; sourceTree = "<group>"; };
42BC06042AC588180044A9FE /* KlarnaStandaloneWebView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KlarnaStandaloneWebView.m; sourceTree = "<group>"; };
7917D752255C45FB00E16799 /* RNKlarnaMobileSDKTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RNKlarnaMobileSDKTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
7917D754255C45FB00E16799 /* PaymentViewWrapperTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PaymentViewWrapperTests.m; sourceTree = "<group>"; };
7917D756255C45FB00E16799 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -115,6 +124,8 @@
children = (
B3E7B5881CC2AC0600A0062D /* KlarnaPaymentViewManager.h */,
B3E7B5891CC2AC0600A0062D /* KlarnaPaymentViewManager.mm */,
42BC05FD2AC57D950044A9FE /* KlarnaStandaloneWebViewManager.h */,
42BC05FE2AC57E110044A9FE /* KlarnaStandaloneWebViewManager.m */,
9CDEDC2923475BAC006C9C97 /* view */,
);
path = Sources;
Expand Down Expand Up @@ -149,6 +160,8 @@
children = (
792F67BB2AB8AD7D00675E18 /* PaymentViewWrapper.mm */,
792F67BC2AB8AD7D00675E18 /* PaymentViewWrapper.h */,
42BC06012AC5866B0044A9FE /* KlarnaStandaloneWebView.h */,
42BC06022AC586C50044A9FE /* KlarnaStandaloneWebView.m */,
);
path = newarch;
sourceTree = "<group>";
Expand All @@ -158,6 +171,8 @@
children = (
792F67BE2AB8AD7D00675E18 /* PaymentViewWrapper.mm */,
792F67BF2AB8AD7D00675E18 /* PaymentViewWrapper.h */,
42BC06002AC585950044A9FE /* KlarnaStandaloneWebView.h */,
42BC06042AC588180044A9FE /* KlarnaStandaloneWebView.m */,
);
path = oldarch;
sourceTree = "<group>";
Expand Down Expand Up @@ -365,8 +380,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
42BC06032AC586C50044A9FE /* KlarnaStandaloneWebView.m in Sources */,
B3E7B58A1CC2AC0600A0062D /* KlarnaPaymentViewManager.mm in Sources */,
792F67C02AB8AD7D00675E18 /* PaymentViewWrapper.mm in Sources */,
42BC06052AC588180044A9FE /* KlarnaStandaloneWebView.m in Sources */,
42BC05FF2AC57E110044A9FE /* KlarnaStandaloneWebViewManager.m in Sources */,
792F67C12AB8AD7D00675E18 /* PaymentViewWrapper.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
5 changes: 5 additions & 0 deletions ios/Sources/KlarnaStandaloneWebViewManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <React/RCTViewManager.h>

@interface KlarnaStandaloneWebViewManager : RCTViewComponentView

@end
22 changes: 22 additions & 0 deletions ios/Sources/KlarnaStandaloneWebViewManager.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#import "KlarnaStandaloneWebViewManager.h"

#import <React/RCTUIManager.h>
#import <React/RCTLog.h>


#ifdef RCT_NEW_ARCH_ENABLED
#import "view/newarch/KlarnaStandaloneWebView.h"
#else
#import "view/oldarch/KlarnaStandaloneWebView.h"
#endif

@implementation KlarnaStandaloneWebViewManager

RCT_EXPORT_MODULE(RNKlarnaStandaloneWebView)

#pragma mark - View

RCT_EXPORT_VIEW_PROPERTY(returnUrl, NSString)

@end

18 changes: 18 additions & 0 deletions ios/Sources/view/newarch/KlarnaStandaloneWebView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#if RCT_NEW_ARCH_ENABLED

#import <React/RCTUIManager.h>
#import <React/RCTViewComponentView.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface KlarnaStandaloneWebView : RCTViewComponentView

@property (nonatomic, weak) RCTUIManager* uiManager;

@end

NS_ASSUME_NONNULL_END

#endif

25 changes: 25 additions & 0 deletions ios/Sources/view/newarch/KlarnaStandaloneWebView.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#if RCT_NEW_ARCH_ENABLED

#import "KlarnaStandaloneWebView.h"

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

#import <react/renderer/components/RNKlarnaMobileSDK/ComponentDescriptors.h>
#import <react/renderer/components/RNKlarnaMobileSDK/EventEmitters.h>
#import <react/renderer/components/RNKlarnaMobileSDK/Props.h>
#import <react/renderer/components/RNKlarnaMobileSDK/RCTComponentViewHelpers.h>

#import "RCTFabricComponentsPlugins.h"

using namespace facebook::react;

@interface KlarnaStandaloneWebView ()

@end

@implementation KlarnaStandaloneWebView

#endif

25 changes: 25 additions & 0 deletions ios/Sources/view/oldarch/KlarnaStandaloneWebView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#if !RCT_NEW_ARCH_ENABLED

#import <React/RCTUIManager.h>

#import <AVFoundation/AVFoundation.h>
#import <UIKit/UIKit.h>
#import <React/RCTView.h>
#import <React/RCTUIManager.h>

NS_ASSUME_NONNULL_BEGIN

@interface KlarnaStandaloneWebView : UIView

@property (nonatomic, strong) NSString* returnUrl;

#pragma mark - React Native Overrides
- (void) setReturnUrl:(NSString *)returnUrl;

@property (nonatomic, weak) RCTUIManager* uiManager;

@end

NS_ASSUME_NONNULL_END

#endif
28 changes: 28 additions & 0 deletions ios/Sources/view/oldarch/KlarnaStandaloneWebView.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#if !RCT_NEW_ARCH_ENABLED

#import "KlarnaStandaloneWebView.h"

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

@interface KlarnaStandaloneWebView ()

@property (nonatomic, strong) KlarnaStandaloneWebView* klarnaStandaloneWebView;

@end

@implementation KlarnaStandaloneWebView

#pragma mark - React Native Overrides

- (void) setReturnUrl:(NSString *)returnUrl {
_returnUrl = returnUrl;
if (returnUrl.length > 0) {
self.klarnaStandaloneWebView.returnUrl = [NSURL URLWithString:self.returnUrl];
}
}

@end

#endif

0 comments on commit c5dbfe4

Please sign in to comment.