@@ -7,7 +7,7 @@ import androidx.lifecycle.DefaultLifecycleObserver
7
7
import androidx.lifecycle.Lifecycle
8
8
import androidx.lifecycle.LifecycleOwner
9
9
import androidx.lifecycle.LifecycleRegistry
10
- import androidx.lifecycle.ViewTreeLifecycleOwner
10
+ import androidx.lifecycle.setViewTreeLifecycleOwner
11
11
import com.mapbox.bindgen.Value
12
12
import com.mapbox.common.SettingsServiceFactory
13
13
import com.mapbox.common.SettingsServiceStorageType
@@ -67,22 +67,18 @@ class MapboxMapController(
67
67
/*
68
68
Mirrors lifecycle of the parent, with one addition - switches to DESTROYED state
69
69
when `dispose` is called.
70
- `parentLifecycle ` is the lifecycle of the Flutter activity, which may live much longer then
70
+ `lifecycle ` is the lifecycle of the Flutter activity, which may live much longer then
71
71
the MapView attached.
72
72
*/
73
73
private class LifecycleHelper (
74
- val parentLifecycle : Lifecycle ,
74
+ override val lifecycle : Lifecycle ,
75
75
val shouldDestroyOnDestroy : Boolean ,
76
76
) : LifecycleOwner, DefaultLifecycleObserver {
77
77
78
78
val lifecycleRegistry: LifecycleRegistry = LifecycleRegistry (this )
79
79
80
80
init {
81
- parentLifecycle.addObserver(this )
82
- }
83
-
84
- override fun getLifecycle (): Lifecycle {
85
- return lifecycleRegistry
81
+ lifecycle.addObserver(this )
86
82
}
87
83
88
84
override fun onCreate (owner : LifecycleOwner ) {
@@ -108,7 +104,7 @@ class MapboxMapController(
108
104
override fun onDestroy (owner : LifecycleOwner ) = propagateDestroyEvent()
109
105
110
106
fun dispose () {
111
- parentLifecycle .removeObserver(this )
107
+ lifecycle .removeObserver(this )
112
108
propagateDestroyEvent()
113
109
}
114
110
@@ -173,14 +169,14 @@ class MapboxMapController(
173
169
}
174
170
lifecycleHelper = LifecycleHelper (lifecycleProvider.getLifecycle()!! , shouldDestroyOnDestroy)
175
171
176
- mapView?.let { ViewTreeLifecycleOwner .set(it, lifecycleHelper) }
172
+ mapView?.setViewTreeLifecycleOwner( lifecycleHelper)
177
173
}
178
174
179
175
override fun onFlutterViewDetached () {
180
176
super .onFlutterViewDetached()
181
177
lifecycleHelper?.dispose()
182
178
lifecycleHelper = null
183
- ViewTreeLifecycleOwner .set( mapView!! , null )
179
+ mapView!! .setViewTreeLifecycleOwner( null )
184
180
}
185
181
186
182
override fun dispose () {
@@ -251,4 +247,4 @@ class MapboxMapController(
251
247
SettingsServiceFactory .getInstance(SettingsServiceStorageType .NON_PERSISTENT )
252
248
.set(" com.mapbox.common.telemetry.internal.custom_user_agent_fragment" , Value .valueOf(" FlutterPlugin/$version " ))
253
249
}
254
- }
250
+ }
0 commit comments