Skip to content

Commit

Permalink
⭐️ Impl: RNIModalSheetBottomAttachedOverlayController Scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Oct 6, 2024
1 parent 7657c12 commit 78a2bb4
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 214 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// RNIModalSheetBottomAttachedOverlayController.swift
// react-native-ios-modal
//
// Created by Dominic Go on 10/6/24.
//

import UIKit
import DGSwiftUtilities
import react_native_ios_utilities


public class RNIModalSheetBottomAttachedOverlayController:
ModalSheetBottomAttachedOverlayController {

public override func setupContent() {
defer {
super.setupContent();
};

// MARK: TODO TEMP!
self.contentController = DummyContentController();
self.view.backgroundColor = .red;
};
};

// MARK: TODO - TEMP!
public class DummyContentController: UIViewController {
public override func viewDidLoad() {
self.view.backgroundColor = .blue;

self.view.translatesAutoresizingMaskIntoConstraints = false;
NSLayoutConstraint.activate([
self.view.heightAnchor.constraint(equalToConstant: 100),
]);
};
};
179 changes: 0 additions & 179 deletions ios/RNIModalSheetView/RNIModalSheetDecorationController.swift

This file was deleted.

68 changes: 52 additions & 16 deletions ios/RNIModalSheetView/RNIModalSheetViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ open class RNIModalSheetViewController: ModalSheetViewControllerLifecycleNotifie
private(set) public weak var mainSheetContent: RNIWrapperViewContent?;

public var positionConfigForMainSheetContent: AlignmentPositionConfig = .default;

public var bottomOverlayController: RNIModalSheetBottomAttachedOverlayController?;

// MARK: - Computed Properties
// ---------------------------
Expand All @@ -46,6 +48,36 @@ open class RNIModalSheetViewController: ModalSheetViewControllerLifecycleNotifie
public override func viewDidLoad() {
super.viewDidLoad();

self.setupMainContent();
//self.setupBottomOverlayIfNeeded();
};

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
// --------------

func setupMainContent(){
guard let mainSheetContentParent = self.mainSheetContentParent,
let mainSheetContent = mainSheetContentParent.contentDelegate as? RNIWrapperViewContent
else {
Expand Down Expand Up @@ -91,27 +123,31 @@ open class RNIModalSheetViewController: ModalSheetViewControllerLifecycleNotifie
);
};
};

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

guard let mainSheetContentParent = self.mainSheetContentParent else {
func setupBottomOverlayIfNeeded(){
guard let bottomOverlayController = self.bottomOverlayController,
let targetView = self.closestSheetDropShadowView?.superview
else {
return;
};

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

// let the child setup constraints + add itself as it's subview...
// but, is this okay?
//
// 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
);

self.positionConfigForMainSheetContent.applySize(
toRootReactView: mainSheetContentParent,
attachingTo: self.view
);
targetView.bringSubviewToFront(bottomOverlayController.view);

self.addChild(bottomOverlayController);
bottomOverlayController.didMove(toParent: parent);
};

// MARK: Methods
// --------------
};

extension RNIModalSheetViewController: RNIViewLifecycle {
Expand Down
31 changes: 12 additions & 19 deletions ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public final class RNIModalSheetViewDelegate: UIView, RNIContentView {
public var modalSheetController: RNIModalSheetViewController?;
public var sheetMainContentParentView: RNIContentViewParentDelegate?;

public var sheetBottomAttachedOverlayController: RNIModalSheetDecorationController?;
public var sheetBottomAttachedOverlayController: RNIModalSheetBottomAttachedOverlayController?;
public var sheetBottomAttachedOverlayParentView: RNIContentViewParentDelegate?;

// MARK: - Properties - RNIContentViewDelegate
Expand Down Expand Up @@ -121,24 +121,17 @@ public final class RNIModalSheetViewDelegate: UIView, RNIContentView {
modalVC.sheetPresentationStateMachine.eventDelegates.add(self);
modalVC.modalFocusEventDelegates.add(self);

if let sheetBottomAttachedOverlayParentView = self.sheetBottomAttachedOverlayParentView {
let childVC = RNIModalSheetDecorationController();
self.sheetBottomAttachedOverlayController = childVC;

childVC.rootReactView = sheetBottomAttachedOverlayParentView;

childVC.positionConfig = .init(
horizontalAlignment: .stretchTarget,
verticalAlignment: .targetBottom
);

childVC.view.backgroundColor = .red;
childVC.view.alpha = 0.5;

modalVC.view.addSubview(childVC.view);
modalVC.addChild(childVC);
childVC.didMove(toParent: modalVC);
};
// 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;
// };

return modalVC;
};
Expand Down

0 comments on commit 78a2bb4

Please sign in to comment.