Skip to content

Commit

Permalink
⭐️ Impl: ModalSheetBottomAttachedOverlayController
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Oct 6, 2024
1 parent b78cc5e commit 7657c12
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions ios/ModalSheet/ModalSheetBottomAttachedOverlayController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// RNIModalSheetDecorationController.swift
// react-native-ios-modal
//
// Created by Dominic Go on 10/3/24.
//

import UIKit
import DGSwiftUtilities


public class ModalSheetBottomAttachedOverlayController: UIViewController {

public var contentController: UIViewController?;

public var layoutConfig:
ModalSheetBottomAttachedOverlayLayoutConfig = .default;

public override func viewDidLoad() {
super.viewDidLoad();
self.setupContent();
};

// MARK: - Setup
// -------------

public func setupContent(){
guard let contentController = self.contentController else {
return;
};

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

var constraints: [NSLayoutConstraint] = [
self.view.leadingAnchor.constraint(
equalTo: contentController.view.leadingAnchor
),
self.view.trailingAnchor.constraint(
equalTo: contentController.view.trailingAnchor
),
self.view.topAnchor.constraint(
equalTo: contentController.view.topAnchor
),
];

constraints += self.layoutConfig.createInternalBottomConstraint(
forView: contentController.view,
attachingTo: self.view
);

NSLayoutConstraint.activate(constraints);

self.addChild(contentController);
contentController.didMove(toParent: self);
};

// MARK: - Methods
// ---------------

public func attachView(
anchoredToBottomEdgesOf bottomEdgeAnchorView: UIView,
withSheetContainerView sheetContainerView: UIView
){
self.view.translatesAutoresizingMaskIntoConstraints = false;
bottomEdgeAnchorView.addSubview(self.view);

var constraints: [NSLayoutConstraint] = [];
constraints += self.layoutConfig.createExternalHorizontalConstraints(
forView: self.view,
attachingTo: sheetContainerView
);

constraints += self.layoutConfig.createExternalBottomConstraints(
forView: self.view,
attachingTo: bottomEdgeAnchorView
);

NSLayoutConstraint.activate(constraints);
};
};

0 comments on commit 7657c12

Please sign in to comment.