构成关于变化值的不令人耳目一新的视图

发布于 2025-01-29 02:55:29 字数 551 浏览 3 评论 0原文

我在属性

var uistate(uistate(uistate())

我有一个可访问此值的可访问该值

fun AppView(viewModel: BridgeViewModel) {
    val uiState = viewModel.uiState

    when {
        uiState.isLoading -> {
            LoadingView()
        }
        uiState.data != null -> {
            TextToShareView(to = uiState.data)
        }
    }
}

之后,我在创建合并后,我在ViewModel中触发一个函数,以更改状态,就像更改状态一样因此,

uistate = uistate(isloading = true)

问题是,当我更改状态值时,可以重新缩放可合件。

有什么想法吗?我看不出这与文档中的官方样本有何不同。

I have a ViewModel with the property

var uiState by mutableStateOf(UiState())

I have a composable that accesses this value like so

fun AppView(viewModel: BridgeViewModel) {
    val uiState = viewModel.uiState

    when {
        uiState.isLoading -> {
            LoadingView()
        }
        uiState.data != null -> {
            TextToShareView(to = uiState.data)
        }
    }
}

After the composable is created I trigger a function in my ViewModel that changes the state like so

uiState = UiState(isLoading = true)

The problem is, the composable is not being redrawn when I change the value of state.

Any idea? I can't see how this is different to the official sample in the docs.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文