Skip to content

Commit

Permalink
MacOS Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
BenRiceM committed Jan 8, 2025
1 parent 59b1660 commit 26fd579
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
61 changes: 36 additions & 25 deletions Sources/AdaptiveSheet/AdaptiveSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ struct AdaptiveModifier<CardContent: View, PinnedContent: View>: ViewModifier {
}

private var availableDetents : Set<PresentationDetent> {

guard !isMacEnvironment else { return [.large] }

return isExpandable && style != .alert
? [adaptiveDetent, adaptiveDetentTwo, .large]
: [adaptiveDetent, adaptiveDetentTwo]
Expand All @@ -169,12 +166,7 @@ struct AdaptiveModifier<CardContent: View, PinnedContent: View>: ViewModifier {
self.fullHeightDidChange = fullHeightDidChange
self.onDismiss = onDismiss

if isMacEnvironment {
self.selectedDetent = .large
self.isExpandable = true
} else {
self.selectedDetent = .height(.defaultDetentHeight)
}
self.selectedDetent = .height(.defaultDetentHeight)
}

private var minimumFittingSize : CGSize
Expand All @@ -183,14 +175,9 @@ struct AdaptiveModifier<CardContent: View, PinnedContent: View>: ViewModifier {
content
.sheet(isPresented: $isPresented) {
onDismiss?()

if UIDevice.current.userInterfaceIdiom == .mac {
selectedDetent = .large
} else {
selectedDetent = adaptiveDetent
}
selectedDetent = adaptiveDetent
} content: {
if #available(iOS 18.0, *), UIDevice.current.userInterfaceIdiom == .pad, !isMacEnvironment {
if #available(iOS 18.0, *), UIDevice.current.userInterfaceIdiom == .pad {
sheetBody
.frame(minWidth: minimumFittingSize.width, minHeight: minimumFittingSize.height)
.presentationSizing(.fitted.sticky(horizontal: true, vertical: false))
Expand Down Expand Up @@ -222,7 +209,13 @@ struct AdaptiveModifier<CardContent: View, PinnedContent: View>: ViewModifier {
heightLimit: trueHeightLimit,
cardContent: cardContent
)
.background { BackgroundFill(isLargeSheet: isLargeSheet) }
.background {
if isMacEnvironment {
EmptyView()
} else {
BackgroundFill(isLargeSheet: isLargeSheet)
}
}
.overlay(alignment: .bottom, content: {
bottomPinnedContent($isPresented, $selectedDetent)
.background { PinnedGradientView(isLargeSheet: isLargeSheet) }
Expand All @@ -244,7 +237,13 @@ struct AdaptiveModifier<CardContent: View, PinnedContent: View>: ViewModifier {
.background { PinnedGradientView(isLargeSheet: isLargeSheet) }
.ignoresSafeArea(edges: .bottom)
})
.background { BackgroundFill(isLargeSheet: isLargeSheet) }
.background {
if isMacEnvironment {
EmptyView()
} else {
BackgroundFill(isLargeSheet: isLargeSheet)
}
}

case .navigationListView:

Expand All @@ -271,7 +270,7 @@ struct AdaptiveModifier<CardContent: View, PinnedContent: View>: ViewModifier {
}
.tint(.primary)
.mask(BackgroundFill(isLargeSheet: isLargeSheet))
.padding(.horizontal, isLargeSheet ? 0 : 16)
.padding(.horizontal, (isMacEnvironment || isLargeSheet) ? 0 : 16)
.scrollBounceBehavior(.basedOnSize)
.scrollIndicators(isLargeSheet ? .automatic : .hidden)
.presentationDragIndicator(.hidden)
Expand Down Expand Up @@ -313,7 +312,13 @@ struct AdaptiveAlertView<CardContent: View> : View {
ScrollView {
cardContent($isPresented, $selectedDetent)
.frame(maxWidth: .infinity)
.background { BackgroundFill(isLargeSheet: isLargeSheet) }
.background {
if isMacEnvironment {
EmptyView()
} else {
BackgroundFill(isLargeSheet: isLargeSheet)
}
}
.onGeometryChange(for: CGFloat.self, of: \.size.height) {
AdaptiveLayout.handleHeightChange(
to: $0,
Expand Down Expand Up @@ -473,12 +478,20 @@ struct PinnedGradientView: View {
struct BackgroundFill : View {
var isLargeSheet : Bool
var body: some View {
RoundedRectangle(cornerRadius: isLargeSheet ? 0 : 36)
.foregroundStyle(Color.backgroundColor)
.ignoresSafeArea(.all, edges: isLargeSheet ? [.bottom] : [])
if isMacEnvironment {
Rectangle()
.foregroundStyle(Color.backgroundColor)
.ignoresSafeArea(.all, edges: isLargeSheet ? [.bottom] : [])
} else {
RoundedRectangle(cornerRadius: isLargeSheet || isMacEnvironment ? 0 : 36)
.foregroundStyle(Color.backgroundColor)
.ignoresSafeArea(.all, edges: isLargeSheet ? [.bottom] : [])
}
}
}



struct AdaptiveLayout {

@MainActor
Expand All @@ -490,8 +503,6 @@ struct AdaptiveLayout {
isExpandable: Binding<Bool> = .constant(false),
heightLimit: CGFloat
) {
guard !isMacEnvironment else { return }

var isLargeSheet : Bool { selectedDetent.wrappedValue == .large }

isExpandable.wrappedValue = height > heightLimit
Expand Down
3 changes: 2 additions & 1 deletion Sources/AdaptiveSheet/AdaptiveSheetPreview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public struct AdaptiveSheetPreview: View {
)
}
}
.frame(maxWidth: 600)
.adaptiveAlert(isPresented: $isShowingSimpleAlert) { isPresented, detent in
DemoAlertView()
}
Expand All @@ -57,7 +58,7 @@ public struct AdaptiveSheetPreview: View {
isPresented.wrappedValue = false
}
}
.adaptiveSheet(isPresented: $isShowingExpandingList, options: AdaptiveOptions(adaptiveDetentLimit: 200, minimumFittingSize: CGSize(width: 500, height: 200))) { _, _ in
.adaptiveSheet(isPresented: $isShowingExpandingList, options: AdaptiveOptions(adaptiveDetentLimit: 500, minimumFittingSize: CGSize(width: 500, height: 200))) { _, _ in
DemoExpandingListView(count: $expandingListCount)
.safeAreaPadding(.bottom, 120)
} bottomPinnedContent: { isPresented, _ in
Expand Down

0 comments on commit 26fd579

Please sign in to comment.