Skip to content

Commit

Permalink
Merge pull request #7085 from vector-im/mauroromito/7082_fix_scrollab…
Browse files Browse the repository at this point in the history
…le_bottom_sheet

Rich Text Editor: Scrollable and Custom Sizable Bottom Sheet
  • Loading branch information
Velin92 authored Nov 18, 2022
2 parents b5dc19d + 657f992 commit 47e9a53
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,26 @@ class VectorHostingBottomSheetPreferences {
case medium
case large

/// only available on iOS16, medium behaviour will be used instead
/// - Parameters:
/// - height: The height of the custom detent, if the height is bigger than the maximum possible height for a detent the latter will be returned
/// - identifier: The identifier used to identify the custom detent during detent transitions, by default the value is set to "custom", however if you are supporting multiple custom detents in a bottom sheet, you should specify a different identifier for each
case custom(height: CGFloat, identifier: String = "custom")

@available(iOS 15, *)
fileprivate func uiSheetDetent() -> UISheetPresentationController.Detent {
switch self {
case .medium: return .medium()
case .large: return .large()
case let .custom(height, identifier):
if #available(iOS 16, *) {
let identifier = UISheetPresentationController.Detent.Identifier(identifier)
return .custom(identifier: identifier) { context in
return min(height, context.maximumDetentValue)
}
} else {
return .medium()
}
}
}

Expand All @@ -38,6 +53,12 @@ class VectorHostingBottomSheetPreferences {
switch self {
case .medium: return .medium
case .large: return .large
case let .custom(_, identifier):
if #available(iOS 16, *) {
return UISheetPresentationController.Detent.Identifier(identifier)
} else {
return .medium
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ final class ComposerCreateActionListCoordinator: NSObject, Coordinator, Presenta
view = ComposerCreateActionList(viewModel: viewModel.context)
let hostingVC = VectorHostingController(rootView: view)
hostingVC.bottomSheetPreferences = VectorHostingBottomSheetPreferences(
detents: [.medium],
detents: [.custom(height: 470)],
prefersGrabberVisible: true,
cornerRadius: 20
cornerRadius: 20,
prefersScrollingExpandsWhenScrolledToEdge: false
)
hostingController = hostingVC
super.init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct ComposerCreateActionList: View {
@ObservedObject var viewModel: ComposerCreateActionListViewModel.Context

var body: some View {
VStack {
ScrollView {
VStack(alignment: .leading) {
ForEach(viewModel.viewState.actions) { action in
HStack(spacing: 16) {
Expand Down Expand Up @@ -78,9 +78,10 @@ struct ComposerCreateActionList: View {

}
}
.padding(.top, 8)
Spacer()
}.background(theme.colors.background.ignoresSafeArea())
}
.padding(.top, 23)
.background(theme.colors.background.ignoresSafeArea())
}
}

Expand Down
1 change: 1 addition & 0 deletions changelog.d/7082.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rich Text Composer: Bottom Sheet is sized to always show all the elements inside, and in case it reaches the top, is also scrollable.

0 comments on commit 47e9a53

Please sign in to comment.