AndroidJetpackCompose中使用ModalBottomSheet导致内存泄漏。
创始人
2024-10-08 11:36:13
0

在使用 ModalBottomSheet 的时候,应该在 Compose 中使用 State 来控制 bottom sheet 的打开和关闭。同时,也需要在 bottom sheet 关闭时手动清空 bottom sheet 内部的 Composable。以下是示例代码:

@Composable fun MyScreen() { // State,用来控制 bottom sheet 的打开和关闭状态 val bottomSheetState = rememberModalBottomSheetState(...)

// 打开 bottom sheet
Button(onClick = { bottomSheetState.show() }) {
    Text("Show Bottom Sheet")
}

ModalBottomSheetLayout(
    sheetState = bottomSheetState,
    sheetContent = {
        // bottomSheetContent,显示 bottom sheet 内容
        val bottomSheetContent = remember { mutableStateOf(...) }
        // 关闭 bottom sheet 时清空内部 Composable
        bottomSheetState.onDismissed { bottomSheetContent.value = null }
        // 显示 bottom sheet 内容
        bottomSheetContent.value?.let { content -> Content(content) }
    },
    content = {
        // 主界面内容
        ...
    }
)

}

相关内容

热门资讯

事发当天"德扑圈透视... 事发当天"德扑圈透视"wpk辅助购买(竟然存在有辅助平台)-哔哩哔哩在进入wpk辅助购买软件靠谱后,...
透视挂"wepoke... 透视挂"wepoker私人局俱乐部辅助"werplan外卦神器(一直是有辅助安装)-哔哩哔哩1、操作...
针对"pokemmo... 针对"pokemmo脚本辅助"wepoker钻石怎么看底牌(竟然有辅助插件)-哔哩哔哩1、超多福利:...
透视辅助"wepok... 透视辅助"wepoker透视挂底牌"wepoker透视最简单三个步骤(其实有辅助app)-哔哩哔哩1...
连日来"哈糖大菠萝可... 连日来"哈糖大菠萝可以开挂吗"德州透视是真的假的(一贯是有辅助平台)-哔哩哔哩哈糖大菠萝可以开挂吗透...
推出新举措"wepo... 推出新举措"wepoker国外版透视"wpk透视怎么安装(其实是有辅助app)-哔哩哔哩1、wepo...
有玩家发现"hhpo... 有玩家发现"hhpoker辅助软件是真的么"wepoker辅助分析器(一贯存在有辅助神器)-哔哩哔哩...
今天下午"wepok... 今天下午"wepoker破解器"wepoker开辅助能查到吗(切实真的是有辅助工具)-哔哩哔哩一、w...
近日"hhpoker... 近日"hhpoker辅助器"德普之星怎么设置埋牌(总是真的有辅助神器)-哔哩哔哩1、完成德普之星怎么...
最终"wepoker... 最终"wepoker怎么开辅助"pokemmo内置修改器(竟然是有辅助软件)-哔哩哔哩1、进入游戏-...