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

Add SwiftUI Support for Button #1960

Closed
wants to merge 8 commits into from

Conversation

imthath-m
Copy link
Contributor

@imthath-m imthath-m commented Jan 28, 2024

Platforms Impacted

  • iOS
  • macOS

Description of changes

Added a new FluentButtonStyle which confirms to SwiftUI.ButtonStyle. This makes it easy to apply fluent styles to any button in SwiftUI.

The behaviour of styles in SwiftUI is slightly different from how we work with custom components in UIKit. Hence, this new FluentButtonStyle does not affect the content inside the button, which can be text, image or both. We can create a separate custom SwiftUI view to mimic the behaviour of the custom UIKit button with regards to images and text.

Binary change

Total increase: 1,50,920 bytes
Total decrease: -920 bytes

File Before After Delta
Total 3,11,49,392 bytes 3,12,99,392 bytes 🛑 1,50,000 bytes
Full breakdown
File Before After Delta
FluentButtonStyle.o 0 bytes 1,27,096 bytes 🛑 1,27,096 bytes
__.SYMDEF 48,86,280 bytes 49,08,664 bytes ⚠️ 22,384 bytes
FocusRingView.o 8,23,392 bytes 8,24,832 bytes ⚠️ 1,440 bytes
Button.o 2,12,528 bytes 2,12,280 bytes 🎉 -248 bytes
ListActionItem.o 2,25,496 bytes 2,24,824 bytes 🎉 -672 bytes

Verification

Compared existing buttons in UIKit with SwiftUI. Looks similar.

Visual Verification
Before After
Screenshot or description before this change Screenshot or description with this change

Pull request checklist

This PR has considered:

  • Light and Dark appearances
  • 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)
  • 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 imthath-m requested a review from a team as a code owner January 28, 2024 08:05
@imthath-m imthath-m marked this pull request as draft January 28, 2024 08:05
@imthath-m imthath-m force-pushed the swiftui-button branch 2 times, most recently from 09b2a97 to 4b72ae8 Compare January 29, 2024 18:11
@imthath-m imthath-m marked this pull request as ready for review January 30, 2024 12:32
@imthath-m
Copy link
Contributor Author

I am not able to test how the UIKit button responds to keyboard interactions in iPad. I tried but couldn't get control to reach this delegate method and see how it behaves.

So I've not implemented the focus ring view in the new FluentButtonStyle. Would be helpful if anyone can point out what I am missing with regards to focus behaviour.

@imthath-m imthath-m changed the title [Draft] Add SwiftUI Support for Button Add SwiftUI Support for Button Jan 31, 2024
@mischreiber
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants