diff --git a/ios/RNIModalSheetView/RNIModalSheetBottomAttachedOverlayController.swift b/ios/RNIModalSheetView/RNIModalSheetBottomAttachedOverlayController.swift index f6023c8..541dc98 100644 --- a/ios/RNIModalSheetView/RNIModalSheetBottomAttachedOverlayController.swift +++ b/ios/RNIModalSheetView/RNIModalSheetBottomAttachedOverlayController.swift @@ -9,29 +9,82 @@ import UIKit import DGSwiftUtilities import react_native_ios_utilities - public class RNIModalSheetBottomAttachedOverlayController: ModalSheetBottomAttachedOverlayController { + public var reactParentView: RNIContentViewParentDelegate?; + public override func setupContent() { defer { super.setupContent(); }; - // MARK: TODO TEMP! - self.contentController = DummyContentController(); - self.view.backgroundColor = .red; + guard let reactParentView = self.reactParentView else { + return; + }; + + let childVC = RNIContentViewController(); + self.contentController = childVC; + + childVC.reactContentParentView = reactParentView; + childVC.contentSizingMode = .sizingHeightFromReactAndWidthFromNative; + + //self.contentController = DummyContentController(); + }; }; -// MARK: TODO - TEMP! +// MARK: - RNIContentViewController+RNIViewLifecycle +// ------------------------------------------------- + +extension RNIContentViewController: RNIViewLifecycle { + + public func notifyOnUpdateLayoutMetrics( + sender: RNIContentViewParentDelegate, + oldLayoutMetrics: RNILayoutMetrics, + newLayoutMetrics: RNILayoutMetrics + ) { + + guard self.contentSizingMode.isSizingWidthOrHeightFromReact else { + return; + }; + + self.view.setNeedsLayout(); + + return; + self.view.updateConstraints() + self.reactContentParentView?.invalidateIntrinsicContentSize(); + + print( + "RNIContentViewController.\(#function)", + "\n - reactContentParentView.intrinsicContentSize", self.reactContentParentView?.intrinsicContentSize.debugDescription ?? "N/A", + "\n - reactContentParentView.intrinsicContentSize", self.reactContentParentView?.intrinsicContentSizeOverride.debugDescription ?? "N/A", + "\n - arg oldLayoutMetrics.frame", oldLayoutMetrics.frame.size.debugDescription, + "\n - arg oldLayoutMetrics.contentFrame", oldLayoutMetrics.contentFrame.size, + "\n - arg newLayoutMetrics", newLayoutMetrics.frame.size.debugDescription, + "\n - arg newLayoutMetrics.contentFrame", oldLayoutMetrics.contentFrame.size, + "\n" + ); + } +}; + + + + public class DummyContentController: UIViewController { public override func viewDidLoad() { self.view.backgroundColor = .blue; + let size = self.view.bounds.size; + self.view.translatesAutoresizingMaskIntoConstraints = false; NSLayoutConstraint.activate([ self.view.heightAnchor.constraint(equalToConstant: 100), ]); }; + + public override func viewWillLayoutSubviews() { + let size = self.view.bounds.size; + print(size); + } }; diff --git a/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift b/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift index 0c7fc5d..4b47047 100644 --- a/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift +++ b/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift @@ -120,18 +120,14 @@ public final class RNIModalSheetViewDelegate: UIView, RNIContentView { modalVC.modalLifecycleEventDelegates.add(self); modalVC.sheetPresentationStateMachine.eventDelegates.add(self); modalVC.modalFocusEventDelegates.add(self); - - // TODO: TEMP!! - let childVC = RNIModalSheetBottomAttachedOverlayController(); - modalVC.bottomOverlayController = childVC; - - // if let sheetBottomAttachedOverlayParentView = self.sheetBottomAttachedOverlayParentView { - // let childVC = RNIModalSheetBottomAttachedOverlayController(); - // self.sheetBottomAttachedOverlayController = childVC; - // modalVC.bottomAttachedOverlayController = childVC; - // - // childVC.mainContentView = sheetBottomAttachedOverlayParentView; - // }; + + if let sheetBottomAttachedOverlayParentView = self.sheetBottomAttachedOverlayParentView { + let childVC = RNIModalSheetBottomAttachedOverlayController(); + self.sheetBottomAttachedOverlayController = childVC; + modalVC.bottomOverlayController = childVC; + + childVC.reactParentView = sheetBottomAttachedOverlayParentView; + }; return modalVC; }; diff --git a/ios/Temp/RNIContentViewController.swift b/ios/Temp/RNIContentViewController.swift new file mode 100644 index 0000000..e81fa4b --- /dev/null +++ b/ios/Temp/RNIContentViewController.swift @@ -0,0 +1,113 @@ +// +// RNIContentViewController.swift +// react-native-ios-modal +// +// Created by Dominic Go on 10/7/24. +// + +import UIKit +import DGSwiftUtilities +import react_native_ios_utilities + + +public class RNIContentViewController: UIViewController { + + public typealias ContentSizingMode = RNIContentSizingMode; + public typealias ContentPositioningMode = RNIContentPositioningMode; + + // MARK: - Properties + // ------------------ + + public var contentSizingMode: ContentSizingMode = .sizingFromNative; + public var contentPositioningMode: ContentPositioningMode = .stretch; + + public var nativeViewHeightConstraint: NSLayoutConstraint?; + public var nativeViewWidthConstraint: NSLayoutConstraint?; + + public var reactContentParentView: RNIContentViewParentDelegate?; + + // MARK: - View Controller Lifecycle + // --------------------------------- + + public override func loadView() { + super.loadView(); + }; + + public override func viewDidLoad() { + guard let reactContentParentView = self.reactContentParentView else { + return; + }; + + reactContentParentView.reactViewLifecycleDelegates.add(self); + + reactContentParentView.translatesAutoresizingMaskIntoConstraints = false; + self.view.addSubview(reactContentParentView); + + let constraints = self.contentPositioningMode.createConstraints( + forView: reactContentParentView, + attachingTo: self.view + ); + + // self.nativeViewHeightConstraint = self.view.heightAnchor.constraint( + // equalToConstant: reactContentParentView.cachedLayoutMetrics?.frame.height ?? 0 + // ); + + + + // constraints.append( + // self.view.heightAnchor.constraint( + // equalTo: reactContentParentView.heightAnchor + // ) + // ); + // + // let constraints = [ + // reactContentParentView.leadingAnchor.constraint( + // equalTo: self.view.leadingAnchor + // ), + // reactContentParentView.trailingAnchor.constraint( + // equalTo: self.view.trailingAnchor + // ), + // reactContentParentView.bottomAnchor.constraint( + // equalTo: self.view.bottomAnchor + // ), + // self.view.heightAnchor.constraint( + // equalTo: reactContentParentView.heightAnchor + // ), + // ]; + + + + // self.view.backgroundColor = .red; + + + + NSLayoutConstraint.activate(constraints); + + // MARK: Set Initial Size + let newSize = self.view.bounds.size; + let hasValidSize = !newSize.isZero; + + if hasValidSize { + self.contentSizingMode.updateReactSizeIfNeeded( + forReactParent: reactContentParentView, + withNewSize: newSize + ); + }; + }; + + public override func viewWillLayoutSubviews() { + self.updateSizeIfNeeded(); + }; + + public func updateSizeIfNeeded(){ + guard let reactContentParentView = self.reactContentParentView else { + return; + }; + + let newSize = self.view.bounds.size; + self.contentSizingMode.updateReactSizeIfNeeded( + forReactParent: reactContentParentView, + withNewSize: newSize + ); + }; +};