-
Notifications
You must be signed in to change notification settings - Fork 50
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
.environment(\.font, .custom(...))
type inference fails with a confusing error message
#347
Comments
Thanks for the report. Could also use .font(.custom...) |
|
I think there's a misunderstanding. .font(_:) is defined on View and establishes the default font for everything in the View. It is exactly equivalent to .environment(.font, ...) The same pattern applies to most SwiftUI modifiers - it is very rare to need to set .environment(.key, ...) directly |
TIL! https://developer.apple.com/documentation/swiftui/view/font(_:)
So, I guess the FWIW, this is the top hit in Google Search for changing the default font. https://stackoverflow.com/a/75992302/54829 So I think this issue is still a bit of a footgun for folks who don't know that |
In SwiftUI, you can use the
.environment()
modifier to set a custom default font, like this:But Skip has a type inference bug in this code: you have to call it with
Font.custom()
and not with simply.custom()
, or it will fail to compile on Android.I know that type-inference bugs are something I just have to deal with in Skip, but instead of saying, "Cannot infer type for this parameter", I get a really cryptic error message.
To reproduce this bug, I forked the Showcase app https://github.com/dfabulich/skipapp-showcase/tree/environment-font-bug-example and added a one-line commit: dfabulich/skipapp-showcase@4d55295
Expected: Build fails with "Cannot infer type for this parameter" error
Actual:
The text was updated successfully, but these errors were encountered: