diff --git a/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.h b/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.h deleted file mode 100644 index 63db973168d0..000000000000 --- a/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.h +++ /dev/null @@ -1,6 +0,0 @@ -#import -#import - -@interface AppDelegate : RCTAppDelegate - -@end diff --git a/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.mm b/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.mm deleted file mode 100644 index ddea64bfd235..000000000000 --- a/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.mm +++ /dev/null @@ -1,47 +0,0 @@ -#import "AppDelegate.h" - -#import -#import - -@implementation AppDelegate - -- (void)applicationDidFinishLaunching:(NSNotification *)notification -{ - self.moduleName = @"HelloWorld"; - // 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 = @{}; - self.dependencyProvider = [RCTAppDependencyProvider new]; - - return [super applicationDidFinishLaunching:notification]; -} - -- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge -{ - return [self bundleURL]; -} - -- (NSURL *)bundleURL -{ -#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 diff --git a/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.swift b/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.swift new file mode 100644 index 000000000000..1a9040193722 --- /dev/null +++ b/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.swift @@ -0,0 +1,62 @@ +import SwiftUI +import React +import React_RCTAppDelegate +import ReactAppDependencyProvider + +@main +struct HelloWorldApp: App { + @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate + + var body: some Scene { + Window("HelloWorld", id: "main") { + ReactNativeView(factory: appDelegate.reactNativeFactory) + } + .defaultSize(width: 1280, height: 720) + } +} + +// MARK: - App Delegate + +class AppDelegate: NSObject, NSApplicationDelegate { + private let reactNativeDelegate: ReactNativeDelegate + let reactNativeFactory: RCTReactNativeFactory + + override init() { + super.init() + + let delegate = ReactNativeDelegate() + let factory = RCTReactNativeFactory(delegate: delegate) + delegate.dependencyProvider = RCTAppDependencyProvider() + + reactNativeDelegate = delegate + reactNativeFactory = factory + } +} + +// MARK: - React Native Delegate + +class ReactNativeDelegate: RCTDefaultReactNativeFactoryDelegate { + override func sourceURL(for bridge: RCTBridge) -> URL? { + bundleURL() + } + + override func bundleURL() -> URL? { +#if DEBUG + RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index") +#else + Bundle.main.url(forResource: "main", withExtension: "jsbundle") +#endif + } +} + +// MARK: - React Native SwiftUI View + +struct ReactNativeView: NSViewRepresentable { + let factory: RCTReactNativeFactory + + func makeNSView(context: Context) -> NSView { + factory.rootViewFactory.view(withModuleName: "HelloWorld") + } + + func updateNSView(_ nsView: NSView, context: Context) {} +} diff --git a/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/Base.lproj/Main.storyboard b/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/Base.lproj/Main.storyboard deleted file mode 100644 index a3afa65f0c0e..000000000000 --- a/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/Base.lproj/Main.storyboard +++ /dev/null @@ -1,684 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/Info.plist b/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/Info.plist index 5c7ebb780201..5a46616ce88d 100644 --- a/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/Info.plist +++ b/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/Info.plist @@ -35,8 +35,6 @@ - NSMainStoryboardFile - Main NSPrincipalClass NSApplication NSSupportsAutomaticTermination diff --git a/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/main.m b/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/main.m deleted file mode 100644 index 1f154fcf69b0..000000000000 --- a/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/main.m +++ /dev/null @@ -1,5 +0,0 @@ -#import - -int main(int argc, const char *argv[]) { - return NSApplicationMain(argc, argv); -} diff --git a/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld.xcodeproj/project.pbxproj b/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld.xcodeproj/project.pbxproj index 63b8b0b4f7c5..452236213426 100644 --- a/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld.xcodeproj/project.pbxproj +++ b/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld.xcodeproj/project.pbxproj @@ -7,21 +7,18 @@ objects = { /* Begin PBXBuildFile section */ - 5142014D2437B4B30078DB4F /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5142014C2437B4B30078DB4F /* AppDelegate.mm */; }; + 5142014D2437B4B30078DB4F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5142014C2437B4B30078DB4F /* AppDelegate.swift */; }; 514201522437B4B40078DB4F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 514201512437B4B40078DB4F /* Assets.xcassets */; }; - 514201552437B4B40078DB4F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 514201532437B4B40078DB4F /* Main.storyboard */; }; - 514201582437B4B40078DB4F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 514201572437B4B40078DB4F /* main.m */; }; + /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 13B07F961A680F5B00A75B9A /* HelloWorld.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HelloWorld.app; sourceTree = BUILT_PRODUCTS_DIR; }; 514201492437B4B30078DB4F /* HelloWorld.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HelloWorld.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 5142014B2437B4B30078DB4F /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; - 5142014C2437B4B30078DB4F /* AppDelegate.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AppDelegate.mm; sourceTree = ""; }; + 5142014C2437B4B30078DB4F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 514201512437B4B40078DB4F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 514201542437B4B40078DB4F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 514201562437B4B40078DB4F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 514201572437B4B40078DB4F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 514201592437B4B40078DB4F /* HelloWorld.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HelloWorld.entitlements; sourceTree = ""; }; ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ @@ -55,12 +52,10 @@ 5142014A2437B4B30078DB4F /* HelloWorld-macOS */ = { isa = PBXGroup; children = ( - 5142014B2437B4B30078DB4F /* AppDelegate.h */, - 5142014C2437B4B30078DB4F /* AppDelegate.mm */, + 5142014C2437B4B30078DB4F /* AppDelegate.swift */, + 514201512437B4B40078DB4F /* Assets.xcassets */, - 514201532437B4B40078DB4F /* Main.storyboard */, 514201562437B4B40078DB4F /* Info.plist */, - 514201572437B4B40078DB4F /* main.m */, 514201592437B4B40078DB4F /* HelloWorld.entitlements */, ); path = "HelloWorld-macOS"; @@ -159,7 +154,6 @@ hasScannedForEncodings = 0; knownRegions = ( en, - Base, ); mainGroup = 83CBB9F61A601CBA00E9B192; productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */; @@ -185,7 +179,6 @@ buildActionMask = 2147483647; files = ( 514201522437B4B40078DB4F /* Assets.xcassets in Resources */, - 514201552437B4B40078DB4F /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -282,24 +275,13 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 514201582437B4B40078DB4F /* main.m in Sources */, - 5142014D2437B4B30078DB4F /* AppDelegate.mm in Sources */, + + 5142014D2437B4B30078DB4F /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ -/* Begin PBXVariantGroup section */ - 514201532437B4B40078DB4F /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 514201542437B4B40078DB4F /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - /* Begin XCBuildConfiguration section */ 13B07F941A680F5B00A75B9A /* Debug */ = { isa = XCBuildConfiguration;