Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

df/FloatingPanelEnhancements #108

Merged
merged 40 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
bdb639d
Start
dfeinzimer Jul 29, 2022
60c5839
Progress
dfeinzimer Jul 29, 2022
f5952d8
Progress
dfeinzimer Jul 29, 2022
934595d
Progress
dfeinzimer Jul 29, 2022
1f34502
Update FloatingPanel.swift
dfeinzimer Jul 29, 2022
1c28a80
Progress
dfeinzimer Jul 29, 2022
61e27e7
Progress
dfeinzimer Jul 29, 2022
2bd0f95
Progress
dfeinzimer Jul 29, 2022
1647d8f
Update FloatingPanel.swift
dfeinzimer Jul 29, 2022
100febb
Update FloatingPanel.swift
dfeinzimer Jul 29, 2022
d94f9c7
Progress
dfeinzimer Jul 29, 2022
687e398
Progress
dfeinzimer Jul 29, 2022
5b775ae
Merge in latest
dfeinzimer Jul 29, 2022
2ef0f50
Default detent
dfeinzimer Jul 29, 2022
0c04f28
Progress
dfeinzimer Jul 30, 2022
0cf61b2
Add doc
dfeinzimer Jul 30, 2022
51950f3
Finish doc
dfeinzimer Jul 30, 2022
8143f08
Update FloatingPanelModifier.swift
dfeinzimer Aug 1, 2022
07a39de
Update FloatingPanel.swift
dfeinzimer Aug 1, 2022
4d6de42
Update FloatingPanel.swift
dfeinzimer Aug 1, 2022
6ff6195
Add doc
dfeinzimer Aug 1, 2022
8216d5a
Merge latest
dfeinzimer Aug 3, 2022
902f796
Add padding to content bottom in compact envs
dfeinzimer Aug 3, 2022
060d0f5
Address hidden handle
dfeinzimer Aug 4, 2022
07cff79
Simplification
dfeinzimer Aug 5, 2022
bce92eb
Update FloatingPanel.swift
dfeinzimer Aug 5, 2022
f83b293
Merge latest
dfeinzimer Aug 8, 2022
268bd8d
Merge branch 'v.next' into df/FloatingPanelEnhancements
dfeinzimer Aug 8, 2022
63a44ff
Merge in latest
dfeinzimer Aug 10, 2022
6fc4d81
Merge branch 'v.next' into df/FloatingPanelEnhancements
dfeinzimer Aug 11, 2022
ebfb7ea
Merge branch 'v.next' into df/FloatingPanelEnhancements
dfeinzimer Aug 18, 2022
1af0791
Merge branch 'v.next' into df/FloatingPanelEnhancements
dfeinzimer Aug 22, 2022
6d0175c
`makeHandleArea` -> `makeHandleView`
dfeinzimer Aug 22, 2022
5352247
Doc simplification
dfeinzimer Aug 22, 2022
c75e7e3
Update FloatingPanel.swift
dfeinzimer Aug 22, 2022
2b82038
Doc updates
dfeinzimer Aug 22, 2022
d695cbb
Update FloatingPanelDetent.swift
dfeinzimer Aug 22, 2022
efe7102
Update FloatingPanel.swift
dfeinzimer Aug 22, 2022
9c76d72
Remove deprecated method
dfeinzimer Aug 22, 2022
77e6867
Move padding location
dfeinzimer Aug 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Progress
  • Loading branch information
dfeinzimer committed Jul 29, 2022
commit 61e27e79974c16e03f6078eb650f7285d4213743
34 changes: 15 additions & 19 deletions Sources/ArcGISToolkit/Components/FloatingPanel/FloatingPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,25 @@ import SwiftUI
/// dedicated search panel. They will also be primarily simple containers
/// that clients will fill with their own content.
struct FloatingPanel<Content>: View where Content: View {
// Note: instead of the FloatingPanel being a view, it might be preferable
// to have it be a view modifier, similar to how SwiftUI doesn't have a
// SheetView, but a modifier that presents a sheet.

@Environment(\.horizontalSizeClass) private var horizontalSizeClass

/// The content shown in the floating panel.
let content: Content

/// Creates a `FloatingPanel`
dfeinzimer marked this conversation as resolved.
Show resolved Hide resolved
/// - Parameter content: The view shown in the floating panel.
/// - Parameter detent: <#detent description#>
/// - Parameter detent: Controls the height of the panel.
init(
detent: Binding<FloatingPanelDetent>,
@ViewBuilder content: () -> Content
) {
self.content = content()
_detent = detent
_activeDetent = detent
}

/// The detent that is currently set.
@Binding private var activeDetent: FloatingPanelDetent

/// The color of the handle.
@State private var handleColor: Color = .defaultHandleColor

Expand All @@ -53,9 +52,6 @@ struct FloatingPanel<Content>: View where Content: View {
/// The maximum allowed height of the content.
@State private var maximumHeight: CGFloat = .infinity

/// <#Description#>
@Binding var detent: FloatingPanelDetent

/// A Boolean value indicating whether the panel should be configured for a compact environment.
private var isCompact: Bool {
horizontalSizeClass == .compact
Expand Down Expand Up @@ -94,14 +90,14 @@ struct FloatingPanel<Content>: View where Content: View {
height = maximumHeight
}
}
.onChange(of: detent) { newValue in
.onChange(of: activeDetent) { _ in
withAnimation {
height = heightWithDetent
height = heightFor(detent: activeDetent)
}
}
.onAppear {
withAnimation {
height = heightWithDetent
height = heightFor(detent: activeDetent)
}
}
}
Expand Down Expand Up @@ -133,12 +129,17 @@ struct FloatingPanel<Content>: View where Content: View {
}
}

/// The detent that would produce a height that is closest to the current height
dfeinzimer marked this conversation as resolved.
Show resolved Hide resolved
var closestDetent: FloatingPanelDetent {
return FloatingPanelDetent.allCases.min { d1, d2 in
abs(heightFor(detent: d1) - height) < abs(heightFor(detent: d2) - height)
let choices: [FloatingPanelDetent] = [.oneQuarter, .half, .threeQuarters]
return choices.min {
abs(heightFor(detent: $0) - height) <
abs(heightFor(detent: $1) - height)
} ?? .half
}

/// - Parameter detent: The detent to use when calculating height
/// - Returns: A height for the provided detent based on the current maximum height
dfeinzimer marked this conversation as resolved.
Show resolved Hide resolved
func heightFor(detent: FloatingPanelDetent) -> CGFloat {
switch detent {
case .min:
Expand All @@ -153,11 +154,6 @@ struct FloatingPanel<Content>: View where Content: View {
return maximumHeight
}
}

/// - Returns: Displayable height given the current detent
var heightWithDetent: CGFloat {
return heightFor(detent: detent)
}
}

/// The "Handle" view of the floating panel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

import Foundation

/// <#Description#>
public enum FloatingPanelDetent: CaseIterable {
/// A value that represents a height where a sheet naturally rests.
public enum FloatingPanelDetent {
case min
case oneQuarter
case half
Expand Down