SwiftUI View Extension: Improve pointer interaction
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
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.
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)