Klicken Sie zuerst auf Lazylist, funktioniert nicht nur an zweiter StelleAndroid

Forum für diejenigen, die für Android programmieren
Anonymous
 Klicken Sie zuerst auf Lazylist, funktioniert nicht nur an zweiter Stelle

Post by Anonymous »

Ich habe einen Bildschirm mit komponierbarer Funktion mit Lazyrow im Inneren. . Und - Erster Klick fängt nicht Onclick Block ein. Was mache ich falsch? < /P>

Code: Select all

@Composable
fun RoommsScreenPart(
modifier: Modifier = Modifier,
uiState: State
) {
val state = rememberLazyListState()
var canScrolling by remember { mutableStateOf(true) }
val density = LocalDensity.current

Box(modifier = modifier) {
if (uiState.items.isNotEmpty()) {
Column {
Text(
text = "Title",
style = AppTheme.typography.title2,
color = AppTheme.colorScheme.onSurface
)

LazyRow(
modifier = Modifier.clickable { canScrolling = false },
state = state,
userScrollEnabled = true,
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(Dp8)
) {
items(
count = Int.MAX_VALUE,
itemContent = {
val index = it % uiState.items.size
Roomm(uiState.items[index])
}
)
}
}
}

LaunchedEffect(Unit) {
snapshotFlow { canScrolling }
.collect {
if (it) {
while (true) {
val needToScrollItems =
uiState.items.size - state.layoutInfo.visibleItemsInfo.size + 1
state.animateScrollBy(
value = needToScrollItems * with(density) { Dp40.toPx() },
animationSpec = tween(
durationMillis = 4000 * needToScrollItems,
easing = LinearEasing
)
)
delay(100)
}
}
}
}
LaunchedEffect(Unit) {
snapshotFlow { canScrolling }
.collect {
if (!it) {
delay(5000)
canScrolling = true
}
}
}
}
}

< /code>
Lazylistelement < /p>
@Composable
private fun Roomm(item: Item) {
Box(
modifier = Modifier
.fillMaxHeight()
.aspectRatio(1f)
.clip(RoundedCornerShape(Dp12))
) {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(item.photoLink)
.crossfade(true)
.error(R.drawable.room_large)
.build(),
contentScale = ContentScale.Crop,
contentDescription = null,
modifier = Modifier.fillMaxSize(),
)
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post