Skip to content

Commit cce1d21

Browse files
feat: Update Swift AppDelegate templates and tests for Expo 53 support
1 parent 525ed6e commit cce1d21

7 files changed

Lines changed: 172 additions & 350 deletions

File tree

src/plugin/__tests__/__snapshots__/withAuth0-test.ts.snap

Lines changed: 66 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -306,182 +306,92 @@ exports[`addAndroidAuth0Manifest without scheme should have package name 1`] = `
306306
}
307307
`;
308308

309-
exports[`addAuth0AppDelegateCode does not modify the AppDelegate 1`] = `
309+
exports[`addAuth0AppDelegateCode does not modify Swift AppDelegate when linking is already present 1`] = `
310310
"
311-
// This AppDelegate template is used in Expo SDK 43 and newer
312-
// It is (nearly) identical to the pure template used when
313-
// creating a bare React Native app (without Expo)
311+
// Swift AppDelegate template for Expo 53+
314312
315-
#import "AppDelegate.h"
313+
import UIKit
314+
import React
315+
import React_RCTAppDelegate
316+
import ReactAppDependencyProvider
317+
import React_RCTLinking
316318
317-
#import <React/RCTBridge.h>
318-
#import <React/RCTBundleURLProvider.h>
319-
#import <React/RCTRootView.h>
320-
#import <React/RCTLinkingManager.h>
321-
#import <React/RCTConvert.h>
319+
@main
320+
class AppDelegate: RCTAppDelegate {
321+
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
322+
self.moduleName = "Auth0Example"
323+
self.dependencyProvider = RCTAppDependencyProvider()
322324
323-
#if defined(FB_SONARKIT_ENABLED) && __has_include(<FlipperKit/FlipperClient.h>)
324-
#import <FlipperKit/FlipperClient.h>
325-
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
326-
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
327-
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
328-
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
329-
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
325+
// You can add your custom initial props in the dictionary below.
326+
// They will be passed down to the ViewController used by React Native.
327+
self.initialProps = [:]
330328
331-
static void InitializeFlipper(UIApplication *application) {
332-
FlipperClient *client = [FlipperClient sharedClient];
333-
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
334-
[client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
335-
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
336-
[client addPlugin:[FlipperKitReactPlugin new]];
337-
[client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
338-
[client start];
339-
}
340-
#endif
329+
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
330+
}
341331
342-
@implementation AppDelegate
332+
override func sourceURL(for bridge: RCTBridge) -> URL? {
333+
self.bundleURL()
334+
}
343335
344-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
345-
{
346-
#if defined(FB_SONARKIT_ENABLED) && __has_include(<FlipperKit/FlipperClient.h>)
347-
InitializeFlipper(application);
336+
override func bundleURL() -> URL? {
337+
#if DEBUG
338+
RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
339+
#else
340+
Bundle.main.url(forResource: "main", withExtension: "jsbundle")
348341
#endif
342+
}
349343
350-
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
351-
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"main" initialProperties:nil];
352-
id rootViewBackgroundColor = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTRootViewBackgroundColor"];
353-
if (rootViewBackgroundColor != nil) {
354-
rootView.backgroundColor = [RCTConvert UIColor:rootViewBackgroundColor];
355-
} else {
356-
rootView.backgroundColor = [UIColor whiteColor];
344+
// Handle URL schemes for Auth0 authentication
345+
override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
346+
return RCTLinkingManager.application(app, open: url, options: options)
357347
}
358-
359-
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
360-
UIViewController *rootViewController = [UIViewController new];
361-
rootViewController.view = rootView;
362-
self.window.rootViewController = rootViewController;
363-
[self.window makeKeyAndVisible];
364-
365-
[super application:application didFinishLaunchingWithOptions:launchOptions];
366-
367-
return YES;
368-
}
369-
370-
- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge
371-
{
372-
// If you'd like to export some custom RCTBridgeModules, add them here!
373-
return @[];
374-
}
375-
376-
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
377-
#ifdef DEBUG
378-
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
379-
#else
380-
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
381-
#endif
382-
}
383-
384-
// Linking API
385-
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
386-
return [RCTLinkingManager application:application openURL:url options:options];
387348
}
388-
389-
// Universal Links
390-
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
391-
return [RCTLinkingManager application:application
392-
continueUserActivity:userActivity
393-
restorationHandler:restorationHandler];
394-
}
395-
396-
@end
397349
"
398350
`;
399351
400-
exports[`addAuth0AppDelegateCode modifies the AppDelegate 1`] = `
352+
exports[`addAuth0AppDelegateCode modifies Swift AppDelegate to add linking 1`] = `
401353
"
402-
// This AppDelegate template is used in Expo SDK 43 and newer
403-
// It is (nearly) identical to the pure template used when
404-
// creating a bare React Native app (without Expo)
405-
406-
#import "AppDelegate.h"
407-
408-
#import <React/RCTBridge.h>
409-
// @generated begin react-native-auth0-import - expo prebuild (DO NOT MODIFY) sync-60472b7c5bde1787041c5dcbb357e68108fe1334
410-
#import <React/RCTLinkingManager.h>
411-
// @generated end react-native-auth0-import
412-
#import <React/RCTBundleURLProvider.h>
413-
#import <React/RCTRootView.h>
414-
#import <React/RCTConvert.h>
415-
416-
#if defined(FB_SONARKIT_ENABLED) && __has_include(<FlipperKit/FlipperClient.h>)
417-
#import <FlipperKit/FlipperClient.h>
418-
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
419-
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
420-
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
421-
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
422-
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
423-
424-
static void InitializeFlipper(UIApplication *application) {
425-
FlipperClient *client = [FlipperClient sharedClient];
426-
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
427-
[client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
428-
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
429-
[client addPlugin:[FlipperKitReactPlugin new]];
430-
[client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
431-
[client start];
432-
}
433-
#endif
354+
// Swift AppDelegate template for Expo 53+
355+
356+
import UIKit
357+
import React
358+
import React_RCTAppDelegate
359+
// @generated begin react-native-auth0-import-swift - expo prebuild (DO NOT MODIFY) sync-8f8140f6ace974b4bb8a60975d49acbdd6303038
360+
import React_RCTLinking
361+
// @generated end react-native-auth0-import-swift
362+
import ReactAppDependencyProvider
363+
364+
@main
365+
class AppDelegate: RCTAppDelegate {
366+
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
367+
self.moduleName = "Auth0Example"
368+
self.dependencyProvider = RCTAppDependencyProvider()
369+
370+
// You can add your custom initial props in the dictionary below.
371+
// They will be passed down to the ViewController used by React Native.
372+
self.initialProps = [:]
373+
374+
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
375+
}
376+
// @generated begin react-native-auth0-linking-swift - expo prebuild (DO NOT MODIFY) sync-ba380858111cdf18a4962daf3f391b02f6c9b25a
377+
// Handle URL schemes for Auth0 authentication
378+
override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
379+
return RCTLinkingManager.application(app, open: url, options: options)
380+
}
381+
// @generated end react-native-auth0-linking-swift
434382
435-
@implementation AppDelegate
383+
override func sourceURL(for bridge: RCTBridge) -> URL? {
384+
self.bundleURL()
385+
}
436386
437-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
438-
{
439-
#if defined(FB_SONARKIT_ENABLED) && __has_include(<FlipperKit/FlipperClient.h>)
440-
InitializeFlipper(application);
387+
override func bundleURL() -> URL? {
388+
#if DEBUG
389+
RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
390+
#else
391+
Bundle.main.url(forResource: "main", withExtension: "jsbundle")
441392
#endif
442-
443-
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
444-
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"main" initialProperties:nil];
445-
id rootViewBackgroundColor = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTRootViewBackgroundColor"];
446-
if (rootViewBackgroundColor != nil) {
447-
rootView.backgroundColor = [RCTConvert UIColor:rootViewBackgroundColor];
448-
} else {
449-
rootView.backgroundColor = [UIColor whiteColor];
450393
}
451-
452-
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
453-
UIViewController *rootViewController = [UIViewController new];
454-
rootViewController.view = rootView;
455-
self.window.rootViewController = rootViewController;
456-
[self.window makeKeyAndVisible];
457-
458-
[super application:application didFinishLaunchingWithOptions:launchOptions];
459-
460-
return YES;
461-
}
462-
463-
- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge
464-
{
465-
// If you'd like to export some custom RCTBridgeModules, add them here!
466-
return @[];
467-
}
468-
469-
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
470-
#ifdef DEBUG
471-
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
472-
#else
473-
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
474-
#endif
475-
}
476-
477-
// @generated begin react-native-auth0-linking - expo prebuild (DO NOT MODIFY) sync-4120cf784d32ef9e73c7c71def92162e38e5087f
478-
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
479-
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
480-
{
481-
return [RCTLinkingManager application:app openURL:url options:options];
482394
}
483-
// @generated end react-native-auth0-linking
484-
@end
485395
"
486396
`;
487397

src/plugin/__tests__/fixtures/appdelegate-withlinking.ts

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)