qdsfdhvh/compose-imageloader

picture can't be reload automatic when data changed

Closed this issue · 2 comments

request help, refer this 动图.

@Composable
fun VideoItem(modifier: Modifier, vod: Vod, showSite: Boolean, click: (Vod) -> Unit) {
    Card(
        modifier = modifier
            .clickable(enabled = true, onClick = { click(vod) }),
        elevation = 8.dp,
        shape = RoundedCornerShape(8.dp)
    ) {
        Box(modifier = modifier) {
            AutoSizeImage(url = vod.vodPic!!,
                modifier = Modifier.height(220.dp),
                contentDescription = vod.vodName,
                contentScale = ContentScale.Crop,
                placeholderPainter = { painterResource("empty.png") },
                errorPainter = { painterResource("empty.png") })
            Text(
                text = vod.vodName!!,
                modifier = Modifier.background(Color.DarkGray.copy(alpha = 0.6F)).align(Alignment.BottomCenter)
                    .fillMaxWidth().padding(0.dp, 10.dp),
                color = darkColors().onBackground, maxLines = 1, softWrap = true,
                overflow = TextOverflow.Ellipsis, style = TextStyle(textAlign = TextAlign.Center)
            )
        }
        Text(
            modifier = Modifier
                .clip(RoundedCornerShape(3.dp))
                .width(10.dp)
                .padding(5.dp),
            text = if (showSite) vod.site?.name ?: "" else vod.vodRemarks!!,
            fontWeight = FontWeight.Bold,
            style = TextStyle(
                color = Color.White,
                shadow = Shadow(Color.Black, offset = Offset(2F, 2F), blurRadius = 1.5F)
            )
        )
    }
}```


@composable
fun videoScene(modifier: Modifier, onClickSearch: () -> Unit, onClickSetting: () -> Unit) {
val scope = rememberCoroutineScope()
val snackbarHostState = SnackbarHostState()
val scaffoldState = rememberScaffoldState(snackbarHostState = snackbarHostState)
val state = rememberLazyGridState()
val adapter = rememberScrollbarAdapter(state)

LaunchedEffect("homeLoad") {
    homeLoad()
}

val canLoad = rememberUpdatedState(state.canScrollForward)
DisposableEffect(canLoad.value){
    if(!canLoad.value){
        showProgress()
        SiteViewModel.viewModelScope.launch {
            try {
                if(currentClass == null || currentClass?.typeId == "home") return@launch
                 SiteViewModel.categoryContent(api?.home?.value?.key ?: "", currentClass?.typeId, page++.toString(), true, HashMap())
                val list = SiteViewModel.result.value?.list
                if(list?.isNotEmpty() == true){
                    val vodList = homeVodResult?.toMutableList()
                    vodList?.addAll(list)
                    homeVodResult = vodList?.toList()?.toMutableList()
                }
            } finally {
                hideProgress()
            }
        }
    }
    onDispose {}
}

var showChooseHome by remember { mutableStateOf(false) }
var showDetailDialog by remember { mutableStateOf(false) }

var chooseVod by remember { mutableStateOf<Vod?>(null) }
Scaffold(
    scaffoldState = scaffoldState,
    topBar = {
        VideoTopBar(
            onClickSearch = { onClickSearch() },
            onClickChooseHome = { showChooseHome = true },
            onClickSetting = { onClickSetting() })
    }
) {
    Box(modifier = modifier.fillMaxSize()) {
        if (homeVodResult?.isEmpty() == true) {
            Image(
                modifier = modifier.align(Alignment.Center),
                painter = androidx.compose.ui.res.painterResource("nothing.png"),
                contentDescription = "nothing here",
                contentScale = ContentScale.Crop
            )
        } else {
            Column {
                if (classList.isNotEmpty()) {
                    ClassRow(classList){
                        scope.launch {
                            state.animateScrollToItem(0)
                        }
                    }
                }
                LazyVerticalGrid(
                    modifier = modifier.padding(15.dp),
                    columns = GridCells.Adaptive(140.dp),
                    contentPadding = PaddingValues(5.dp),
                    state = state,
                    verticalArrangement = Arrangement.spacedBy(10.dp),
                    horizontalArrangement = Arrangement.spacedBy(10.dp),
                    userScrollEnabled = true
                ) {
                    itemsIndexed(homeVodResult ?: listOf()) { _, item ->
                        VideoItem(Modifier, item, false) {
                            chooseVod = it
                            showDetailDialog = true
                        }
                    }
                }
            }
            VerticalScrollbar(
                adapter, modifier = Modifier.align(Alignment.CenterEnd),
                style = defaultScrollbarStyle().copy(
                    unhoverColor = Color.DarkGray.copy(0.3F),
                    hoverColor = Color.DarkGray
                )
            )
        }
        DetailDialog(showDetailDialog, chooseVod, api?.home?.value?.key ?: "") { showDetailDialog = false }
        ChooseHomeDialog(showChooseHome, onClose = { showChooseHome = false }){
            scope.launch {
                state.animateScrollToItem(0)
            }
        }
    }
}

}

Hi, I tried to simulate the problem #441, but I didn't get the bug, if possible, can you give me a demo?

Hi, I tried to simulate the problem #441, but I didn't get the bug, if possible, can you give me a demo?

demo.zip
here is. (●'◡'●)