-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AppDelegate with RootHolder for ios app lifecycle implementation …
…with decompose
- Loading branch information
1 parent
0aaa5fa
commit 35b31d0
Showing
4 changed files
with
89 additions
and
18 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,63 @@ | ||
import SwiftUI | ||
import ComposeApp | ||
|
||
@main | ||
struct iOSApp: App { | ||
|
||
@UIApplicationDelegateAdaptor(AppDelegate.self) | ||
var appDelegate: AppDelegate | ||
|
||
var rootHolder: RootHolder { | ||
appDelegate.rootHolder | ||
} | ||
|
||
var body: some Scene { | ||
WindowGroup { | ||
ContentView() | ||
ContentView(rootComponet: rootHolder.root) | ||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in | ||
debugPrint("Swift onResume") | ||
LifecycleRegistryExtKt.resume(rootHolder.lifecycle) | ||
} | ||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification)) { _ in | ||
debugPrint("Swift onPause") | ||
LifecycleRegistryExtKt.pause(rootHolder.lifecycle) | ||
} | ||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didEnterBackgroundNotification)) { _ in | ||
debugPrint("Swift onStop") | ||
LifecycleRegistryExtKt.stop(rootHolder.lifecycle) | ||
} | ||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willTerminateNotification)) { _ in | ||
debugPrint("Swift onDestroy") | ||
LifecycleRegistryExtKt.destroy(rootHolder.lifecycle) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
class RootHolder: ObservableObject { | ||
|
||
let lifecycle: LifecycleRegistry | ||
let root: RootComponent | ||
|
||
init() { | ||
lifecycle = LifecycleRegistryKt.LifecycleRegistry() | ||
lifecycle.subscribe(callbacks: LifecycleCallbacksImpl()) | ||
let homeViewModel = HomeViewModel() | ||
|
||
root = DefaultRootComponent( | ||
componentContext: DefaultComponentContext(lifecycle: lifecycle), | ||
homeViewModel: homeViewModel | ||
) | ||
|
||
LifecycleRegistryExtKt.create(lifecycle) | ||
} | ||
|
||
deinit { | ||
LifecycleRegistryExtKt.destroy(lifecycle) | ||
} | ||
|
||
} | ||
|
||
class AppDelegate: NSObject, UIApplicationDelegate { | ||
let rootHolder: RootHolder = RootHolder() | ||
} |