@@ -52,9 +52,10 @@ struct FloatingPanel<Content>: View where Content: View {
52
52
/// The maximum allowed height of the content.
53
53
@State private var maximumHeight : CGFloat = . zero
54
54
55
- /// The detent that was the active detent until a FloatingPanelDetentPreference was set .
55
+ /// Stores the detent that was active before a `FloatingPanelDetent.Preference` was applied .
56
56
///
57
- /// When the FloatingPanelDetentPreference is unset, this detent should be restored to the active detent..
57
+ /// This value allows the panel to restore the previous state when the preference is cleared.
58
+ /// It is only set when a new preference is first applied and cleared when the preference is removed.
58
59
@State private var overriddenDetent : FloatingPanelDetent ?
59
60
60
61
var body : some View {
@@ -71,18 +72,16 @@ struct FloatingPanel<Content>: View where Content: View {
71
72
. clipped ( )
72
73
. onPreferenceChange ( FloatingPanelDetent . Preference. self) { preference in
73
74
if let preference {
74
- // Only update the overridden detent if one
75
- // wasn't already saved. This prevents a
76
- // FloatingPanelDetentPreference from being
77
- // saved as the overridden detent.
75
+ // Only set the overridden detent if it's `nil`.
76
+ // This prevents a preference from being saved
77
+ // as the overridden detent.
78
78
if overriddenDetent == nil {
79
79
overriddenDetent = activeDetent
80
80
}
81
81
activeDetent = preference
82
82
} else if let overriddenDetent {
83
- // When the FloatingPanelDetentPreference is
84
- // unset, restore the overridden detent as the
85
- // active detent.
83
+ // When the preference is unset, restore the
84
+ // overridden detent as the active detent.
86
85
activeDetent = overriddenDetent
87
86
self . overriddenDetent = nil
88
87
}
0 commit comments