diff --git a/android/src/main/java/in/juspay/hypersdkreact/HyperFragmentViewManager.java b/android/src/main/java/in/juspay/hypersdkreact/HyperFragmentViewManager.java index 7bcf009..7f982c4 100644 --- a/android/src/main/java/in/juspay/hypersdkreact/HyperFragmentViewManager.java +++ b/android/src/main/java/in/juspay/hypersdkreact/HyperFragmentViewManager.java @@ -21,6 +21,7 @@ import com.facebook.react.common.MapBuilder; import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.ViewGroupManager; +import com.facebook.react.uimanager.annotations.ReactProp; import org.json.JSONObject; @@ -35,6 +36,13 @@ public class HyperFragmentViewManager extends ViewGroupManager { private static final int COMMAND_PROCESS = 175; private final ReactApplicationContext reactContext; + // Track props for each view + private String currentNamespace = null; + private String currentPayload = null; + private FrameLayout currentView = null; + + // Architecture detection + private final Boolean newArchEnabled = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; public HyperFragmentViewManager(ReactApplicationContext reactContext) { this.reactContext = reactContext; @@ -58,6 +66,64 @@ protected FrameLayout createViewInstance(@NonNull ThemedReactContext context) { public Map getCommandsMap() { return MapBuilder.of("process", COMMAND_PROCESS); } + // Fabric-compatible props + @ReactProp(name = "ns") + public void setNs(FrameLayout view, @Nullable String ns) { + currentNamespace = ns; + currentView = view; + tryProcessProps(); + } + + @ReactProp(name="height") + public void setHeight(FrameLayout view, @Nullable int height) { + + } + @ReactProp(name = "payload") + public void setPayload(FrameLayout view, @Nullable String payload) { + currentPayload = payload; + currentView = view; + tryProcessProps(); + } + + + private void tryProcessProps() { + if (currentNamespace != null && currentPayload != null && currentView != null && newArchEnabled) { + currentView.post(() -> { + processWithProps(currentView, currentNamespace, currentPayload); + }); + } + } + + private void processWithProps(FrameLayout view, String namespace, String payload) { + try { + setupLayout(view); + + JSONObject fragments = new JSONObject(); + fragments.put(namespace, view); + + JSONObject payloadObj = new JSONObject(payload); + payloadObj.getJSONObject("payload").put("fragmentViewGroups", fragments); + + FragmentActivity activity = (FragmentActivity) reactContext.getCurrentActivity(); + HyperServices hyperServices = HyperSdkReactModule.getHyperServices(); + + if (activity == null || hyperServices == null) { + return; + } + + hyperServices.process(activity, payloadObj); + + } catch (Exception e) { + SdkTracker.trackAndLogBootException( + NAME, + LogConstants.CATEGORY_LIFECYCLE, + LogConstants.SUBCATEGORY_HYPER_SDK, + LogConstants.SDK_TRACKER_LABEL, + "Exception in processWithProps", + e + ); + } + } @Override public void receiveCommand(@NonNull FrameLayout root, String commandId, @Nullable ReadableArray args) { diff --git a/ios/HyperSdkReact.mm b/ios/HyperSdkReact.mm index ca3ad01..95bf450 100644 --- a/ios/HyperSdkReact.mm +++ b/ios/HyperSdkReact.mm @@ -439,7 +439,13 @@ + (NSString*)dictionaryToString:(id)dict{ @end @implementation HyperFragmentViewManagerIOS -RCT_EXPORT_MODULE() + + +RCT_EXPORT_MODULE(HyperFragmentViewManagerIOS) + +NSString *_currentNamespace; +NSString *_currentPayload; +UIView *_currentView; - (dispatch_queue_t)methodQueue{ return dispatch_get_main_queue(); @@ -454,7 +460,81 @@ - (UIView *)view return [[UIView alloc] init]; } -RCT_EXPORT_METHOD(process:(nonnull NSNumber *)viewTag nameSpace:(NSString *)nameSpace payload:(NSString *)payload) + +RCT_CUSTOM_VIEW_PROPERTY(ns, NSString, UIView) +{ + [self setNs:json forView:view]; +} + +RCT_CUSTOM_VIEW_PROPERTY(payload, NSString, UIView) +{ + [self setPayload:json forView:view]; +} + + +- (void) setHeight:(NSString*)ns forView:(UIView*)view { + +} + +- (void) setWidth:(NSString*)ns forView:(UIView*)view { + +} +- (void)setNs:(NSString *)ns forView:(UIView *)view +{ + _currentNamespace = ns; + _currentView = view; + [self tryProcessProps]; +} + + +- (void)setPayload:(NSString *)payload forView:(UIView *)view +{ + _currentPayload = payload; + _currentView = view; + [self tryProcessProps]; +} + +- (void)tryProcessProps +{ + if (_currentNamespace && _currentPayload && _currentView) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self processWithPropsForView:_currentView ns:_currentNamespace payload:_currentPayload]; + }); + } +} + +- (void)processWithPropsForView:(UIView *)view ns:(NSString *)ns payload:(NSString *)payload +{ + HyperServices *hyperServicesInstance = _hyperServicesReference; + if (payload && payload.length > 0) { + @try { + NSDictionary *jsonData = [HyperSdkReact stringToDictionary:payload]; + if (jsonData && [jsonData isKindOfClass:[NSDictionary class]] && jsonData.allKeys.count > 0) { + if (hyperServicesInstance.baseViewController == nil || hyperServicesInstance.baseViewController.view.window == nil) { + id baseViewController = RCTPresentedViewController(); + if ([baseViewController isMemberOfClass:RCTModalHostViewController.class] && [baseViewController presentingViewController]) { + [hyperServicesInstance setBaseViewController:[baseViewController presentingViewController]]; + } else { + [hyperServicesInstance setBaseViewController:baseViewController]; + } + } + + [self manuallyLayoutChildren:view]; + + NSMutableDictionary *nestedPayload = [jsonData[@"payload"] mutableCopy]; + NSDictionary *fragmentViewGroup = @{ns: view}; + nestedPayload[@"fragmentViewGroups"] = fragmentViewGroup; + NSMutableDictionary *updatedJsonData = [jsonData mutableCopy]; + updatedJsonData[@"payload"] = nestedPayload; + [hyperServicesInstance process:[updatedJsonData copy]]; + } + } @catch (NSException *exception) { + // Handle exception silently + } + } +} + +RCT_EXPORT_METHOD(process:(nonnull NSNumber *)viewTag ns:(NSString *)ns payload:(NSString *)payload) { HyperServices *hyperServicesInstance = _hyperServicesReference; if (payload && payload.length>0) { @@ -477,7 +557,7 @@ - (UIView *)view return; } NSMutableDictionary *nestedPayload = [jsonData[@"payload"] mutableCopy]; - NSDictionary *fragmentViewGroup = @{nameSpace: view}; + NSDictionary *fragmentViewGroup = @{ns: view}; nestedPayload[@"fragmentViewGroups"] = fragmentViewGroup; NSMutableDictionary *updatedJsonData = [jsonData mutableCopy]; updatedJsonData[@"payload"] = nestedPayload; @@ -496,4 +576,3 @@ - (void)manuallyLayoutChildren:(UIView *)view { } @end - diff --git a/src/HyperFragmentView.tsx b/src/HyperFragmentView.tsx index 7861b57..fb90b53 100644 --- a/src/HyperFragmentView.tsx +++ b/src/HyperFragmentView.tsx @@ -30,8 +30,11 @@ if (Platform.OS === 'android') { ); } +const newArchEnabled = global?.nativeFabricUIManager ? true : false; + const createFragment = (viewId: number, namespace: string, payload: string) => { - if (Platform.OS === 'android') { + if(!newArchEnabled) { + if (Platform.OS === 'android') { UIManager.dispatchViewManagerCommand( viewId, //@ts-ignore @@ -49,6 +52,9 @@ const createFragment = (viewId: number, namespace: string, payload: string) => { ]); } } + + } + }; const HyperFragmentView: React.FC = ({ @@ -71,7 +77,15 @@ const HyperFragmentView: React.FC = ({ return ( - + {newArchEnabled?:} ); };