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 8 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).

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
convenience init(dynamicColor: DynamicColor) {
// Simple closure to return a nil NSColor if the passed-in Color is
// also nil, since the argument to `NSColor.init(_:)` is not optional.
let colorResolver = { $0 != nil ? NSColor($0!) : nil }
Copy link
Contributor

Choose a reason for hiding this comment

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

Since Optional includes support for .map() and .flatMap(), I wonder if you could remove this closure and instead do something like:

self.init(light: NSColor(dynamicColor.light),
          dark: dynamicColor.dark.map { NSColor($0) }

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)

@@ -40,15 +40,19 @@ extension Color {
///
/// - Parameter dynamicColor: A dynmic color structure that describes the `Color` to be created.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Not related to this PR, but there's a typo here. dynmic -> dynamic

import SwiftUI
import UIKit
Copy link
Contributor

Choose a reason for hiding this comment

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

A little surprised this didn't generate a lint warning. There's the sorted_imports rule for this, which you could opt into.

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.

4 participants