Skip to content

Commit 2875970

Browse files
Yaswanth0606Yaswanth Polisetti
andauthored
fix: Added HyperSdkReactDelegate to get reactNativeFactory (#131)
Co-authored-by: Yaswanth Polisetti <[email protected]>
1 parent c120824 commit 2875970

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,26 @@ If your view dynamically computes height. Height can be obtained by adding the f
349349
350350
```
351351
352+
#### If your AppDelegate is in swift
353+
If your `AppDelegate` is in `swift` and you are using react native version greater than or equal to 0.78, then your AppDelegate.swift has to implement the protocol `HyperSdkReactDelegate` and return the `reactNativeFactory` property from the `getReactNativeFactory` function. This helps us to render your view(Merchant View) in our payment page.
354+
355+
```swift
356+
...
357+
import hyper_sdk_react
358+
359+
@main
360+
class AppDelegate: UIResponder, UIApplicationDelegate, HyperSdkReactDelegate {
361+
...
362+
var reactNativeFactory: RCTReactNativeFactory?
363+
...
364+
365+
func getReactNativeFactory() -> Any! {
366+
return reactNativeFactory
367+
}
368+
}
369+
370+
```
371+
352372
## Payload Structure
353373
354374
Please refer [here for Express Checkout SDK](https://developer.juspay.in/v2.0/docs/payload) and [here for Payment Page SDK](https://developer.juspay.in/v4.0/docs/payload), for all request and response payload structure.

ios/HyperSdkReact.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@
1515

1616
@interface HyperSdkReact : RCTEventEmitter <RCTBridgeModule>
1717

18-
#import <HyperSDK/HyperSDK.h>
1918
@property HyperServices *hyperInstance;
2019
@property id <HyperDelegate> delegate;
2120

2221
@end
2322

23+
@protocol HyperSdkReactDelegate <NSObject>
24+
25+
- (id)getReactNativeFactory;
26+
27+
@end
28+
2429
@interface SdkDelegate : NSObject <HyperDelegate>
2530
@property (nonatomic, strong) NSMutableDictionary *rootHolder;
2631
@property (nonatomic, strong) NSMutableDictionary *heightHolder;

ios/latest/HyperMerchantView.mm

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
// HyperMerchantView.mm
88
#import "HyperMerchantView.h"
9+
#import "HyperSdkReact.h"
910
#import <objc/runtime.h>
1011
#if __has_include("RCTRootViewFactory.h")
1112
#import "RCTRootViewFactory.h"
@@ -19,18 +20,25 @@ + (UIView *)createReactNativeViewWithModuleName:(NSString *)moduleName {
1920

2021
#if HAS_NEW_ARCH_SUPPORT
2122
id appDelegate = RCTSharedApplication().delegate;
22-
unsigned int ivarCount = 0;
23-
Ivar *ivars = class_copyIvarList([appDelegate class], &ivarCount);
2423
id factory = nil;
25-
for (unsigned int i = 0; i < ivarCount; i++) {
26-
const char *ivarName = ivar_getName(ivars[i]);
27-
// Swift mangles property names - look for reactNativeFactory or _reactNativeFactory
28-
if (strcmp(ivarName, "_reactNativeFactory") == 0 || strcmp(ivarName, "reactNativeFactory") == 0) {
29-
factory = object_getIvar(appDelegate, ivars[i]);
30-
break;
24+
if ([appDelegate conformsToProtocol:@protocol(HyperSdkReactDelegate)]) {
25+
id<HyperSdkReactDelegate> reactDelegate = appDelegate;
26+
factory = [reactDelegate getReactNativeFactory];
27+
}
28+
29+
if (!factory) {
30+
unsigned int ivarCount = 0;
31+
Ivar *ivars = class_copyIvarList([appDelegate class], &ivarCount);
32+
for (unsigned int i = 0; i < ivarCount; i++) {
33+
const char *ivarName = ivar_getName(ivars[i]);
34+
// Swift mangles property names - look for reactNativeFactory or _reactNativeFactory
35+
if (strcmp(ivarName, "_reactNativeFactory") == 0 || strcmp(ivarName, "reactNativeFactory") == 0) {
36+
factory = object_getIvar(appDelegate, ivars[i]);
37+
break;
38+
}
3139
}
40+
free(ivars);
3241
}
33-
free(ivars);
3442
if (!factory) {
3543
return nil;
3644
}

0 commit comments

Comments
 (0)