Skip to content

Commit

Permalink
Fix flutter 3.24
Browse files Browse the repository at this point in the history
  • Loading branch information
tranhuongk committed Aug 11, 2024
1 parent 019aabe commit 14ddb3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ dependencies {
implementation "com.mapbox.maps:android:11.6.0-rc.1"

implementation "androidx.annotation:annotation:1.7.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.8.4"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import androidx.lifecycle.ViewTreeLifecycleOwner
import androidx.lifecycle.setViewTreeLifecycleOwner
import com.mapbox.bindgen.Value
import com.mapbox.common.SettingsServiceFactory
import com.mapbox.common.SettingsServiceStorageType
Expand Down Expand Up @@ -67,22 +67,18 @@ class MapboxMapController(
/*
Mirrors lifecycle of the parent, with one addition - switches to DESTROYED state
when `dispose` is called.
`parentLifecycle` is the lifecycle of the Flutter activity, which may live much longer then
`lifecycle` is the lifecycle of the Flutter activity, which may live much longer then
the MapView attached.
*/
private class LifecycleHelper(
val parentLifecycle: Lifecycle,
override val lifecycle: Lifecycle,
val shouldDestroyOnDestroy: Boolean,
) : LifecycleOwner, DefaultLifecycleObserver {

val lifecycleRegistry: LifecycleRegistry = LifecycleRegistry(this)

init {
parentLifecycle.addObserver(this)
}

override fun getLifecycle(): Lifecycle {
return lifecycleRegistry
lifecycle.addObserver(this)
}

override fun onCreate(owner: LifecycleOwner) {
Expand All @@ -108,7 +104,7 @@ class MapboxMapController(
override fun onDestroy(owner: LifecycleOwner) = propagateDestroyEvent()

fun dispose() {
parentLifecycle.removeObserver(this)
lifecycle.removeObserver(this)
propagateDestroyEvent()
}

Expand Down Expand Up @@ -173,14 +169,14 @@ class MapboxMapController(
}
lifecycleHelper = LifecycleHelper(lifecycleProvider.getLifecycle()!!, shouldDestroyOnDestroy)

mapView?.let { ViewTreeLifecycleOwner.set(it, lifecycleHelper) }
mapView?.setViewTreeLifecycleOwner(lifecycleHelper)
}

override fun onFlutterViewDetached() {
super.onFlutterViewDetached()
lifecycleHelper?.dispose()
lifecycleHelper = null
ViewTreeLifecycleOwner.set(mapView!!, null)
mapView!!.setViewTreeLifecycleOwner(null)
}

override fun dispose() {
Expand Down Expand Up @@ -251,4 +247,4 @@ class MapboxMapController(
SettingsServiceFactory.getInstance(SettingsServiceStorageType.NON_PERSISTENT)
.set("com.mapbox.common.telemetry.internal.custom_user_agent_fragment", Value.valueOf("FlutterPlugin/$version"))
}
}
}

0 comments on commit 14ddb3d

Please sign in to comment.