icerockdev / moko-geo

Geolocation access for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
152 stars 16 forks source link

please add compose sample. #43

Open yangwuan55 opened 5 months ago

yangwuan55 commented 5 months ago

Thanks.

clauub commented 5 months ago

@yangwuan55 did you find any compose sample? I needed some too. But I've managed to figure out how to make it work on compose

yangwuan55 commented 5 months ago

@yangwuan55 did you find any compose sample? I needed some too. But I've managed to figure out how to make it work on compose

You can do like this:


        val facotry = rememberLocationTrackerFactory(LocationTrackerAccuracy.Best)
        val locationTracker = facotry.createLocationTracker(getPermissionController())
        BindLocationTrackerEffect(locationTracker)

        val viewModel = getScreenModel<SomeViewModel>()
        LaunchedEffect(locationTracker) {
            viewModel.init(locationTracker)
        }

In viewmodel:

suspend fun init(locationTracker: LocationTracker) {
        this.locationTracker = locationTracker
        locationTracker.startTracking()
}

fun onCleared() {
       locationTracker.stopTracking()
}
ishaangarg commented 4 months ago
    val locationTracker = facotry.createLocationTracker(getPermissionController())

could be val locationTracker = remember { facotry.createLocationTracker(getPermissionController()) } to avoid recomps

rahulhundekari commented 1 month ago

@yangwuan55 what does this method contains? getPermissionController() How it will be collected from Android and iOS?

yangwuan55 commented 1 month ago

@yangwuan55 what does this method contains? getPermissionController() How it will be collected from Android and iOS?

see here https://github.com/icerockdev/moko-permissions