-
Notifications
You must be signed in to change notification settings - Fork 61
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
Fix iOS lifecycle #660
Fix iOS lifecycle #660
Changes from all commits
225c983
4b3c47a
7df9251
5caaf98
3465f6e
794daa2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ Please refer to [2.0.0-alpha10 – Migration guide](2.0.0-alpha10.md) | |
- [#654](https://github.com/bumble-tech/appyx/pull/654) - Renamings | ||
- [#657](https://github.com/bumble-tech/appyx/pull/657) - Rename ParentNode & Node to Node and LeafNode | ||
- [#644](https://github.com/bumble-tech/appyx/pull/644) – Refactor AppyxComponent and application of draggable modifier | ||
- [#660](https://github.com/bumble-tech/appyx/pull/660) - Make IosNodeHost to receive a Lifecycle class to fix iOS lifecycle problems | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this to pending changes, alpha10 is already released |
||
|
||
### Fixed | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.bumble.appyx.navigation.platform | ||
|
||
import com.bumble.appyx.navigation.lifecycle.Lifecycle | ||
|
||
class LifecycleHelper { | ||
val lifecycle: PlatformLifecycleRegistry = PlatformLifecycleRegistry() | ||
|
||
fun created() { | ||
lifecycle.setCurrentState(Lifecycle.State.CREATED) | ||
} | ||
|
||
fun resumed() { | ||
lifecycle.setCurrentState(Lifecycle.State.RESUMED) | ||
} | ||
|
||
fun started() { | ||
lifecycle.setCurrentState(Lifecycle.State.STARTED) | ||
} | ||
|
||
fun destroyed() { | ||
lifecycle.setCurrentState(Lifecycle.State.DESTROYED) | ||
} | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: fix indentation |
||
switch newPhase { | ||
case .background: appDelegate.lifecycleHolder.lifecycleHelper.created() | ||
case .inactive: appDelegate.lifecycleHolder.lifecycleHelper.created() | ||
case .active: appDelegate.lifecycleHolder.lifecycleHelper.resumed() | ||
@unknown default: break | ||
} | ||
zsoltk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
} | ||
|
||
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() | ||
} | ||
} |
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 | ||
} | ||
} | ||
} | ||
Comment on lines
+21
to
29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: fix indentation |
||
} | ||
} | ||
} | ||
|
||
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() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to surround code related names with
`