diff --git a/Sources/BottomSheet/BottomSheetView/BottomSheetView.swift b/Sources/BottomSheet/BottomSheetView/BottomSheetView.swift index 4fa54df34..fa02d2dcc 100644 --- a/Sources/BottomSheet/BottomSheetView/BottomSheetView.swift +++ b/Sources/BottomSheet/BottomSheetView/BottomSheetView.swift @@ -105,8 +105,6 @@ internal struct BottomSheetView: View { // Make the GeometryReader ignore specific safe area (for transition to work) // On iPhone and iPad not floating ignore bottom safe area, because the BottomSheet moves to the bottom edge // On iPad floating and Mac ignore top safe area, because the BottomSheet moves to the top edge - .edgesIgnoringSafeArea( - self.isIPadFloatingOrMac ? .top : .bottom - ) + .ignoresSafeAreaCompatible(.container, edges: self.isIPadFloatingOrMac ? .top : .bottom) } } diff --git a/Sources/BottomSheet/Helper/Extensions/ViewExtension.swift b/Sources/BottomSheet/Helper/Extensions/ViewExtension.swift new file mode 100644 index 000000000..3b34e04be --- /dev/null +++ b/Sources/BottomSheet/Helper/Extensions/ViewExtension.swift @@ -0,0 +1,38 @@ +// +// ViewExtension.swift +// +// +// Created by Chocoford on 2023/6/16. +// + +import SwiftUI + +enum SafeAreaRegionsCompatible { + case all + case container + case keyboard + + @available(iOS 14.0, macOS 11.0, *) + var safeAreaRegions: SafeAreaRegions { + switch self { + case .all: + return .all + case .container: + return .container + case .keyboard: + return .keyboard + } + } +} + +internal extension View { + @ViewBuilder + func ignoresSafeAreaCompatible(_ regions: SafeAreaRegionsCompatible = .all, + edges: Edge.Set = .all) -> some View { + if #available(iOS 14.0, macOS 11.0, *) { + ignoresSafeArea(regions.safeAreaRegions, edges: edges) + } else { + edgesIgnoringSafeArea(edges) + } + } +}