This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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)) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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)) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val animatable = remember { Animatable(0f) } | |
... | |
//Modifier.tapOrPress | |
onCompleted = { | |
scope.launch { | |
selectedPosition = it | |
animatable.snapTo(1f) | |
} | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var selectedPosition by remember { mutableStateOf(0) } | |
val selectedBar by remember(selectedPosition, barAreas) { | |
derivedStateOf { | |
barAreas.find { it.xStart < selectedPosition && selectedPosition < it.xEnd } | |
} | |
} | |
Modifier.tapOrPress( | |
onStart = { }, | |
onCancel = { }, |
NewerOlder