This file contains 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
"apns": { | |
"payload": { | |
"aps": { | |
"alert": { | |
"title": "Title", | |
"body": "Message" | |
}, | |
"sound": "popcorn.mp3" | |
} | |
} |
This file contains 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
.onAppear { | |
// Show alert | |
self.viewModel.alert = .init(alert: Alert(title: Text("Hello, I am an alert!"))) | |
// Show sheet | |
self.viewModel.sheet = .init(view: AnyView(SheetView())) | |
} |
This file contains 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
struct ContentView: View { | |
@StateObject private var viewModel: ViewModel = .init() | |
var body: some View { | |
ZStack { | |
Text("Hello, from the content view!") | |
} | |
.alert(item: self.$viewModel.alert) { $0.alert } | |
.sheet(item: self.$viewModel.sheet) { $0.view } | |
} |
This file contains 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
class ViewModel: ObservableObject { | |
@Published var alert: AlertContainer? | |
@Published var sheet: SheetContainer? | |
} |
This file contains 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
struct SheetContainer: Identifiable { | |
let id = UUID() | |
let view: AnyView | |
} |
This file contains 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
struct AlertContainer: Identifiable { | |
let id = UUID() | |
let alert: Alert | |
} |
This file contains 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
@main | |
struct RealtimeLocalizationApp: App { | |
@StateObject var appEnvironment: AppEnvironment = .init() | |
var body: some Scene { | |
WindowGroup { | |
ContentView() | |
.environmentObject(appEnvironment) | |
} |
This file contains 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
struct ContentView: View { | |
@EnvironmentObject var appEnvironment: AppEnvironment | |
var body: some View { | |
VStack { | |
Spacer() | |
Text(appEnvironment.localizationManager.localize("helloWorld")) |