-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Platform: Implement Platform.isCatalyst #29937
Conversation
Base commit: a315e4c |
Base commit: a315e4c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like the function doesn’t add much and the check could simply be inlined, but I assume the compiler will optimise it that way so it’s mostly a stylistic choice 🤷♂️
@@ -67,6 +68,10 @@ const Platform = { | |||
} | |||
return false; | |||
}, | |||
// $FlowFixMe[unsafe-getters-setters] | |||
get isCatalyst(): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer this to called isMacCatalyst()
as it's more clear and more inline with how Apple markets the technology.
My general concern is that this will force all platforms to implement a isMacCatalyst()
method, which is very specific, so I wonder if we should instead go with a method called isDesktop()
to be more inclusive for our other platforms. That way react-native-macos
and react-native-windows
can return true
for this method as well.
Thoughts @alloy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that, I’m just a little concerned about the boundaries. Would this return true
on iPad OS or what is the definition of a desktop machine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the purpose is it would return true
for macOS (AppKit or UIKit) and Windows. 😄
Although lots of people use iPad as a desktop, I think the general expectation is that it is not classified as a desktop. If that's a controversial opinion, then we can consider another name. We already have isPad()
and isTV()
methods that describe the type of device rather than particular OS, so I think isDesktop()
would fit nicely in there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, perhaps desktops and iPads together are ‘workstations’? In any case, seems like we have enough ways to narrow down the type, so I’m good with ‘desktop’ 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just include it inside Platform.OS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EhsanSarshar because Mac Catalyst isn't a platform itself, it's running the iOS app on macOS, so its behavior should mostly follow iOS except for some cases where we want it to be desktop.
Also, Platform.OS
is handled by the packager (Metro) during build time, not here in React Native. See this PR for the implementation of Platform.select
with mac
: facebook/metro#495.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@charpeni Will you update this to be isDesktop
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
Any updates on this? This is a great enhancement |
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This PR was closed because it has been stalled for 7 days with no activity. |
Summary
Following up on #27484, instead of adding
Platform.isMac
this pull request is proposingPlatform.isCatalyst
to avoid a collision withreact-native-macos
.Platform.OS
is still returningios
, even on macOS with Catalyst.In the meantime, you can rely on
react-native-is-catalyst
as an external dependency.Changelog
[General] [Added] - Implement Platform.isCatalyst to know if we're running on macOS with Catalyst.
Test Plan