Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class BottomSheetDemoController: DemoController {
bottomSheetViewController?.preferredWidth = sender.isOn ? 400 : 0
}

@objc private func toggleResizingViewOverlayContent(_ sender: BooleanCell) {
bottomSheetViewController?.shouldResizingViewOverlayContent = sender.isOn
}

@objc private func showTransientSheet() {
let hostingVC = UIHostingController(rootView: BottomSheetDemoListContentView())

Expand Down Expand Up @@ -275,7 +279,11 @@ class BottomSheetDemoController: DemoController {
DemoItem(title: "Set preferred width to 400",
type: .boolean,
action: #selector(togglePreferredWidth),
isOn: bottomSheetViewController?.preferredWidth == 400)
isOn: bottomSheetViewController?.preferredWidth == 400),
DemoItem(title: "Should resizing view overlay content",
type: .boolean,
action: #selector(toggleResizingViewOverlayContent),
isOn: bottomSheetViewController?.shouldResizingViewOverlayContent ?? false)
],
[
DemoItem(title: "Show transient sheet", type: .action, action: #selector(showTransientSheet))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,19 @@ public class BottomSheetController: UIViewController, Shadowable, TokenizedContr
/// When enabled, users will be able to move the sheet to the hidden state by swiping down.
@objc open var allowsSwipeToHide: Bool = false

/// Indicates whether the `resizingHandleView` should overlay the `headerContentHeight` or `expandedContentView`
///
/// The default value is false.
@objc open var shouldResizingViewOverlayContent: Bool = false {
didSet {
guard shouldResizingViewOverlayContent != oldValue && isViewLoaded else {
return
}
updateResizingHandleConstraints()
view.setNeedsLayout()
}
}

/// Current height of the portion of a collapsed sheet that's in the safe area.
@objc public private(set) var collapsedHeightInSafeArea: CGFloat = 0 {
didSet {
Expand Down Expand Up @@ -603,6 +616,16 @@ public class BottomSheetController: UIViewController, Shadowable, TokenizedContr
resizingHandleView.tokenSet.setOverrideValue(tokenSet[.resizingHandleMarkColor], forToken: .markColor)
}

private func updateResizingHandleConstraints() {
if let resizingHandleContentOverlapConstraints {
if shouldResizingViewOverlayContent {
NSLayoutConstraint.activate([resizingHandleContentOverlapConstraints])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will there not be conflicting constraints now?

} else {
NSLayoutConstraint.deactivate([resizingHandleContentOverlapConstraints])
}
}
}

private func updateShadow() {
switch style {
case .primary:
Expand Down Expand Up @@ -696,6 +719,14 @@ public class BottomSheetController: UIViewController, Shadowable, TokenizedContr
stackView.bottomAnchor.constraint(equalTo: bottomSheetContentView.bottomAnchor)
])

if let headerContentView {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combine with the if let on line 706

resizingHandleContentOverlapConstraints = headerContentView.topAnchor.constraint(equalTo: resizingHandleView.bottomAnchor, constant: -currentResizingHandleHeight)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just constrain to top anchor instead of constraining to bottom anchor and then applying negative offset?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the resizing view should just be added as a subview of the bottomSheetContentView. It shouldn't matter what's in the content, just that we overlay on top. And then depending on the bool value, we either shift the content stack down by the resizing handle height, or not. No constraint activating / deactivating needed.

} else {
resizingHandleContentOverlapConstraints = expandedContentView.topAnchor.constraint(equalTo: resizingHandleView.bottomAnchor, constant: -currentResizingHandleHeight)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll need to account for new height in expandedSheetHeight/collapsedSheetHeight

}
stackView.bringSubviewToFront(resizingHandleView)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe uikit works in order so if you add resizing handle last, you won't have to call bring subview to front

updateResizingHandleConstraints()

return makeBottomSheetByEmbedding(contentView: bottomSheetContentView)
}()

Expand Down Expand Up @@ -1337,6 +1368,8 @@ public class BottomSheetController: UIViewController, Shadowable, TokenizedContr

private var headerContentViewHeightConstraint: NSLayoutConstraint?

private var resizingHandleContentOverlapConstraints: NSLayoutConstraint?

private var currentStateChangeAnimator: UIViewPropertyAnimator?

private var currentExpansionState: BottomSheetExpansionState = .collapsed
Expand Down
Loading