From ea58adf899b2bfc26e7a475e956c98774f88b163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthieu=20D=C3=A9glon?= Date: Fri, 18 Oct 2024 09:53:09 +0200 Subject: [PATCH] fix: Feedbacks --- .../Modifiers/FloatingPanelHelper.swift | 73 +++---------------- 1 file changed, 10 insertions(+), 63 deletions(-) diff --git a/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift b/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift index cbe571a..3bb0031 100644 --- a/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift +++ b/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift @@ -30,11 +30,7 @@ public extension View { @ViewBuilder content: @escaping () -> Content ) -> some View { sheet(isPresented: isPresented) { - if UIDevice.current.userInterfaceIdiom == .pad { - if #available(iOS 16.0, *) { - content().modifier(SelfSizingPaneliPadViewModifier(title: title)) - } - } else if #available(iOS 16.0, *) { + if #available(iOS 16.0, *) { content().modifier(SelfSizingPanelViewModifier(title: title)) } else { content().modifier(SelfSizingPanelBackportViewModifier(title: title)) @@ -48,11 +44,7 @@ public extension View { @ViewBuilder content: @escaping (Item) -> Content ) -> some View { sheet(item: item) { item in - if UIDevice.current.userInterfaceIdiom == .pad { - if #available(iOS 16.0, *) { - content(item).modifier(SelfSizingPaneliPadViewModifier(title: title)) - } - } else if #available(iOS 16.0, *) { + if #available(iOS 16.0, *) { content(item).modifier(SelfSizingPanelViewModifier(title: title)) } else { content(item).modifier(SelfSizingPanelBackportViewModifier(title: title)) @@ -77,6 +69,7 @@ public struct SelfSizingPanelBackportViewModifier: ViewModifier { @LazyInjectService private var platformDetector: PlatformDetectable @Environment(\.dismiss) private var dismiss + @Environment(\.isCompactWindow) private var isCompactWindow @State private var currentDetents: Set = [.medium] @@ -105,7 +98,7 @@ public struct SelfSizingPanelBackportViewModifier: ViewModifier { } private var shouldShowCloseButton: Bool { - return platformDetector.isMac || (UIDevice.current.orientation.isLandscape && UIDevice.current.userInterfaceIdiom != .pad) + return !isCompactWindow || (UIDevice.current.orientation.isLandscape && UIDevice.current.userInterfaceIdiom != .pad) } private var shouldShowHeader: Bool { @@ -149,8 +142,8 @@ public struct SelfSizingPanelBackportViewModifier: ViewModifier { } } .padding(.top, topPadding) - .backport.presentationDragIndicator(backportDragIndicator) - .backport.presentationDetents(currentDetents) + .backport.presentationDragIndicator(isCompactWindow ? backportDragIndicator : .hidden) + .backport.presentationDetents(isCompactWindow ? currentDetents : [.large]) .ikPresentationCornerRadius(20) } } @@ -160,6 +153,7 @@ public struct SelfSizingPanelViewModifier: ViewModifier { @LazyInjectService private var platformDetector: PlatformDetectable @Environment(\.dismiss) private var dismiss + @Environment(\.isCompactWindow) private var isCompactWindow @State private var currentDetents: Set = [.height(0)] @State private var selection: PresentationDetent = .height(0) @@ -178,7 +172,7 @@ public struct SelfSizingPanelViewModifier: ViewModifier { } private var shouldShowCloseButton: Bool { - return platformDetector.isMac || (UIDevice.current.orientation.isLandscape && UIDevice.current.userInterfaceIdiom != .pad) + return !isCompactWindow || (UIDevice.current.orientation.isLandscape && UIDevice.current.userInterfaceIdiom != .pad) } private var shouldShowHeader: Bool { @@ -229,55 +223,8 @@ public struct SelfSizingPanelViewModifier: ViewModifier { } } .padding(.top, topPadding) - .presentationDetents(currentDetents, selection: $selection) - .presentationDragIndicator(dragIndicator) - .ikPresentationCornerRadius(20) - } -} - -@available(iOS 16.0, *) -public struct SelfSizingPaneliPadViewModifier: ViewModifier { - @Environment(\.dismiss) private var dismiss - - @State private var selection: PresentationDetent = .fraction(0.5) - - let dragIndicator: Visibility - let title: String? - - private let topPadding = IKPadding.large - private let titleSpacing = IKPadding.small - - private var headerSize: CGFloat { - guard title != nil else { - return topPadding - } - return topPadding + titleSpacing + UIFont.preferredFont(forTextStyle: .headline).pointSize - } - - public init(dragIndicator: Visibility = Visibility.hidden, title: String? = nil) { - self.dragIndicator = dragIndicator - self.title = title - } - - public func body(content: Content) -> some View { - VStack(spacing: titleSpacing) { - ZStack { - if let title { - Text(title) - .font(Font(UIFont.preferredFont(forTextStyle: .headline))) - } - FloatingPanelCloseButton(size: .medium, dismissAction: dismiss) - .frame(maxWidth: .infinity, alignment: .trailing) - .padding(.trailing, value: .medium) - } - - ScrollView { - content - .padding(.bottom, value: .medium) - } - } - .padding(.top, topPadding) - .presentationDragIndicator(dragIndicator) + .presentationDetents(isCompactWindow ? currentDetents : [.large], selection: $selection) + .presentationDragIndicator(isCompactWindow ? dragIndicator : .hidden) .ikPresentationCornerRadius(20) } }