-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create and pass LifecycleHelper from iOS apps to main.ios.kt
- Loading branch information
Showing
8 changed files
with
102 additions
and
12 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,17 +1,52 @@ | ||
import SwiftUI | ||
import ios | ||
import Foundation | ||
import UIKit | ||
|
||
@main | ||
struct iOSApp: App { | ||
|
||
@UIApplicationDelegateAdaptor(AppDelegate.self) | ||
var appDelegate: AppDelegate | ||
|
||
@Environment(\.scenePhase) var scenePhase | ||
|
||
var body: some Scene { | ||
WindowGroup { | ||
ZStack { | ||
Color.white.ignoresSafeArea(.all) // status bar color | ||
ContentView() | ||
ContentView(lifecycleHelper: appDelegate.lifecycleHolder.lifecycleHelper) | ||
} | ||
.onOpenURL { incomingURL in | ||
Main_iosKt.handleDeepLinks(url: incomingURL) | ||
} | ||
.onChange(of: scenePhase) { newPhase in | ||
switch newPhase { | ||
case .background: appDelegate.lifecycleHolder.lifecycleHelper.created() | ||
case .inactive: appDelegate.lifecycleHolder.lifecycleHelper.created() | ||
case .active: appDelegate.lifecycleHolder.lifecycleHelper.resumed() | ||
@unknown default: break | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
class AppDelegate: NSObject, UIApplicationDelegate { | ||
let lifecycleHolder: LifecycleHolder = LifecycleHolder() | ||
} | ||
|
||
class LifecycleHolder { | ||
|
||
let lifecycleHelper: LifecycleHelper | ||
|
||
init() { | ||
lifecycleHelper = LifecycleHelper() | ||
lifecycleHelper.created() | ||
} | ||
|
||
deinit { | ||
// Destroy the root component before it is deallocated | ||
lifecycleHelper.destroyed() | ||
} | ||
} |
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,13 +1,50 @@ | ||
import SwiftUI | ||
import ios | ||
import Foundation | ||
import UIKit | ||
|
||
@main | ||
struct iOSApp: App { | ||
|
||
@UIApplicationDelegateAdaptor(AppDelegate.self) | ||
var appDelegate: AppDelegate | ||
|
||
@Environment(\.scenePhase) var scenePhase | ||
|
||
var body: some Scene { | ||
WindowGroup { | ||
ZStack { | ||
Color.white.ignoresSafeArea(.all) // status bar color | ||
ContentView() | ||
}.preferredColorScheme(.light) | ||
ContentView(lifecycleHelper: appDelegate.lifecycleHolder.lifecycleHelper) | ||
} | ||
.preferredColorScheme(.light) | ||
.onChange(of: scenePhase) { newPhase in | ||
switch newPhase { | ||
case .background: appDelegate.lifecycleHolder.lifecycleHelper.created() | ||
case .inactive: appDelegate.lifecycleHolder.lifecycleHelper.created() | ||
case .active: appDelegate.lifecycleHolder.lifecycleHelper.resumed() | ||
@unknown default: break | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
class AppDelegate: NSObject, UIApplicationDelegate { | ||
let lifecycleHolder: LifecycleHolder = LifecycleHolder() | ||
} | ||
|
||
class LifecycleHolder { | ||
|
||
let lifecycleHelper: LifecycleHelper | ||
|
||
init() { | ||
lifecycleHelper = LifecycleHelper() | ||
lifecycleHelper.created() | ||
} | ||
|
||
deinit { | ||
// Destroy the root component before it is deallocated | ||
lifecycleHelper.destroyed() | ||
} | ||
} |