-
Notifications
You must be signed in to change notification settings - Fork 441
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
feat(macos): support react-native-macos #1002
base: main
Are you sure you want to change the base?
feat(macos): support react-native-macos #1002
Conversation
🦋 Changeset detectedLatest commit: b3da68b The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
4e9d4ce
to
259809c
Compare
|
||
#if TARGET_OS_MACCATALYST | ||
id<OIDExternalUserAgent> externalUserAgent = nil; | ||
#elif TARGET_OS_IOS | ||
id<OIDExternalUserAgent> externalUserAgent = iosCustomBrowser != nil ? [self getCustomBrowser: iosCustomBrowser] : [self getExternalUserAgentWithPresentingViewController:presentingViewController | ||
prefersEphemeralSession:prefersEphemeralSession]; | ||
#elif TARGET_OS_OSX | ||
id<OIDExternalUserAgent> externalUserAgent = nil; |
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 was unsure about this externalUserAgent = nil
, but it does turn out that under-the-hood for the APIs we're calling, the AppAuth library makes an appropriate OIDExternalUserAgentMac
for you so there's no need to make one yourself.
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST | ||
[UIApplication.sharedApplication endBackgroundTask:rnAppAuthTaskId]; | ||
rnAppAuthTaskId = UIBackgroundTaskInvalid; | ||
#elif TARGET_OS_OSX | ||
// Brings this app to the foreground. | ||
[[NSRunningApplication currentApplication] activateWithOptions:(NSApplicationActivateAllWindows)]; | ||
#endif |
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.
macOS AppKit apps don't get backgrounded, so we don't need to declare background tasks (but do benefit from refocusing the app).
s.platform = :ios, '10.0' | ||
s.ios.deployment_target = '10.0' | ||
s.osx.deployment_target = '10.15' |
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.
Technically, AppAuth lets us deploy down to the following versions:
s.ios.deployment_target = "9.0"
s.osx.deployment_target = "10.12"
I've chosen 10.15
for this library just to align with the react-native-macos
template's minimum deployment target.
Thanks @Saadnajmi for your great guidance! I'll address those aspects once I'm free (think today I'll be working on other things, however). As we discussed on Twitter, react-native-test-app may be the way forwards for integrating an out-of-tree-platform's example app into this repo, and rnx-kit may be able to help out with the Metro config. |
259809c
to
8ec536a
Compare
@Saadnajmi I've now migrated the PR to use react-native-test-app, which resolves my issues with the Metro bundler. I've also aligned to a common minor of React Native, and have addressed all the However, the demo app requires a custom AppDelegate to make it conform to |
8ec536a
to
ce193fc
Compare
I don't think RNTA supports custom App Delegates, so that would be a feature request (@tido64 fyi). It does support expo config plugins, does that let you modify the app delegate? https://github.com/microsoft/react-native-test-app/wiki/Config-Plugins Though I'm realizing for macOS, that means you need 0.74 😅 |
Unfortunately the one implementing Expo config plugins support for react-native-macos is none other than myself, so I can report that it’s not ready yet 😅 I’ve actually already completed the implementation of Expo config plugins, but need to rewrite the tests, which I was hoping to get at this evening. Still though, it would depend on Expo reviewing and merging it, and even then would only make it into SDK 51 (which expects RN 0.74 🥲) or later. So I think we’d either need a new feature in RNTestApp or go without it in this case. |
Okay, I've ripped out RNTA again and now have a mix of
This is the best I can do! Would be able to get them both on the same version if RNTA supported custom AppDelegates, however. |
I don't know if this helps, but I've had this branch for a while that I've just submitted: microsoft/react-native-test-app#2160 |
@tido64 Thanks so much for that PR; it should make everything easier! Sorry I wasn't able to review any closer – I had my hands full last week. I'll try it out once I get back to this PR. |
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.
Thanks for the great PR ❤️
I've spotted a few very minor issues that would be great if you could address before we merge.
examples/demo/ios/Podfile.lock
Outdated
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.
The current version of CocoaPods is 1.15.2
- https://github.com/CocoaPods/CocoaPods/releases
Can this change be reverted, or is there a specific reason for this change?
examples/demo/README.md
Outdated
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.
It would be very helpful if you could add/update any setup instructions to cover macOS as well on docs/docs/introduction.md
and README.md
.
examples/demo/macos/Podfile.lock
Outdated
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.
It would be great if this could also use COCOAPODS: 1.15.2
instead of 1.14.3
@robwalkerco Thank you for the review! Pending tasks in my mind:
I've been a little burnt out lately so may not be able to jump straight on this but do hope to push this over the line soon. |
.yarnrc
Outdated
# yarn lockfile v1 | ||
|
||
|
||
yarn-path ".yarn/releases/yarn-1.19.1.cjs" |
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.
If we want to use a non-global version of Yarn, we should look at enabling corepack instead of checking in the binary. Since this is unrelated to this specific PR, it would be best to revert this change and open a separate PR for this specifically.
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 was actually hoping to just install using global Yarn v1 here, but installation always failed with the following error:
expected workspace package to exist for "eslint"
I looked up the error and it recommended this as the fix. If you know another way to get yarn to successfully install this repo's packages, I'd be happy to implement that.
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 managed to successfully install with global Yarn v1, so I've removed this.
I've done a little more work on this to see if this can be migrated to React Native Test App, which would be helpful for adding Windows support in future. @tido64 I'm struggling to use
const { createRunOncePlugin, } = require("@expo/config-plugins");
const { mergeContents } = require("@expo/config-plugins/build/utils/generateCode");
const { macos } = require("react-native-test-app/plugins/index");
function withCustomAppDelegate(config) {
return macos.withAppDelegate(config, (config) => {
// See:
// - examples/demo/node_modules/react-native-test-app/macos/ReactTestApp/AppDelegate.swift
// - https://github.com/microsoft/react-native-test-app/pull/2160#issue-2435799831
config.modResults.contents = mergeContents({
tag: "config-plugin.js",
src: config.modResults.contents,
newSrc: "extension AppDelegate: RNAppAuthAuthorizationFlowManager {}",
anchor: /extension AppDelegate {/,
offset: 0,
comment: "//",
}).contents;
return config;
});
}
module.exports = createRunOncePlugin(
withCustomAppDelegate,
"test-plugin.js",
"UNVERSIONED"
);
#import <React/RCTLinkingManager.h>
// ... a few lines later:
- (void)applicationWillFinishLaunching:(NSNotification *)notification {
[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self
andSelector:@selector(getURL:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];
}
- (void)getURL:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)reply
{
NSString* urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSURL *url = [NSURL URLWithString:urlString];
if ([self.authorizationFlowManagerDelegate resumeExternalUserAgentFlowWithURL:url]) {
return;
}
[RCTLinkingManager getUrlEventHandler:event withReplyEvent:reply];
} ... Unfortunately, the current AppDelegate has multiple occurences of the string "applicationWillFinishLaunching", so it is impossible to come up with a non-fragile RegExp pattern to use with it (particularly as the config plugin does not support multi-line regexes). The Expo Config AppDelegate Plugin moreover seems to no-op if there's more than one match. Largely, this is down to the |
@robwalkerco I'm proceeding to try to get this onto React Native Test App so that adding support for Windows in future will be simpler and to improve long-term maintainability (we'd be able to just bump the version of RNTA to upgrade all example apps). Would you be happy with me migrating the repo to use RNTA as part of this PR, or should it be a follow-up PR? (Noting that I wasn't having much luck getting this working without RNTA – testing the |
I added some anchor points. I hope this helps: microsoft/react-native-test-app#2188 |
@shirakaba It would be preferable if adding RNTA could be handled in a separate PR. That should also help to get this initial macOS PR merged more quickly for you. |
38d7a63
to
5ca0d4a
Compare
3248a96
to
0f7670c
Compare
… exist for "eslint"' error yarnpkg/yarn#8405
FIXME: need to ask how to customise the AppDelegate as in the previous commit, as it's complaining about: Thread 1: "<ReactTestApp.AppDelegate: 0x10a3e7b50> does not conform to RNAppAuthAuthorizationFlowManager" And will likely need to do similar customisation for Android.
Based on these: facebook/react-native#42278
This reverts commit ce193fc.
0f7670c
to
a9ddf95
Compare
@robwalkerco I've:
Is there any blocker to merging this now? |
Fixes #1001
Description
Adds react-native-macos support 🥳
Steps to verify
Follow the updated setup instructions in
examples/demo/README.md
to run the demo app. See the following screenshots for expected behaviour with the two providers: