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

Move FluentTheme code to new FluentUI_common module #2139

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

mischreiber
Copy link
Contributor

@mischreiber mischreiber commented Mar 7, 2025

Platforms Impacted

  • iOS
  • visionOS
  • macOS

Description of changes

This PR lights up FluentTheme and various other low-level Fluent utilities on macOS by moving them to a new cross-platform module, FluentUI_common. To walk through the changes, I've split the diff into four commits.

320e374: Create FluentUI_common target

  • Nice and easy: updating Package.swift to specify a new build target, FluentUI_common.
  • Updating both FluentUI_macos and FluentUI_ios to depend on this new target.

e6b2370: Move common files to FluentUI_common directory

  • This moves many FluentTheme- and token-related files to the new FluentUI_common directory, with almost no changes.
  • First exception to this is Color+Extensions.swift, which hooks into the new macOS-specific DynamicColor integration found in NSColor+Extensions.swift.
  • Second exception is FluentUI.swift, which now also exports FluentUI_common in addition to the platform-specific module. This means users can continue to simply import FluentUI and get the code they expect.

069ec24: Add import FluentUI_common to iOS files

  • This is a big commit, but nothing interesting is happening.
  • I've just added import FluentUI_common to every remaining file in FluentUI_ios, now that so much of the support structure of Fluent iOS has been moved to that library.

1e07c89: Add import FluentUI_common to tests

  • Same for tests :)

Binary change

TBA, will be testing the built app to see impact.

Verification

Ran all automation on both iOS and macOS, and got the same level of success as before my change (there are some failing Notification tests that we should fix later).

Also added a direct FluentTheme reference in the new FluentUI demo app, demonstrating the ability to access Fluent colors from macOS.

Before After
before after
before_dark after_dark

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

@mischreiber mischreiber requested review from a team as code owners March 7, 2025 23:48
self.init(dynamicColor)
} else {
#if os(macOS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a good excuse to rename Color+Extensions.swift to something more descriptive and then introduce something like DynamicColor+UIKit and DynamicColor+AppKit (or similar names)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the appeal, but two reasons I'm inclined to keep the current names for now:

  1. Color+Extensions.swift isn't purely based around DynamicColor; it also adds Color.init(hexValue:). In fact, the public API is half and half, and doesn't even mention DynamicColor at all.
  2. Our convention in Fluent is to name extension files after the class they're extending. Since the files in question extend Color, NSColor, and UIColor, they should all be named [Color|NSColor|UIColor]+Something.swift. We could change the +Something part, but we run into the same problem that there are multiple kinds of additions to each class, not just DynamicColor.

@@ -3,8 +3,8 @@
// Licensed under the MIT License.
//

#if canImport(UIKit)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed? Or can we just make this file not compile for macOS?

@@ -6,30 +6,31 @@
import SwiftUI

/// A container that stores a dynamic set of `Color` values.
struct DynamicColor: Hashable {
@objc(MSFDynamicColor)
public final class DynamicColor: NSObject {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That a bunch of stuff (well actually not that much, but not zero) now has to be exposed publicly when it wasn't before makes me second guess myself. There's no way to share code selectively across platforms with use of path includes/excludes in Package.swift/MicrosoftFluentUI.podspec?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, is it actually gross to do this without introducing a new module?

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.

5 participants