diff --git a/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift b/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift index a48eae81..71a80d24 100644 --- a/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift +++ b/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift @@ -11,6 +11,10 @@ import react_native_ios_utilities @objc(RNIModalSheetViewDelegate) public final class RNIModalSheetViewDelegate: UIView, RNIContentView { + + enum NativeIDKey: String { + case mainSheetContent; + }; public static var propKeyPathMap: Dictionary> { return [:]; @@ -23,13 +27,15 @@ public final class RNIModalSheetViewDelegate: UIView, RNIContentView { // MARK: Properties // ---------------- + public var detachedModalContentParentViews: [RNIContentViewParentDelegate] = []; + + public var modalSheetController: RNIModalSheetViewController?; + public var sheetMainContentParentView: RNIContentViewParentDelegate?; + // MARK: - Properties - RNIContentViewDelegate // ------------------------------------------- public weak var parentReactView: RNIContentViewParentDelegate?; - public var modalSheetController: RNIModalSheetViewController?; - - public var detachedModalContentParentViews: [RNIContentViewParentDelegate] = []; // MARK: Properties - Props // ------------------------ @@ -68,16 +74,27 @@ extension RNIModalSheetViewDelegate: RNIContentViewDelegate { superBlock: () -> Void ) { + defer { + childComponentView.removeFromSuperview(); + }; + guard let reactView = childComponentView as? RNIContentViewParentDelegate, - reactView.contentDelegate is RNIWrapperViewContent + reactView.contentDelegate is RNIWrapperViewContent, + let nativeID = reactView.reactNativeID, + let nativeIDKey = NativeIDKey(rawValue: nativeID) else { return; }; - reactView.removeFromSuperview(); - reactView.attachReactTouchHandler(); + defer { + reactView.attachReactTouchHandler(); + self.detachedModalContentParentViews.append(reactView); + }; - self.detachedModalContentParentViews.append(reactView); + switch nativeIDKey { + case .mainSheetContent: + self.sheetMainContentParentView = reactView; + }; }; public func notifyOnUnmountChildComponentView( @@ -122,11 +139,8 @@ extension RNIModalSheetViewDelegate: RNIContentViewDelegate { guard let closestVC = closestVC else { throw RNIUtilitiesError(errorCode: .unexpectedNilValue); }; - - let mainSheetContentParent = - self.detachedModalContentParentViews.first; - guard let mainSheetContentParent = mainSheetContentParent else { + guard let mainSheetContentParent = self.sheetMainContentParentView else { throw RNIUtilitiesError(errorCode: .unexpectedNilValue); }; diff --git a/src/components/ModalSheetView/ModalSheetViewContent.tsx b/src/components/ModalSheetView/ModalSheetViewContent.tsx index 0c9fea4c..6fd17651 100644 --- a/src/components/ModalSheetView/ModalSheetViewContent.tsx +++ b/src/components/ModalSheetView/ModalSheetViewContent.tsx @@ -40,7 +40,6 @@ export function ModalSheetViewContent( ? styles.wrapperViewDetached : styles.wrapperViewAttached ), - props.style, ]} onDidSetViewID={(event) => { props.onDidSetViewID?.(event); diff --git a/src/components/ModalSheetView/ModalSheetViewContentTypes.tsx b/src/components/ModalSheetView/ModalSheetViewContentTypes.tsx index 1dbf4d5f..cf1ffbe5 100644 --- a/src/components/ModalSheetView/ModalSheetViewContentTypes.tsx +++ b/src/components/ModalSheetView/ModalSheetViewContentTypes.tsx @@ -1,5 +1,4 @@ import type { ViewStyle } from 'react-native'; - import type { RNIWrapperViewProps } from 'react-native-ios-utilities'; import type { RNIModalSheetViewProps } from "../../native_components/RNIModalSheetVIew"; @@ -8,6 +7,9 @@ import type { ModalSheetContentMap } from "./ModalSheetContentMap"; export type ModalSheetViewContentInheritedProps = Pick & Pick; export type ModalSheetViewContentBaseProps = { @@ -17,6 +19,5 @@ export type ModalSheetViewContentBaseProps = { }; export type ModalSheetViewContentProps = - RNIWrapperViewProps & ModalSheetViewContentInheritedProps & ModalSheetViewContentBaseProps; \ No newline at end of file diff --git a/src/components/ModalSheetView/ModalSheetViewMainContent.tsx b/src/components/ModalSheetView/ModalSheetViewMainContent.tsx new file mode 100644 index 00000000..9b7837d3 --- /dev/null +++ b/src/components/ModalSheetView/ModalSheetViewMainContent.tsx @@ -0,0 +1,20 @@ +import * as React from 'react'; + +import { ModalSheetViewContent } from './ModalSheetViewContent'; +import type { ModalSheetViewMainContentProps } from './ModalSheetViewMainContentTypes'; +import { ModalSheetViewNativeIDKeys } from './ModalSheetViewNativeIDKeys'; + + +export function ModalSheetViewMainContent( + props: React.PropsWithChildren +) { + const { children, ...otherProps } = props; + return ( + + {children} + + ); +}; \ No newline at end of file diff --git a/src/components/ModalSheetView/ModalSheetViewMainContentTypes.ts b/src/components/ModalSheetView/ModalSheetViewMainContentTypes.ts new file mode 100644 index 00000000..714cf859 --- /dev/null +++ b/src/components/ModalSheetView/ModalSheetViewMainContentTypes.ts @@ -0,0 +1,13 @@ +import type { ModalSheetViewContentProps } from './ModalSheetViewContentTypes'; + + +export type ModalSheetViewMainContentInheritedProps = Pick; + +export type ModalSheetViewMainContentBaseProps = { +}; + +export type ModalSheetViewMainContentProps = + & ModalSheetViewMainContentInheritedProps + & ModalSheetViewMainContentBaseProps; \ No newline at end of file diff --git a/src/components/ModalSheetView/ModalSheetViewNativeIDKeys.ts b/src/components/ModalSheetView/ModalSheetViewNativeIDKeys.ts index 3d314e3e..48392317 100644 --- a/src/components/ModalSheetView/ModalSheetViewNativeIDKeys.ts +++ b/src/components/ModalSheetView/ModalSheetViewNativeIDKeys.ts @@ -1,5 +1,5 @@ -export const MODAL_SHEET_VIEW_CONTENT_NATIVE_ID_KEYS = Object.freeze({ +export const ModalSheetViewNativeIDKeys = Object.freeze({ mainSheetContent: 'mainSheetContent', }); \ No newline at end of file diff --git a/src/components/ModalSheetView/index.ts b/src/components/ModalSheetView/index.ts index c10591ff..de8822ba 100644 --- a/src/components/ModalSheetView/index.ts +++ b/src/components/ModalSheetView/index.ts @@ -1,7 +1,7 @@ export * from './ModalSheetView'; -export * from './ModalSheetViewContent'; +export * from './ModalSheetViewMainContent'; export type * from './ModalSheetViewTypes'; export type * from './ModalSheetViewContentTypes';