forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 167
feat(macos): migrate init template from Objective-C to Swift #2948
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
Draft
Saadnajmi
wants to merge
5
commits into
microsoft:main
Choose a base branch
from
Saadnajmi:swift-init-template
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c00ca3f
feat(macos): migrate init template from Objective-C to Swift
Saadnajmi 9fbf879
refactor(macos): use @resultBuilder for declarative menu creation
Saadnajmi a2e7825
refactor(macos): extract menu into NSMenu.standardMenu(appName:) factory
Saadnajmi 049bf85
refactor(macos): adopt SwiftUI App lifecycle with NSViewRepresentable
Saadnajmi a7d14f3
Apply suggestion from @Saadnajmi
Saadnajmi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 0 additions & 6 deletions
6
...ges/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.h
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
...es/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.mm
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
...react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) {} | ||
| } | ||
684 changes: 0 additions & 684 deletions
684
...ive/local-cli/generator-macos/templates/macos/HelloWorld-macOS/Base.lproj/Main.storyboard
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/main.m
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.