From 18fc9653b41d91c5125b044463e4042ab0d75a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthieu=20D=C3=A9glon?= Date: Fri, 18 Oct 2024 08:05:27 +0200 Subject: [PATCH 1/7] fix: Fix the size of floating panel just for iPad --- .../Modifiers/FloatingPanelHelper.swift | 59 ++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift b/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift index 5cc5c91..dc7d5cd 100644 --- a/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift +++ b/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift @@ -30,7 +30,11 @@ public extension View { @ViewBuilder content: @escaping () -> Content ) -> some View { sheet(isPresented: isPresented) { - if #available(iOS 16.0, *) { + if UIDevice.current.userInterfaceIdiom == .pad { + if #available(iOS 16.0, *) { + content().modifier(SelfSizingPaneliPadViewModifier(title: title)) + } + } else if #available(iOS 16.0, *) { content().modifier(SelfSizingPanelViewModifier(title: title)) } else { content().modifier(SelfSizingPanelBackportViewModifier(title: title)) @@ -44,7 +48,11 @@ public extension View { @ViewBuilder content: @escaping (Item) -> Content ) -> some View { sheet(item: item) { item in - if #available(iOS 16.0, *) { + if UIDevice.current.userInterfaceIdiom == .pad { + if #available(iOS 16.0, *) { + content(item).modifier(SelfSizingPaneliPadViewModifier(title: title)) + } + } else if #available(iOS 16.0, *) { content(item).modifier(SelfSizingPanelViewModifier(title: title)) } else { content(item).modifier(SelfSizingPanelBackportViewModifier(title: title)) @@ -226,3 +234,50 @@ public struct SelfSizingPanelViewModifier: ViewModifier { .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.visible, 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) + .ikPresentationCornerRadius(20) + } +} From c41e96ebccb329b196428ce23210d920d15e6fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthieu=20D=C3=A9glon?= Date: Fri, 18 Oct 2024 08:21:22 +0200 Subject: [PATCH 2/7] fix: Change visibility of drag indicator --- .../InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift b/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift index dc7d5cd..cbe571a 100644 --- a/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift +++ b/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift @@ -254,7 +254,7 @@ public struct SelfSizingPaneliPadViewModifier: ViewModifier { return topPadding + titleSpacing + UIFont.preferredFont(forTextStyle: .headline).pointSize } - public init(dragIndicator: Visibility = Visibility.visible, title: String? = nil) { + public init(dragIndicator: Visibility = Visibility.hidden, title: String? = nil) { self.dragIndicator = dragIndicator self.title = title } 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 3/7] 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) } } From 44d5410eefbc32021f74bbec8d7c5d0daff25e28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthieu=20D=C3=A9glon?= Date: Mon, 28 Oct 2024 08:52:25 +0100 Subject: [PATCH 4/7] refactor: Add early guard --- .../InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift b/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift index 3bb0031..89cfb8d 100644 --- a/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift +++ b/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift @@ -206,6 +206,7 @@ public struct SelfSizingPanelViewModifier: ViewModifier { .padding(.bottom, value: .medium) } .introspect(.scrollView, on: .iOS(.v16, .v17, .v18)) { scrollView in + guard selection != .height(headerSize) else { return } let totalPanelContentHeight = scrollView.contentSize.height + headerSize guard selection != .height(totalPanelContentHeight) else { return } From f7401fabd7a6b837fd40748a21e2f074ea2a13b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthieu=20D=C3=A9glon?= Date: Mon, 28 Oct 2024 14:04:20 +0100 Subject: [PATCH 5/7] refactor: Refactor var name and modify guard --- .../Modifiers/FloatingPanelHelper.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift b/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift index 89cfb8d..3f026f8 100644 --- a/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift +++ b/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift @@ -97,12 +97,12 @@ public struct SelfSizingPanelBackportViewModifier: ViewModifier { return topPadding + titleSpacing + UIFont.preferredFont(forTextStyle: .headline).pointSize } - private var shouldShowCloseButton: Bool { + private var isCompactMode: Bool { return !isCompactWindow || (UIDevice.current.orientation.isLandscape && UIDevice.current.userInterfaceIdiom != .pad) } private var shouldShowHeader: Bool { - return title != nil || shouldShowCloseButton + return title != nil || isCompactMode } public init(dragIndicator: Visibility = Visibility.visible, title: String? = nil) { @@ -119,7 +119,7 @@ public struct SelfSizingPanelBackportViewModifier: ViewModifier { .font(Font(UIFont.preferredFont(forTextStyle: .headline))) } - if shouldShowCloseButton { + if isCompactMode { FloatingPanelCloseButton(size: .medium, dismissAction: dismiss) .frame(maxWidth: .infinity, alignment: .trailing) .padding(.trailing, value: .medium) @@ -171,12 +171,12 @@ public struct SelfSizingPanelViewModifier: ViewModifier { return topPadding + titleSpacing + UIFont.preferredFont(forTextStyle: .headline).pointSize } - private var shouldShowCloseButton: Bool { + private var isCompactMode: Bool { return !isCompactWindow || (UIDevice.current.orientation.isLandscape && UIDevice.current.userInterfaceIdiom != .pad) } private var shouldShowHeader: Bool { - return title != nil || shouldShowCloseButton + return title != nil || isCompactMode } public init(dragIndicator: Visibility = Visibility.visible, title: String? = nil) { @@ -193,7 +193,7 @@ public struct SelfSizingPanelViewModifier: ViewModifier { .font(Font(UIFont.preferredFont(forTextStyle: .headline))) } - if shouldShowCloseButton { + if isCompactMode { FloatingPanelCloseButton(size: .medium, dismissAction: dismiss) .frame(maxWidth: .infinity, alignment: .trailing) .padding(.trailing, value: .medium) @@ -206,7 +206,7 @@ public struct SelfSizingPanelViewModifier: ViewModifier { .padding(.bottom, value: .medium) } .introspect(.scrollView, on: .iOS(.v16, .v17, .v18)) { scrollView in - guard selection != .height(headerSize) else { return } + guard isCompactMode else { return } let totalPanelContentHeight = scrollView.contentSize.height + headerSize guard selection != .height(totalPanelContentHeight) else { return } From 6e2de073688f6c00a58d629d476daa2f08d54dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthieu=20D=C3=A9glon?= Date: Thu, 7 Nov 2024 14:24:55 +0100 Subject: [PATCH 6/7] fix: Feedbacks --- .../Modifiers/FloatingPanelHelper.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift b/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift index 3f026f8..fb7f21c 100644 --- a/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift +++ b/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift @@ -121,7 +121,7 @@ public struct SelfSizingPanelBackportViewModifier: ViewModifier { if isCompactMode { FloatingPanelCloseButton(size: .medium, dismissAction: dismiss) - .frame(maxWidth: .infinity, alignment: .trailing) + .frame(maxWidth: .infinity, alignment: .leading) .padding(.trailing, value: .medium) } } @@ -132,7 +132,8 @@ public struct SelfSizingPanelBackportViewModifier: ViewModifier { .padding(.bottom, value: .medium) } .introspect(.scrollView, on: .iOS(.v15)) { scrollView in - guard !currentDetents.contains(.large) else { return } + guard isCompactMode, !currentDetents.contains(.large) else { return } + let totalPanelContentHeight = scrollView.contentSize.height + headerSize scrollView.isScrollEnabled = totalPanelContentHeight > (scrollView.window?.bounds.height ?? 0) @@ -195,7 +196,7 @@ public struct SelfSizingPanelViewModifier: ViewModifier { if isCompactMode { FloatingPanelCloseButton(size: .medium, dismissAction: dismiss) - .frame(maxWidth: .infinity, alignment: .trailing) + .frame(maxWidth: .infinity, alignment: .leading) .padding(.trailing, value: .medium) } } From c3580f49889c2351535172e060eca051ef48d8d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthieu=20D=C3=A9glon?= Date: Thu, 7 Nov 2024 14:34:48 +0100 Subject: [PATCH 7/7] fix: Leading padding --- .../InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift b/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift index fb7f21c..2828e41 100644 --- a/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift +++ b/Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift @@ -122,7 +122,7 @@ public struct SelfSizingPanelBackportViewModifier: ViewModifier { if isCompactMode { FloatingPanelCloseButton(size: .medium, dismissAction: dismiss) .frame(maxWidth: .infinity, alignment: .leading) - .padding(.trailing, value: .medium) + .padding(.leading, value: .medium) } } } @@ -197,7 +197,7 @@ public struct SelfSizingPanelViewModifier: ViewModifier { if isCompactMode { FloatingPanelCloseButton(size: .medium, dismissAction: dismiss) .frame(maxWidth: .infinity, alignment: .leading) - .padding(.trailing, value: .medium) + .padding(.leading, value: .medium) } } }