From 4cbfe5f41ead4cf280fdd56c076a4d19873330f6 Mon Sep 17 00:00:00 2001 From: Dominic Go Date: Fri, 27 Sep 2024 18:09:23 +0800 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20Impl:=20`ModalSheetView.ge?= =?UTF-8?q?tModalMetrics`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RNIModalSheetViewController.swift | 17 +++++++++++++++++ .../RNIModalSheetViewDelegate.swift | 7 +++++++ .../ModalSheetView/ModalSheetView.tsx | 7 +++++++ .../ModalSheetView/ModalSheetViewTypes.tsx | 11 ++++++++++- .../RNIModalSheetVIew/RNIModalSheetView.tsx | 13 +++++++++++++ .../RNIModalSheetVIew/RNIModalSheetViewTypes.ts | 4 ++++ src/types/ModalMetrics.ts | 8 ++++++++ src/types/ModalViewControllerMetrics.ts | 14 ++++++++++++++ src/types/PresentationControllerMetrics.ts | 13 +++++++++++++ 9 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/types/ModalMetrics.ts create mode 100644 src/types/ModalViewControllerMetrics.ts create mode 100644 src/types/PresentationControllerMetrics.ts diff --git a/ios/RNIModalSheetView/RNIModalSheetViewController.swift b/ios/RNIModalSheetView/RNIModalSheetViewController.swift index 5598507c..c583287b 100644 --- a/ios/RNIModalSheetView/RNIModalSheetViewController.swift +++ b/ios/RNIModalSheetView/RNIModalSheetViewController.swift @@ -22,6 +22,23 @@ open class RNIModalSheetViewController: UIViewController { public var positionConfigForMainSheetContent: AlignmentPositionConfig = .default; + // MARK: - Computed Properties + // --------------------------- + + public var baseEventObject: [String: Any] { + var eventDict: [String: Any] = [:]; + + eventDict["modalViewControllerMetrics"] = + self.modalMetrics.synthesizedDictionaryJSON; + + if let presentationControllerMetrics = self.presentationControllerMetrics { + eventDict["presentationControllerMetrics"] = + presentationControllerMetrics.synthesizedDictionaryJSON; + }; + + return eventDict; + }; + // MARK: - View Controller Lifecycle // --------------------------------- diff --git a/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift b/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift index 71a80d24..d25192dd 100644 --- a/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift +++ b/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift @@ -173,6 +173,13 @@ extension RNIModalSheetViewDelegate: RNIContentViewDelegate { }; resolveBlock([:]); + + case "getModalMetrics": + guard let modalSheetController = self.modalSheetController else { + throw RNIUtilitiesError(errorCode: .unexpectedNilValue); + }; + + resolveBlock(modalSheetController.baseEventObject as NSDictionary); default: throw RNIUtilitiesError(errorCode: .invalidValue); diff --git a/src/components/ModalSheetView/ModalSheetView.tsx b/src/components/ModalSheetView/ModalSheetView.tsx index 5775121b..7b5b21c9 100644 --- a/src/components/ModalSheetView/ModalSheetView.tsx +++ b/src/components/ModalSheetView/ModalSheetView.tsx @@ -41,6 +41,13 @@ export const ModalSheetView = React.forwardRef< ...commandArgs, }); }, + getModalMetrics: async () => { + if(nativeRef.current == null) { + throw Error("Unable to get ref to native sheet"); + }; + + return await nativeRef.current.getModalMetrics(); + }, })); const shouldEnableDebugBackgroundColors = diff --git a/src/components/ModalSheetView/ModalSheetViewTypes.tsx b/src/components/ModalSheetView/ModalSheetViewTypes.tsx index a1140dcb..2b4bdc72 100644 --- a/src/components/ModalSheetView/ModalSheetViewTypes.tsx +++ b/src/components/ModalSheetView/ModalSheetViewTypes.tsx @@ -5,12 +5,16 @@ import type { RemapObject } from "react-native-ios-utilities"; import type { RNIModalSheetViewProps, RNIModalSheetViewRef } from "../../native_components/RNIModalSheetVIew"; +type ModalSheetViewRefInherited = Pick; + type ModalSheetViewRefInheritedRaw = Pick; -export type ModalSheetViewRef = RemapObject Promise; @@ -20,6 +24,11 @@ export type ModalSheetViewRef = RemapObject Promise; }>; + +export type ModalSheetViewRef = + ModalSheetViewRefInherited + & ModalSheetViewRefInheritedRemapped; + export type ModalSheetViewInheritedProps = Pick { + if(viewID == null) return; + const module = Helpers.getRNIUtilitiesModule(); + + const result = await module.viewCommandRequest( + /* viewID : */ viewID, + /* commandName: */ 'getModalMetrics', + /* commandArgs: */ {}, + ); + + return result as any; + }, })); const reactChildrenCount = React.Children.count(props.children); diff --git a/src/native_components/RNIModalSheetVIew/RNIModalSheetViewTypes.ts b/src/native_components/RNIModalSheetVIew/RNIModalSheetViewTypes.ts index 06dfdc92..050f8712 100644 --- a/src/native_components/RNIModalSheetVIew/RNIModalSheetViewTypes.ts +++ b/src/native_components/RNIModalSheetVIew/RNIModalSheetViewTypes.ts @@ -4,6 +4,8 @@ import type { StateReactTag, StateViewID } from "react-native-ios-utilities"; import type { RNIModalSheetNativeViewProps } from "./RNIModalSheetNativeView"; +import type { ModalMetrics } from "../../types/ModalMetrics"; + export type RNIModalSheetViewRef = { getViewID: () => StateViewID; @@ -16,6 +18,8 @@ export type RNIModalSheetViewRef = { dismissModal: (commandArgs: { isAnimated: boolean; }) => Promise; + + getModalMetrics: () => Promise; }; export type RNIModalSheetViewInheritedOptionalProps = Partial