Skip to content

Commit

Permalink
💫 Update: RNIModalSheetViewController Content Layout Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Oct 7, 2024
1 parent edaaec5 commit 944874a
Showing 1 changed file with 28 additions and 53 deletions.
81 changes: 28 additions & 53 deletions ios/RNIModalSheetView/RNIModalSheetViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ open class RNIModalSheetViewController: ModalSheetViewControllerLifecycleNotifie
public weak var mainSheetContentParent: RNIContentViewParentDelegate?;
private(set) public weak var mainSheetContent: RNIWrapperViewContent?;

public var positionConfigForMainSheetContent: AlignmentPositionConfig = .default;

public var mainSheetContentController: RNIContentViewController?;
public var bottomOverlayController: RNIModalSheetBottomAttachedOverlayController?;

// MARK: - Computed Properties
// ---------------------------

// TODO: TEMP!
public var baseEventObject: [String: Any] {
var eventDict: [String: Any] = [:];

Expand Down Expand Up @@ -55,24 +55,6 @@ open class RNIModalSheetViewController: ModalSheetViewControllerLifecycleNotifie
public override func viewIsAppearing(_ animated: Bool) {
self.setupBottomOverlayIfNeeded();
};

public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews();

guard let mainSheetContentParent = self.mainSheetContentParent else {
return;
};

self.positionConfigForMainSheetContent.setIntrinsicContentSizeOverrideIfNeeded(
forRootReactView: mainSheetContentParent,
withSize: self.view.bounds.size
);

self.positionConfigForMainSheetContent.applySize(
toRootReactView: mainSheetContentParent,
attachingTo: self.view
);
};

// MARK: Methods
// --------------
Expand All @@ -87,41 +69,35 @@ open class RNIModalSheetViewController: ModalSheetViewControllerLifecycleNotifie
self.mainSheetContent = mainSheetContent;
mainSheetContentParent.reactViewLifecycleDelegates.add(self);

// MARK: Setup Constraints
#if !RCT_NEW_ARCH_ENABLED
mainSheetContentParent.removeAllAncestorConstraints();
#endif

self.view.addSubview(mainSheetContentParent);
mainSheetContentParent.translatesAutoresizingMaskIntoConstraints = false;

let constraints = self.positionConfigForMainSheetContent.createConstraints(
forView: mainSheetContentParent,
attachingTo: self.view,
enclosingView: self.view
);

NSLayoutConstraint.activate(constraints);
let contentVC = RNIContentViewController();
contentVC.reactContentParentView = mainSheetContentParent;
contentVC.contentSizingMode = .sizingFromNative;
contentVC.contentPositioningMode = .stretch;

// MARK: Set Initial Size
let hasValidSize = !self.view.bounds.size.isZero;
if hasValidSize {
self.positionConfigForMainSheetContent.setIntrinsicContentSizeOverrideIfNeeded(
forRootReactView: mainSheetContentParent,
withSize: self.view.bounds.size
);
self.addChild(contentVC);
defer {
contentVC.didMove(toParent: self);
};

let shouldSetSize =
hasValidSize
&& self.positionConfigForMainSheetContent.isStretchingOnBothAxis;

if shouldSetSize {
self.positionConfigForMainSheetContent.applySize(
toRootReactView: mainSheetContentParent,
attachingTo: self.view
);
};
// MARK: Setup Layout

self.view.addSubview(contentVC.view);
contentVC.view.translatesAutoresizingMaskIntoConstraints = false;

NSLayoutConstraint.activate([
contentVC.view.leadingAnchor.constraint(
equalTo: self.view.leadingAnchor
),
contentVC.view.trailingAnchor.constraint(
equalTo: self.view.trailingAnchor
),
contentVC.view.topAnchor.constraint(
equalTo: self.view.topAnchor
),
contentVC.view.bottomAnchor.constraint(
equalTo: self.view.bottomAnchor
),
]);
};

func setupBottomOverlayIfNeeded(){
Expand All @@ -137,7 +113,6 @@ open class RNIModalSheetViewController: ModalSheetViewControllerLifecycleNotifie
// wouldn't it be better if the logic for layout be handled in the child
// vc's `didMove` lifecycle method?
//
//
bottomOverlayController.attachView(
anchoredToBottomEdgesOf: targetView,
withSheetContainerView: self.view
Expand Down

0 comments on commit 944874a

Please sign in to comment.