From aae7d924d63bc96e7b038612b79cf23eec372b5b Mon Sep 17 00:00:00 2001 From: Mohammed Imthathullah Date: Tue, 30 Jan 2024 12:39:16 +0530 Subject: [PATCH] SwiftUI View Extension: Improve pointer interaction Avoiding AnyView because it erases the identity of the View and can cause performance issues --- ios/FluentUI/Core/SwiftUI+ViewModifiers.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ios/FluentUI/Core/SwiftUI+ViewModifiers.swift b/ios/FluentUI/Core/SwiftUI+ViewModifiers.swift index a61d5d43c8..670a3141cf 100644 --- a/ios/FluentUI/Core/SwiftUI+ViewModifiers.swift +++ b/ios/FluentUI/Core/SwiftUI+ViewModifiers.swift @@ -24,12 +24,14 @@ extension View { /// Enables iPad Pointer interaction for the view if available. /// - Parameter isEnabled: Whether the pointer interaction should be enabled. /// - Returns: The modified view. - func pointerInteraction(_ isEnabled: Bool) -> AnyView { - if isEnabled { - return AnyView(self.hoverEffect()) + @ViewBuilder func pointerInteraction(_ isEnabled: Bool) -> some View { + if #available(iOS 17.0, *) { + hoverEffect(isEnabled: isEnabled) + } else if isEnabled { + hoverEffect() + } else { + self } - - return AnyView(self) } /// Measures the size of a view, monitors when its size is updated, and takes a closure to be called when it does