Skip to content

Commit

Permalink
remove MapKit.bindToComposition, YandexMapController.bindToCompositio…
Browse files Browse the repository at this point in the history
…n and make YandexMapController.bindToLifecycleOwner internal
  • Loading branch information
SuLG-ik committed Jun 25, 2024
1 parent 7278728 commit 3940cee
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import kotlinx.coroutines.launch
import ru.sulgik.mapkit.Animation
import ru.sulgik.mapkit.compose.YandexMap
import ru.sulgik.mapkit.compose.YandexMapController
import ru.sulgik.mapkit.compose.bindToComposition
import ru.sulgik.mapkit.compose.bindToLifecycleOwner
import ru.sulgik.mapkit.compose.imageProvider
import ru.sulgik.mapkit.compose.rememberAndInitializeMapKit
Expand Down Expand Up @@ -149,7 +148,6 @@ fun MapScreen(modifier: Modifier = Modifier) {
Box(
modifier = Modifier.fillMaxSize(),
) {
mapController.bindToComposition()
YandexMap(
controller = mapController,
modifier = Modifier.fillMaxSize(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.sulgik.mapkit.compose

import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.LifecycleOwner
Expand All @@ -24,12 +23,4 @@ fun MapKit.bindToLifecycleOwner(lifecycleOwner: LifecycleOwner = LocalLifecycleO
onStop = this::onStop,
onDispose = this::onStop,
)
}

@Composable
fun MapKit.bindToComposition() {
DisposableEffect(this) {
onStart()
onDispose(::onStop)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ fun YandexMap(
controller: YandexMapController = rememberYandexMapController(),
modifier: Modifier = Modifier,
) {
controller.bindToLifecycleOwner()
NativeYandexMap(controller, modifier)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.sulgik.mapkit.compose

import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.LifecycleOwner
import ru.sulgik.mapkit.compose.utils.LifecycleEffect
Expand All @@ -25,19 +24,11 @@ class YandexMapController internal constructor(val mapView: MapView) {
}

@Composable
fun YandexMapController.bindToLifecycleOwner(lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current) {
internal fun YandexMapController.bindToLifecycleOwner(lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current) {
LifecycleEffect(
lifecycleOwner = lifecycleOwner,
onStart = mapView::onStart,
onStop = mapView::onStop,
onDispose = mapView::onStop,
)
}

@Composable
fun YandexMapController.bindToComposition() {
DisposableEffect(this) {
mapView.onStart()
onDispose(mapView::onStop)
}
}

0 comments on commit 3940cee

Please sign in to comment.