我已经开始在我的项目中使用合成。我面临着问题,不知道如何解决它。我有一个列表的照片。当我点击照片,我显示在全屏与此照片对话框。在照片上,我有关闭图标。当我点击关闭图标,对话框关闭。但如果我再次想显示此对话框,它不显示。我的代码:
@Composable
fun AnimalImagies(photoUrl: String) {
var dialogOpen by remember {
mutableStateOf(false)
}
if(dialogOpen){
GetBifImage(photoUrl = photoUrl)
}
val imageLoader = LocalContext.current.imageLoader.newBuilder()
.logger(DebugLogger())
.build()
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(photoUrl)
.crossfade(true)
.build(),
imageLoader = imageLoader,
contentDescription = "",
contentScale = ContentScale.Crop,
modifier = Modifier
.size(140.dp)
.clip(RoundedCornerShape(corner = CornerSize(16.dp)))
.clickable(onClick = { dialogOpen = true })
)
}
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun GetBifImage(photoUrl: String) {
val shouldShowDialog = remember { mutableStateOf(true) }
if (shouldShowDialog.value) {
Dialog(
properties = DialogProperties(usePlatformDefaultWidth = false),
onDismissRequest = {shouldShowDialog.value = false}
) {
Box(modifier = Modifier.fillMaxSize()) {
ZoomImage(photoUrl)
Image(painter = painterResource(id = R.drawable.ic_close_),
contentDescription = "",
modifier = Modifier
.align(Alignment.TopEnd)
.size(30.dp)
.clickable { shouldShowDialog.value=false }
)
}
}
}
}
1条答案
按热度按时间tf7tbtn21#
您需要将
shouldShowDialog
的状态重置为true
。我建议您创建一个lambda to
GetBifImage
组合如下:因此,您需要修改对
AnimalImagies
的调用现在当你点击
Image
,lambda函数会改变dialogOpen