cleanup tweaks

This commit is contained in:
Hailey
2024-10-09 19:20:48 -07:00
parent 2841944789
commit 3aa9980ba5
3 changed files with 28 additions and 24 deletions
+24 -18
View File
@@ -3,9 +3,14 @@ import UIKit
class SheetView: ExpoView, UISheetPresentationControllerDelegate {
// Views
private var sheetVc: SheetViewController?
private var sheetVc: SheetViewController!
private var innerView: UIView?
private var touchHandler: RCTTouchHandler?
// Scroll view
private var scrollView: RCTScrollView?
// Touch handler
private var touchHandler: RCTTouchHandler!
// Events
private let onAttemptDismiss = EventDispatcher()
@@ -26,9 +31,9 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate {
var preventExpansion = false
var cornerRadius: CGFloat?
var minHeight = 0.0
var maxHeight: CGFloat! {
var maxHeight: CGFloat = Util.getScreenHeight() {
didSet {
let screenHeight = Util.getScreenHeight() ?? 0
let screenHeight = Util.getScreenHeight()
if maxHeight > screenHeight {
maxHeight = screenHeight
}
@@ -66,14 +71,22 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate {
}
}
}
private var prevLayoutDetentIdentifier: UISheetPresentationController.Detent.Identifier?
// MARK: - Lifecycle
required init (appContext: AppContext? = nil) {
super.init(appContext: appContext)
self.maxHeight = Util.getScreenHeight()
self.touchHandler = RCTTouchHandler(bridge: appContext?.reactBridge)
self.touchHandler = RCTTouchHandler(bridge: self.appContext?.reactBridge)
self.sheetVc = SheetViewController()
self.touchHandler.attach(to: self.sheetVc.view)
if let sheet = self.sheetVc.sheetPresentationController {
sheet.delegate = self
}
SheetManager.shared.add(self)
}
@@ -84,7 +97,6 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate {
// We don't want this view to actually get added to the tree, so we'll simply store it for adding
// to the SheetViewController
override func insertReactSubview(_ subview: UIView!, at atIndex: Int) {
self.touchHandler?.attach(to: subview)
self.innerView = subview
}
@@ -106,10 +118,7 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate {
private func destroy() {
self.isClosing = false
self.isOpen = false
self.sheetVc = nil
self.touchHandler?.detach(from: self.innerView)
self.touchHandler = nil
self.innerView = nil
SheetManager.shared.remove(self)
}
@@ -125,16 +134,13 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate {
return
}
let sheetVc = SheetViewController()
sheetVc.setDetents(contentHeight: self.clampHeight(contentHeight), preventExpansion: self.preventExpansion)
self.sheetVc.view.addSubview(innerView)
self.sheetVc.setDetents(contentHeight: self.clampHeight(contentHeight), preventExpansion: self.preventExpansion)
if let sheet = sheetVc.sheetPresentationController {
sheet.delegate = self
sheet.preferredCornerRadius = self.cornerRadius
self.selectedDetentIdentifier = sheet.selectedDetentIdentifier
}
sheetVc.view.addSubview(innerView)
self.sheetVc = sheetVc
self.isOpening = true
rvc.present(sheetVc, animated: true) { [weak self] in
@@ -146,16 +152,16 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate {
func updateLayout() {
if self.prevLayoutDetentIdentifier == self.selectedDetentIdentifier,
let contentHeight = self.innerView?.subviews.first?.frame.size.height {
self.sheetVc?.updateDetents(contentHeight: self.clampHeight(contentHeight),
self.sheetVc.updateDetents(contentHeight: self.clampHeight(contentHeight),
preventExpansion: self.preventExpansion)
self.selectedDetentIdentifier = self.sheetVc?.getCurrentDetentIdentifier()
self.selectedDetentIdentifier = self.sheetVc.getCurrentDetentIdentifier()
}
self.prevLayoutDetentIdentifier = self.selectedDetentIdentifier
}
func dismiss() {
self.isClosing = true
self.sheetVc?.dismiss(animated: true) { [weak self] in
self.sheetVc.dismiss(animated: true) { [weak self] in
self?.destroy()
}
}
@@ -21,13 +21,11 @@ class SheetViewController: UIViewController {
}
func setDetents(contentHeight: CGFloat, preventExpansion: Bool) {
guard let sheet = self.sheetPresentationController,
let screenHeight = Util.getScreenHeight()
else {
guard let sheet = self.sheetPresentationController else {
return
}
if contentHeight > screenHeight - 100 {
if contentHeight > Util.getScreenHeight() - 100 {
sheet.detents = [
.large()
]
+2 -2
View File
@@ -6,13 +6,13 @@
//
class Util {
static func getScreenHeight() -> CGFloat? {
static func getScreenHeight() -> CGFloat {
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first {
let safeAreaInsets = window.safeAreaInsets
let fullScreenHeight = UIScreen.main.bounds.height
return fullScreenHeight - (safeAreaInsets.top + safeAreaInsets.bottom)
}
return nil
return 0
}
}