Skeptick
06/29/2020, 5:58 AMUIViewController
. More specifically, working with Lifecycle, subscription for state changes and sending events.
If I just copy LifecycleRegistryExt
and LifecycleWrapper
and do:
override func viewDidLoad() {
self.viewLifecycle = LifecycleRegistry()
self.controller?.controller.onViewCreated(...)
self.controller?.lifecycle.start()
}
override func viewDidAppear(_ animated: Bool) {
self.viewLifecycle?.resume()
}
override func viewDidDisappear(_ animated: Bool) {
self.viewLifecycle?.destroy()
}
deinit {
self.controller?.lifecycle.stop()
}
Would this be the right approach?aiidziis
06/29/2020, 6:02 AMviewDidAppear -> resume
viewDidDisappear -> stop
deinit -> destroy
aiidziis
06/29/2020, 6:04 AMSkeptick
06/29/2020, 6:05 AMaiidziis
06/29/2020, 6:05 AMUIViewController
events.aiidziis
06/29/2020, 6:07 AMhttps://static.packt-cdn.com/products/9781783550814/graphics/0814OT_06_02.jpg▾
Skeptick
06/29/2020, 6:13 AMViewLifecycle
with the life cycle of the viewaiidziis
06/29/2020, 6:15 AMdeinit
is called when object instance is deallocated.Skeptick
06/29/2020, 6:17 AMviewDidUnload
is deprecated, and I don’t know a more suitable method than deinit
to signal that a screen no longer exists.aiidziis
06/29/2020, 6:20 AMonStop
should happen before onDestroy
, because onStop
signals that View
is no longer visible, but onDestroy
signals that View
no longer exists.aiidziis
06/29/2020, 6:21 AMonDestroy
in viewDidDisappear
, but as you see in UIViewController
lifecycle it can reappear.aiidziis
06/29/2020, 6:22 AMonResume
and lifecycle will be messed up.Skeptick
06/29/2020, 6:23 AMaiidziis
06/29/2020, 6:23 AMonStart -> onResume -> onDestroy -> onStop
aiidziis
06/29/2020, 6:25 AMArkadii Ivanov
06/29/2020, 10:05 AMLifecycle
object for both controller and view. A similar (an MVI-ish approach, not MVIKotlin) sample can be found here: https://github.com/badoo/Reaktive/blob/master/sample-ios-app/sample-ios-app/ViewController.swift
So the mapping is as follows:
viewDidLoad
-> onViewCreated
videWillAppear
-> onStart
viewWillDisappear
-> onStop
deinit
-> onViewDestroy
+ onDestroy
This is because in swift UI view can be destroyed when moved to backstack onDesappear
, but its Controller
is not destroyed and will be reused later.
In UIKit there is no such a behaviour.Skeptick
06/29/2020, 11:03 AM