fluentui-apple icon indicating copy to clipboard operation
fluentui-apple copied to clipboard

SwiftUI View Extension: Improve pointer interaction

Open imthath-m opened this issue 2 years ago โ€ข 2 comments

Avoiding AnyView because it erases the identity of the View and can cause performance issues

Platforms Impacted

  • [x] iOS
  • [ ] macOS

Description of changes

Avoiding AnyView because it erases the identity of the View and causes performance issues. Using new hoverEffect(_:) modifier which accepts a boolean in iOS 17+.

Binary change

Total increase: 3,74,192 bytes Total decrease: 0 bytes

File Before After Delta
Total 3,11,49,392 bytes 3,15,23,584 bytes โ›”๏ธ 3,74,192 bytes

I don't fully understand how such a small changes causes 350kb difference.

Full breakdown
File Before After Delta
IndeterminateProgressBar.o 2,33,984 bytes 3,65,752 bytes ๐Ÿ›‘ 1,31,768 bytes
__.SYMDEF 48,86,280 bytes 50,12,696 bytes ๐Ÿ›‘ 1,26,416 bytes
Avatar.o 6,02,160 bytes 7,18,152 bytes ๐Ÿ›‘ 1,15,992 bytes
SwiftUI+ViewModifiers.o 1,36,096 bytes 1,36,112 bytes โš ๏ธ 16 bytes

Verification

https://github.com/microsoft/fluentui-apple/assets/46041492/593fdbc1-ff69-42ee-93a5-66ed29130ad9

Tested on the Avatar SwiftUI demo, the iPad pointer interaction works as before.

No Visual Change.

Pull request checklist

This PR has considered:

  • [ ] Light and Dark appearances
  • [x] iOS supported versions (all major versions greater than or equal current target deployment version)
  • [ ] VoiceOver and Keyboard Accessibility
  • [ ] Internationalization and Right to Left layouts
  • [ ] Different resolutions (1x, 2x, 3x)
  • [ ] Size classes and window sizes (iPhone vs iPad, notched devices, multitasking, different window sizes, etc)
  • [x] iPad Pointer interaction
  • [ ] SwiftUI consumption (validation or new demo scenarios needed)
  • [ ] Objective-C exposure (provide it only if needed)
Microsoft Reviewers: Open in CodeFlow

imthath-m avatar Jan 30 '24 12:01 imthath-m

You can find info about performance issues because of AnyView in this article. This article references related developer docs and WWDC videos as well.

The only place where it is currently exposed from FluentUI is when we use Avatar(_:_:).hasPointerInteraction(true). The more SwiftUI components FluentUI supports, this will be exposed from different places and could cause more issues. I noticed it while working on the SwiftUI button here #1960.

imthath-m avatar Jan 31 '24 02:01 imthath-m

Out of curiosity, can you also run the process under Step 9 of the Size Comparison wiki and post your results too? Size Comparison ยท microsoft/fluentui-apple Wiki (github.com)

mischreiber avatar Feb 10 '24 00:02 mischreiber