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

Remove onSizeChange in favor of new native APIs #989

Open
wants to merge 9 commits into
base: v.next
Choose a base branch
from
25 changes: 22 additions & 3 deletions Sources/ArcGISToolkit/Components/FloorFilter/LevelSelector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,38 @@ extension LevelSelector {
/// A scrollable list of buttons; one for each level to be displayed.
/// - Returns: The scrollable list of level buttons.
@ViewBuilder func makeLevelButtons() -> some View {
ScrollViewReader { proxy in
let scrollView = ScrollViewReader { proxy in
ScrollView {
VStack(spacing: 4) {
let list = VStack(spacing: 4) {
ForEach(filteredLevels, id: \.id) { level in
makeLevelButton(level)
}
}
.onSizeChange { contentHeight = $0.height }
if #available (iOS 18.0, *) {
list
} else {
list
.onGeometryChange(for: CGFloat.self) { proxy in
proxy.frame(in: .global).height
} action: { newHeight in
contentHeight = newHeight
}
}
}
.frame(maxHeight: contentHeight)
.onAppear { scrollToSelectedLevel(with: proxy) }
.onChange(isCollapsed) { _ in scrollToSelectedLevel(with: proxy) }
}
if #available (iOS 18.0, *) {
scrollView
.onScrollGeometryChange(for: CGFloat.self) { geometry in
geometry.contentSize.height
} action: { _, newValue in
contentHeight = newValue
}
} else {
scrollView
}
}

/// Determines a appropriate color for a button in the floor level list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ struct MediaPopupElementView: View {
}
}
}
.onSizeChange {
width = $0.width * widthScaleFactor
.onGeometryChange(for: CGFloat.self) { proxy in
proxy.frame(in: .global).width
} action: { newValue in
width = newValue * widthScaleFactor
}
}

Expand Down
6 changes: 4 additions & 2 deletions Sources/ArcGISToolkit/Components/Scalebar/Scalebar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ public struct Scalebar: View {
}
}
}
.onSizeChange {
height = $0.height
.onGeometryChange(for: CGFloat.self) { proxy in
proxy.frame(in: .global).height
} action: { newValue in
height = newValue
}
.frame(
width: $viewModel.displayLength.wrappedValue,
Expand Down
16 changes: 0 additions & 16 deletions Sources/ArcGISToolkit/Extensions/SwiftUI/View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,6 @@ extension View {
modifier(KeyboardStateChangedModifier(action: action))
}

/// Returns a new `View` that allows a parent `View` to be informed of a child view's size.
/// - Parameter perform: The closure to be executed when the content size of the receiver
/// changes.
/// - Returns: A new `View`.
func onSizeChange(perform: @escaping (CGSize) -> Void) -> some View {
background(
GeometryReader { geometry in
Color.clear
.preference(
key: SizePreferenceKey.self, value: geometry.size
)
}
)
.onPreferenceChange(SizePreferenceKey.self, perform: perform)
}

/// Adds an equal padding amount to the horizontal edges of this view if the target environment
/// is Mac Catalyst.
/// - Parameter length: An amount, given in points, to pad this view on the horizontal edges.
Expand Down
21 changes: 0 additions & 21 deletions Sources/ArcGISToolkit/Utility/SizePreferenceKey.swift

This file was deleted.