microsoft / react-native-test-app

react-native-test-app provides an app for all supported platforms as a package
MIT License
576 stars 87 forks source link

macOS: Migrate to SwiftUI and deprecate `Main.storyboard` #111

Open tido64 opened 4 years ago

tido64 commented 4 years ago

It seems like a better idea to either hookup the window from the nib/storyboard to the AppDelegate; or, if the nib/storyboard doesn’t do anything of interest, just remove the window from there and create it programmatically instead.

Originally posted by @alloy in https://github.com/microsoft/react-native-test-app/pull/104

tido64 commented 10 months ago

We will likely migrate to SwiftUI and deprecate Main.storyboard entirely. This will require us to bump the macOS deployment target to 11.0+. At the moment, we're stuck on 10.15 so we're looking at 4.0 release at the earliest.

In any case, I did some preliminary investigation and it looks like we no longer need to declare the default menu items. The code below will correctly insert the React menu between View and Window:

import SwiftUI

@main
struct ReactTestApp: App {
    @State private var rememberLastComponent = false

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        .commands {
            CommandMenu(LocalizedStringKey(stringLiteral: "React")) {
                Button(LocalizedStringKey(stringLiteral: "Load Embedded JS Bundle")) {
                    // TODO
                }
                Button(LocalizedStringKey(stringLiteral: "Load From Dev Server")) {
                    // TODO
                }
                Toggle(LocalizedStringKey(stringLiteral: "Remember Last Opened Component"), isOn: $rememberLastComponent)
                Divider()
            }
        }
    }
}