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

Views don’t default to native attributes #22665

Closed
breyed opened this issue May 27, 2024 · 6 comments
Closed

Views don’t default to native attributes #22665

breyed opened this issue May 27, 2024 · 6 comments
Labels
area-theme Themes, theming platform/iOS 🍎 s/needs-info Issue needs more info from the author t/bug Something isn't working

Comments

@breyed
Copy link
Contributor

breyed commented May 27, 2024

Description

Even though MAUI builds off a long tradition of “build a native UI”, by default its views differ from native platform views. MAUI should not override the platform defaults, but instead let the platform render them natively if not overridden by user code.

For example, when no style or attribute is applied to the color of a Label, Button, or other view, the platform’s native colors are not used. It’s as if something at startup is setting the colors to non-native defaults. The same applies to other attributes such as size and padding.

Internally, the attributes should default to no value, which should tell the handlers not set a value on the platform view. If a getter is called on a property such as color, its value should be read from the native platform.

Steps to Reproduce

  1. Create a MAUI app and a SwiftUI app from the dotnet new and Xcode templates.
  2. Remove the styles from the MAUI template.
  3. Create buttons on each app with blocky text for easy comparison.
  4. Run each app and note the differences.
<Button Text="⬛︎⬛︎⬛︎⬛︎⬛︎ Enabled XAML ⬛︎⬛︎⬛︎⬛︎⬛︎⬛︎" />
<Button Text="⬛︎⬛︎⬛︎⬛︎⬛︎ Disabled XAML ⬛︎⬛︎⬛︎⬛︎⬛︎⬛︎" IsEnabled="False" />
Button("⬛︎⬛︎⬛︎⬛︎⬛︎ Enabled SwiftUI ⬛︎⬛︎⬛︎⬛︎⬛︎⬛︎") {}
Button("⬛︎⬛︎⬛︎⬛︎⬛︎ Disabled SwiftUI ⬛︎⬛︎⬛︎⬛︎⬛︎⬛︎") {}.disabled(true)
image image image image
Tool Light Enabled Light Disabled Dark Enabled Dark Disabled
XAML #007AFF #C4C4C4 #0A84FF #2E2E2E
SwiftUI #007AFF #C5C5C7 #0A84FF #464649

Link to public reproduction project repository

No response

Version with bug

8.0.40 SR5

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

Tested on iOS 17. Likely affects all platforms and versions.

Did you find any workaround?

You’d could create the styles yourself and then aligned with platform changes, in theory including variants for downlevel native defaults. Alternatively, you could create custom startup code to query the platform’s native defaults and creating styles accordingly.

Relevant log output

No response

@breyed breyed added the t/bug Something isn't working label May 27, 2024
Copy link
Contributor

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@breyed
Copy link
Contributor Author

breyed commented May 27, 2024

This issue is similar to #17414. The other issue lists Windows as the affected platform and gives an example of a Windows corner radius. This issue lists all platforms as likely affected and gives examples of iOS font size and color.

@mattleibow
Copy link
Member

Are you able to test with Xcode and Objective C? I think the Swift UI styles are not the default styles but rather the new Swift UI team's implementation of the default styles.

@mattleibow mattleibow added the s/needs-info Issue needs more info from the author label May 27, 2024
Copy link
Contributor

Hi @breyed. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@breyed
Copy link
Contributor Author

breyed commented May 27, 2024

I created a new app in Xcode using Storyboard (UIKit) for the interface. I added to the storyboard enabled and disabled buttons, leaving all attributes at their defaults. I did this with both Swift and Objective C. Regardless of the language, the colors are identical to the SwiftUI app’s colors.

iOS 13 added support for both dark mode and SwiftUI. With dark mode support, Apple added colors that vary based on light/dark mode. SwiftUI and UIKit both tap into those.

Having thought through that, I changed SupportedOSPlatformVersion in the MAUI app to 13.0. That fixed the problem. The MAUI colors and sizes now match that of XAML. XAML does add some padding around the buttons, but that appears to be intentional to cause buttons to lay out similarly between platforms. Actually, SupportedOSPlatformVersion had no effect. I had forgotten that I had added styling code to my test app to emulate the native color and size.

@drasticactions
Copy link
Contributor

https://github.com/drasticactions/MauiRepros/tree/main/AppleColors

I wrote four test apps: One in SwiftUI, One in Swift/UIKit, One in MAUI, One with .NET iOS directly with no MAUI UI Toolkit. These screenshots were taken with the iPhone 15 Pro simulator.

Simulator Screenshot - iPhone 15 Pro - 2024-05-28 at 16 46 02

Simulator Screenshot - iPhone 15 Pro - 2024-05-28 at 16 45 18

Simulator Screenshot - iPhone 15 Pro - 2024-05-28 at 16 41 10

Simulator Screenshot - iPhone 15 Pro - 2024-05-28 at 16 47 23

If you compare the Swift app with Swift UI one, you'll have the same Hex values for the colors. Likewise with Dark mode.

Simulator Screenshot - iPhone 15 Pro - 2024-05-28 at 16 55 38

Simulator Screenshot - iPhone 15 Pro - 2024-05-28 at 16 56 00

The Swift (Non SwiftUI) colors match up with the XAML values, and the .NET iOS C# ones. Likewise with font sizes. If you want to compare the defaults in UIKit with what's in MAUI, IMO, your best bet is not using SwiftUI to do it.

@mattleibow mattleibow closed this as not planned Won't fix, can't repro, duplicate, stale May 28, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-theme Themes, theming platform/iOS 🍎 s/needs-info Issue needs more info from the author t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants