-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⭐️ Impl:
ModalSheetBottomAttachedOverlayController
- Loading branch information
1 parent
b78cc5e
commit 7657c12
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
ios/ModalSheet/ModalSheetBottomAttachedOverlayController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
}; |