Skip to content

Instantly share code, notes, and snippets.

View PiotrPrus's full-sized avatar
🏠
Working from home

Piotr Prus PiotrPrus

🏠
Working from home
View GitHub Profile
@Composable
fun MapSnapshot(map: MapView, location: LatLng) {
val mapBitmap: MutableState<Bitmap?> = remember { mutableStateOf(null) }
val coroutineScope = rememberCoroutineScope()
if (mapBitmap.value != null) {
Image(
bitmap = mapBitmap.value!!.asImageBitmap(),
contentDescription = "Map snapshot",
@PiotrPrus
PiotrPrus / MapBoxUtils.kt
Created July 6, 2022 14:24
Some mapbox functions needed to use mapBox in Compose
import android.os.Bundle
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import com.mapbox.mapboxsdk.maps.MapView
import com.mapbox.mapboxsdk.maps.MapboxMap
kotlin {
android()
ios {
binaries {
framework {
baseName = "shared"
export(project(":sharedResources"))
export(Deps.Resources.core)
}
plugins {
kotlin("multiplatform")
id("com.android.library")
id("dev.icerock.mobile.multiplatform-resources")
}
kotlin {
android()
iosArm64()
iosX64()
@PiotrPrus
PiotrPrus / motion_scene_box.xml
Created February 21, 2020 23:04
xml scene to demonstrate onClick and onSwipe transitions not working in motionLayout beta4
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetStart="@id/start"
app:constraintSetEnd="@id/end"
app:duration="1000">
<OnSwipe
app:dragDirection="dragDown"
val barAreas = list.mapIndexed { index, item ->
BarArea(
index = index,
data = item,
xStart = horizontalPadding + distance.times(index) - distance.div(2),
xEnd = horizontalPadding + distance.times(index) + distance.div(2)
)
}
@Test
fun cancelSelectionOfThirdElement() {
val list = mutableStateOf(listOf(1, 2, 3, 4, 5, 6, 7, 8))
val selectedItem = mutableStateOf(list.value.first())
val distance = with(composeTestRule.density) { (12.dp + 20.dp.times(3)).toPx() }
composeTestRule.setContent {
BarChartCanvas(list = list.value, barSelected = { selectedItem.value = it })
}
composeTestRule.onNodeWithTag(testTag = "BarChart")
.performGesture { down(Offset(distance, 1f)) }
@Test
fun clickOnThirdElementOfList() {
val list = mutableStateOf(listOf(1, 2, 3, 4, 5, 6, 7, 8))
val selectedItem = mutableStateOf(list.value.first())
val distance = with(composeTestRule.density) { (12.dp + 20.dp.times(3)).toPx() }
composeTestRule.setContent {
BarChartCanvas(list = list.value, barSelected = { selectedItem.value = it })
}
composeTestRule.onNodeWithTag(testTag = "BarChart")
.performGesture { click(position = Offset(distance, 1f)) }
@get:Rule
val composeTestRule = createComposeRule()
@Test
fun checkCanvasExistence() {
val list = mutableStateOf(listOf(1, 2, 3, 4, 5, 6, 7, 8))
composeTestRule.setContent {
BarChartCanvas(list = list.value, barSelected = { })
}
composeTestRule.onNodeWithTag(testTag = "BarChart").assertExists()
Modifier.tapOrPress(
onStart = { position ->
scope.launch {
selectedBar?.let { selected ->
if (position in selected.xStart..selected.xEnd) {
// click in selected area - do nothing
} else {
tempPosition = position
scope.launch {
tempAnimatable.snapTo(0f)