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

Platform: Implement Platform.isCatalyst #29937

Closed
wants to merge 1 commit into from

Conversation

charpeni
Copy link
Contributor

@charpeni charpeni commented Sep 11, 2020

Summary

Following up on #27484, instead of adding Platform.isMac this pull request is proposing Platform.isCatalyst to avoid a collision with react-native-macos.

⚠️ Note that Platform.OS is still returning ios, 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

macOS iOS

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 11, 2020
@charpeni charpeni requested a review from shergin September 11, 2020 19:46
@facebook-github-bot facebook-github-bot added the Contributor A React Native contributor. label Sep 11, 2020
@react-native-bot react-native-bot added the Type: Enhancement A new feature or enhancement of an existing feature. label Sep 11, 2020
@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: a315e4c

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,211,137 60
android hermes armeabi-v7a 6,860,309 60
android hermes x86 7,645,773 68
android hermes x86_64 7,536,709 52
android jsc arm64-v8a 9,370,062 16
android jsc armeabi-v7a 9,011,366 12
android jsc x86 9,232,786 8
android jsc x86_64 9,809,926 8

Base commit: a315e4c

@elicwhite
Copy link
Member

cc @appden @alloy

Copy link
Contributor

@alloy alloy left a 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 {
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor

@appden appden Sep 18, 2020

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.

Copy link
Contributor

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’ 👍

Copy link

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

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do!

@marcosrdz
Copy link

Any updates on this? This is a great enhancement

@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jul 18, 2023
@github-actions
Copy link

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot closed this Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Contributor A React Native contributor. Stale There has been a lack of activity on this issue and it may be closed soon. Type: Enhancement A new feature or enhancement of an existing feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants