ziv kesten
03/03/2022, 9:46 AMTim Malseed
03/03/2022, 10:29 AMlike this
Which makes it a bit easier for us to read your code.
Can you show us where trackProgress
is referenced? I can see the slider, but I can’t see why the Card would recompose, because I can’t see what code surrounds your Card
ziv kesten
03/03/2022, 10:35 AM@Composable
fun AudioTrackView(viewModel: VoiceRecordingViewModel){
Row(...) {
PlayPauseButton() { viewModel.clickAction() }
Slider(
value = viewModel.trackProgress,
valueRange = 0f..duration,
modifier = Modifier
.weight(1f)
.fillMaxWidth()
onValueChange = { newValue ->
viewModel.goToTrackPosition(newValue)
},
)
Text(...)
TrashIcon()
}
}
ziv kesten
03/03/2022, 10:35 AMtrackProgress
which is streamed from the view model is given as the value of the sliderTim Malseed
03/03/2022, 10:38 AMAudioTrackView
here. I don’t see why viewModel.trackProgress
would cause thisTim Malseed
03/03/2022, 10:38 AMAudioTrackView
?Tim Malseed
03/03/2022, 10:39 AMviewModel.goToTrackPosition()
?ziv kesten
03/03/2022, 10:39 AMziv kesten
03/03/2022, 10:41 AMTim Malseed
03/03/2022, 10:42 AMAudioTrackView
?ziv kesten
03/03/2022, 10:42 AMziv kesten
03/03/2022, 10:46 AMfun VoiceRecordInput(viewModel: VoiceRecordingViewModel) {
Column(...)
{
Text(...)
Text(...)
LaunchedEffect(viewModel) {
snapshotFlow {
viewModel.items.firstOrNull { it.state.isIdle && !it.state.targetState }
}.collect {
if (it != null) {
viewModel.cleanInvisibleItems()
}
}
}
LazyColumn(
content = {
items(
items = viewModel.items,
itemContent = { item ->
AudioTrackView(viewModel, item.audioTrack)
}
)
}
)
Box(...)
Text(...)
Button(...)
}
}
ziv kesten
03/03/2022, 10:47 AMTim Malseed
03/03/2022, 10:48 AMTim Malseed
03/03/2022, 10:49 AMTim Malseed
03/03/2022, 10:49 AMTim Malseed
03/03/2022, 10:50 AMLogCompositions
to your composables, with a different tag for each one, you can narrow down where your excessive recomposition is coming from.Tim Malseed
03/03/2022, 10:50 AMziv kesten
03/03/2022, 10:51 AMziv kesten
03/03/2022, 11:19 AMPlayPauseButton() { viewModel.clickAction() }
that contains an AnimatedVisibility
component, i am still investigating but appreciate the help, i hep post my findings here.Tim Malseed
03/03/2022, 11:22 AMTim Malseed
03/03/2022, 11:23 AMTim Malseed
03/03/2022, 11:24 AMMutableInteractionSource()
, but instead use
remember { MutableInteractionSource() }
Tim Malseed
03/03/2022, 11:24 AMziv kesten
03/03/2022, 11:26 AMziv kesten
03/03/2022, 11:26 AMAnimatedVisibility
Tim Malseed
03/03/2022, 11:30 AMziv kesten
03/03/2022, 11:34 AM@ExperimentalAnimationApi
@Composable
private fun AnimatedVisibilityWrapper(
modifier: Modifier,
visible: Boolean,
rotation: Float,
onClick: () -> Unit,
content: @Composable () -> Unit
) {
LogCompositions(tag = "AnimatedVisibilityWrapper")
AnimatedVisibility(
visible = visible,
enter = fadeIn(
animationSpec = tween(delayMillis = 50, durationMillis = 300, easing = FastOutLinearInEasing)
),
exit = fadeOut(
animationSpec = tween(delayMillis = 50, durationMillis = 300, easing = FastOutLinearInEasing)
)
) {
Card(
backgroundColor = Color(255, Random.nextInt(0, 255), Random.nextInt(0, 255), Random.nextInt(0, 255)),
elevation = 0.dp,
modifier = modifier.then(
Modifier
.fillMaxSize()
.graphicsLayer { rotationZ = rotation }
.clickable(
interactionSource = MutableInteractionSource(),
indication = rememberRipple(
radius = 20.dp,
bounded = false
)
) {
onClick()
},
)
) { content() }
}
}
ziv kesten
03/03/2022, 11:34 AMAnimatedVisibilityWrapper(
modifier = Modifier.align(Center),
visible = !isPlaying,
rotation = animateFloatAsState(targetValue = if (isPlaying) 180f else 0f).value,
onClick = { viewModel.playClicked(audioTrack.id) }
) {
Icon(
painterResource(id = R.drawable.ic_play),
modifier = Modifier.align(Center),
contentDescription = "Localized description",
tint = colorResource(id = R.color.lemonade_pink)
)
}
ziv kesten
03/03/2022, 11:35 AMisPlaying
is
val isPlaying = viewModel.playing(audioTrack.id)
Tim Malseed
03/03/2022, 11:41 AMi tried to post only relevant code as much as possibleYes, fair enough haha
Tim Malseed
03/03/2022, 11:41 AMTim Malseed
03/03/2022, 11:42 AMziv kesten
03/03/2022, 11:42 AMziv kesten
03/03/2022, 11:42 AMziv kesten
03/03/2022, 11:43 AMTim Malseed
03/03/2022, 11:46 AMTim Malseed
03/03/2022, 11:47 AMziv kesten
03/03/2022, 11:47 AMziv kesten
03/03/2022, 11:47 AMziv kesten
03/03/2022, 11:48 AMTim Malseed
03/03/2022, 11:48 AMTim Malseed
03/03/2022, 11:48 AMTim Malseed
03/03/2022, 11:49 AMziv kesten
03/03/2022, 11:49 AMziv kesten
03/03/2022, 11:49 AMTim Malseed
03/03/2022, 11:50 AMziv kesten
03/03/2022, 11:51 AMziv kesten
03/03/2022, 11:51 AMTim Malseed
03/03/2022, 11:52 AMziv kesten
03/03/2022, 11:53 AMziv kesten
03/03/2022, 1:44 PMmyanmarking
03/03/2022, 3:01 PMziv kesten
03/03/2022, 3:03 PMmyanmarking
03/03/2022, 3:05 PMmyanmarking
03/03/2022, 3:08 PMziv kesten
03/03/2022, 3:12 PMmyanmarking
03/03/2022, 3:19 PMSurface(
modifier = Modifier
.fillMaxSize(),
color = MaterialTheme.colors.background
) {
var value by remember {
mutableStateOf(0f)
}
LaunchedEffect(key1 = Unit) {
while (true) {
delay(100)
value += 1f
}
}
Row {
Button(onClick = {
Log.i("TAG", "Clicked")
}) {
Text(text = "Button: $value")
}
Slider(value = value, onValueChange = {}, valueRange = 0f..1000f)
}
}
Quick test with a similar sample, it works as expected even when it is recomposing the button. hm .. interestingmyanmarking
03/03/2022, 3:19 PMmyanmarking
03/03/2022, 3:20 PMmyanmarking
03/03/2022, 3:22 PMziv kesten
03/03/2022, 3:27 PMmyanmarking
03/03/2022, 3:28 PMmyanmarking
03/03/2022, 3:28 PMziv kesten
03/03/2022, 3:29 PM