Skip to content
Merged
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
61 changes: 53 additions & 8 deletions ios/epac/DesignSystem/Modifiers/AdaptiveLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,44 @@ private struct RegularSizeClassItemFormSheetModifier<Item: Identifiable, SheetCo
}
}

private struct FormSheetPresentationConfigurator: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> Controller {
Controller()
}

func updateUIViewController(_ uiViewController: Controller, context: Context) {
uiViewController.applyFormSheetPresentation()
}

final class Controller: UIViewController {
override func didMove(toParent parent: UIViewController?) {
super.didMove(toParent: parent)
applyFormSheetPresentation()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
applyFormSheetPresentation()
}

func applyFormSheetPresentation() {
guard let presentationHost else { return }
presentationHost.modalPresentationStyle = .formSheet
}

private var presentationHost: UIViewController? {
var controller = parent
while let current = controller {
if current.presentingViewController != nil {
return current
}
controller = current.parent
}
return parent
}
}
}

extension View {
/// Constrains long-form reading surfaces to `AdaptiveLayout.readingWidth` in a regular
/// horizontal size class while leaving compact layouts unchanged.
Expand All @@ -63,8 +101,8 @@ extension View {
modifier(AdaptiveReadingWidthModifier())
}

/// Presents a sheet normally in compact width and with medium/large detents plus a visible
/// drag indicator in a regular horizontal size class.
/// Presents a sheet normally in compact width and as a form-sized sheet with medium/large
/// detents plus a visible drag indicator in a regular horizontal size class.
///
/// Use this as the Stage-2 drop-in replacement for `.sheet(isPresented:content:)` when a
/// modal should adapt to iPad and Mac Catalyst form-sheet ergonomics. Do not use it for flows
Expand All @@ -76,8 +114,8 @@ extension View {
regularSizeClassFormSheet(isPresented: isPresented, onDismiss: nil, content: content)
}

/// Presents a sheet normally in compact width and with medium/large detents plus a visible
/// drag indicator in a regular horizontal size class.
/// Presents a sheet normally in compact width and as a form-sized sheet with medium/large
/// detents plus a visible drag indicator in a regular horizontal size class.
///
/// Use this as the Stage-2 drop-in replacement for `.sheet(isPresented:onDismiss:content:)`
/// when a modal should adapt to iPad and Mac Catalyst form-sheet ergonomics. Do not use it for
Expand All @@ -96,8 +134,8 @@ extension View {
)
}

/// Presents an item-driven sheet normally in compact width and with medium/large detents plus
/// a visible drag indicator in a regular horizontal size class.
/// Presents an item-driven sheet normally in compact width and as a form-sized sheet with
/// medium/large detents plus a visible drag indicator in a regular horizontal size class.
///
/// Use this as the Stage-2 drop-in replacement for `.sheet(item:onDismiss:content:)` when a
/// modal should adapt to iPad and Mac Catalyst form-sheet ergonomics. Do not use it for flows
Expand All @@ -121,8 +159,15 @@ private extension View {
@ViewBuilder
func regularSizeClassSheetChrome(isEnabled: Bool) -> some View {
if isEnabled {
presentationDetents([.medium, .large])
.presentationDragIndicator(.visible)
if #available(iOS 18.0, *) {
presentationSizing(.form)
.presentationDetents([.medium, .large])
.presentationDragIndicator(.visible)
} else {
background(FormSheetPresentationConfigurator())
.presentationDetents([.medium, .large])
.presentationDragIndicator(.visible)
}
} else {
self
}
Expand Down
2 changes: 1 addition & 1 deletion ios/epac/Views/Common/DataSourceBadge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct DataSourceBadge: View {
}
.accessibilityLabel("\(source.name) — \(badgeText)")
.accessibilityHint("Opens source details")
.sheet(isPresented: $showDetail) {
.regularSizeClassFormSheet(isPresented: $showDetail) {
DataSourceDetailSheet(source: source)
}
}
Expand Down
2 changes: 1 addition & 1 deletion ios/epac/Views/Common/ExplainerCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ struct ExplainerTipModifier: ViewModifier {
.buttonStyle(.plain)
.accessibilityLabel("What is \(term)?")
}
.sheet(isPresented: $showExplainer) {
.regularSizeClassFormSheet(isPresented: $showExplainer) {
ExplainerCard(explainer: explainer)
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions ios/epac/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ struct ContentView: View {
}
.interactiveDismissDisabled()
}
.sheet(isPresented: $showMyMPSetup) {
.regularSizeClassFormSheet(isPresented: $showMyMPSetup) {
PostalCodeSetupView { showMyMPSetup = false }
}
.onChange(of: router.pendingShowPostalCodeSetup) { _, pending in
Expand All @@ -160,7 +160,7 @@ struct ContentView: View {
handleQuickAction(action)
router.pendingQuickAction = nil
}
.sheet(isPresented: $showWhatsNew) {
.regularSizeClassFormSheet(isPresented: $showWhatsNew) {
WhatsNewView { showWhatsNew = false }
.presentationDetents([.medium])
.presentationDragIndicator(.visible)
Expand Down
4 changes: 2 additions & 2 deletions ios/epac/Views/Home/HomeFeedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ struct HomeFeedView: View {
.task {
await loadFeed()
}
.sheet(isPresented: $showPostalCodeSetup) {
.regularSizeClassFormSheet(isPresented: $showPostalCodeSetup) {
PostalCodeSetupView { showPostalCodeSetup = false }
}
.onChange(of: postalCodeStore.savedMemberName) {
Task { await loadFeed() }
}
.sheet(isPresented: $showSettings) {
.regularSizeClassFormSheet(isPresented: $showSettings) {
SettingsView()
}
}
Expand Down
2 changes: 1 addition & 1 deletion ios/epac/Views/Members/MemberProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ struct MemberProfileView: View {
.environmentObject(fetch)
}
.activitySheet($shareItem)
.sheet(isPresented: $showingComparePicker) {
.regularSizeClassFormSheet(isPresented: $showingComparePicker) {
NavigationStack {
List(pickableMembers) { other in
Button {
Expand Down
2 changes: 1 addition & 1 deletion ios/epac/Views/Members/PartyLineScoreView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct PartyLineScoreView: View {
.padding()
.background(Color(.secondarySystemBackground))
.cornerRadius(EpacCornerRadius.m)
.sheet(isPresented: $showInfo) { infoSheet }
.regularSizeClassFormSheet(isPresented: $showInfo) { infoSheet }
}

private var infoSheet: some View {
Expand Down
2 changes: 1 addition & 1 deletion ios/epac/Views/MyMP/MyMPView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ struct MyMPView: View {
Task { await loadActivities() }
}
}
.sheet(isPresented: $showPostalCodeSetup) {
.regularSizeClassFormSheet(isPresented: $showPostalCodeSetup) {
PostalCodeSetupView { showPostalCodeSetup = false }
}
}
Expand Down
2 changes: 1 addition & 1 deletion ios/epac/Views/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct SettingsView: View {
Button(NSLocalizedString("settings.done", comment: "")) { dismiss() }
}
}
.sheet(isPresented: $showPostalCodeChange) {
.regularSizeClassFormSheet(isPresented: $showPostalCodeChange) {
PostalCodeSetupView { showPostalCodeChange = false }
}
}
Expand Down
Loading