From 7657c124d2b3178504b14c6165abaf84f7353251 Mon Sep 17 00:00:00 2001 From: Dominic Go Date: Sun, 6 Oct 2024 08:16:12 +0800 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20Impl:=20`ModalSheetBottomA?= =?UTF-8?q?ttachedOverlayController`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...SheetBottomAttachedOverlayController.swift | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 ios/ModalSheet/ModalSheetBottomAttachedOverlayController.swift diff --git a/ios/ModalSheet/ModalSheetBottomAttachedOverlayController.swift b/ios/ModalSheet/ModalSheetBottomAttachedOverlayController.swift new file mode 100644 index 0000000..5a85316 --- /dev/null +++ b/ios/ModalSheet/ModalSheetBottomAttachedOverlayController.swift @@ -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); + }; +};