Skip to content

Commit

Permalink
fix: Feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu-dgl committed Oct 29, 2024
1 parent c41e96e commit ea58adf
Showing 1 changed file with 10 additions and 63 deletions.
73 changes: 10 additions & 63 deletions Sources/InfomaniakCoreSwiftUI/Modifiers/FloatingPanelHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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<Backport.PresentationDetent> = [.medium]

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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<PresentationDetent> = [.height(0)]
@State private var selection: PresentationDetent = .height(0)
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
}

0 comments on commit ea58adf

Please sign in to comment.