Skip to content

Commit b301004

Browse files
committed
SwiftUI View Extension: Improve pointer interaction
Avoiding AnyView because it erases the identity of the View and can cause performance issues
1 parent 5e902ab commit b301004

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

ios/FluentUI/Core/SwiftUI+ViewModifiers.swift

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ extension View {
2424
/// Enables iPad Pointer interaction for the view if available.
2525
/// - Parameter isEnabled: Whether the pointer interaction should be enabled.
2626
/// - Returns: The modified view.
27-
func pointerInteraction(_ isEnabled: Bool) -> AnyView {
28-
if isEnabled {
29-
return AnyView(self.hoverEffect())
27+
@ViewBuilder func pointerInteraction(_ isEnabled: Bool) -> some View {
28+
if #available(iOS 17.0, *) {
29+
hoverEffect(isEnabled: isEnabled)
30+
} else if isEnabled {
31+
hoverEffect()
32+
} else {
33+
self
3034
}
31-
32-
return AnyView(self)
3335
}
3436

3537
/// Measures the size of a view, monitors when its size is updated, and takes a closure to be called when it does

0 commit comments

Comments
 (0)