Skip to content

Commit

Permalink
feat(macos): add react-native-macos demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
shirakaba committed Jul 27, 2024
1 parent cd01842 commit 5fc3d41
Show file tree
Hide file tree
Showing 26 changed files with 5,023 additions and 3,070 deletions.
4 changes: 4 additions & 0 deletions examples/demo/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ yarn-error.log

# Ruby / CocoaPods
/ios/Pods/
/macos/Pods/
/vendor/bundle/

# Temporary files created by Metro to check the health of the file watcher
.metro-health-check*

# testing
/coverage

# local env files
.env*.local
40 changes: 27 additions & 13 deletions examples/demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,39 @@

![Demo](demo.gif)

## Running the iOS app
## Running the example apps

After cloning the repository, run the following:

```sh
cd react-native-app-auth/Example
yarn
(cd ios && pod install)
npx react-native run-ios
```

## Running the Android app

After cloning the repository, run the following:

```sh
cd react-native-app-auth/Example
yarn
npx react-native run-android
# Install the pods for the iOS example app
cd ios && pod install
# Install the pods for the macOS example app
cd macos && pod install

# From here on, you'll need two terminals.

# [In terminal A]
# Start the Metro bundler
yarn start

# [In terminal B]
# Run the iOS app
yarn ios

# or:
# Run the Android app
yarn android

# or:
# Run the macOS app (after setting `applePlatform = "macos"` in metro.config.js)
#
# Note that we do not currently support running the macOS demo simultaneously
# with iOS or Android apps, as we use the `applePlatform = "macos"` flag to
# force Metro to resolve react-native-macos instead of react-native.
yarn macos
```

### Notes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
1 change: 1 addition & 0 deletions examples/demo/macos/.xcode.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export NODE_BINARY=$(command -v node)
11 changes: 11 additions & 0 deletions examples/demo/macos/Example-macOS/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#import <Cocoa/Cocoa.h>
#import <RCTAppDelegate.h>
#import <React/RCTLinkingManager.h>
#import "RNAppAuthAuthorizationFlowManager.h"

@interface AppDelegate : RCTAppDelegate <RNAppAuthAuthorizationFlowManager>

@property(nonatomic, weak) id<RNAppAuthAuthorizationFlowManagerDelegate>
authorizationFlowManagerDelegate;

@end
60 changes: 60 additions & 0 deletions examples/demo/macos/Example-macOS/AppDelegate.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTLinkingManager.h>

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
self.moduleName = @"Example";
// You can add your custom initial props in the dictionary below.
// They will be passed down to the ViewController used by React Native.
self.initialProps = @{};

return [super applicationDidFinishLaunching:notification];
}

- (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];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
///
/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
/// @return: `true` if the `concurrentRoot` feature is enabled. Otherwise, it returns `false`.
- (BOOL)concurrentRootEnabled
{
#ifdef RN_FABRIC_ENABLED
return true;
#else
return false;
#endif
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"images" : [
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading

0 comments on commit 5fc3d41

Please sign in to comment.