You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AndroidFragment与CircularProgressIndicator混合使用导致点击失效的Bug及临时方案问询

AndroidFragment与CircularProgressIndicator混合使用导致点击失效的Bug及临时方案问询

我已经把这个问题作为bug提交给Google了,不过还是想来这里碰碰运气,看看有没有大佬能给点靠谱的反馈或临时解决思路。

问题是这样的:当我把AndroidFragment和CircularProgressIndicator混合使用时,触发了一个奇怪的bug。具体场景是——如果某个AndroidFragment里包含了CircularProgressIndicator,同时页面上有一个足够长、可以滚动的Column,里面放了多个AndroidFragment,只要一滚动页面,其他任何Composable的点击事件就完全失效了。

下面是能复现这个问题的完整代码:

package com.test.circularprogress

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.content.ContentProviderCompat.requireContext
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.compose.AndroidFragment
import com.test.circularprogress.ui.theme.MyApplicationTheme
import kotlin.jvm.java

class FragmentA: Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return ComposeView(requireContext()).apply {
            setContent {
                FragmentAScreen(onClick = ::clickedSomething)
            }
        }
    }

    private fun clickedSomething() {
        Toast.makeText(requireContext(), "Clicked Something", Toast.LENGTH_SHORT).show()
    }

    @Composable
    private fun FragmentAScreen(
        onClick: (() -> Unit) = {}
    ) {
        Column() {
            Text(text = "FragmentA")
            Button(onClick = onClick ) {
                Text(text = "Click ME! ")
            }
        }
    }
}

class FragmentB: Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return ComposeView(requireContext()).apply {
            setContent {
                Column(modifier = Modifier.background(Color.Red)) {
                    Text(text = "FragmentB ")
                    CircularProgressIndicator(modifier = Modifier.size(40.dp))
                }
            }
        }
    }
}

class FragmentC: Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_c, container, false)
    }
}

class FragmentD: Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return ComposeView(requireContext()).apply {
            setContent {
                Column(modifier = Modifier.height(700.dp).background(Color.Blue)) {
                    Text(text = "FragmentD")
                }
            }
        }
    }
}

class MainActivity : FragmentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            MyActivityScreen()
        }
    }
}

@Composable
@Preview
private fun MyActivityScreen() {
    MyApplicationTheme {
        Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
            Column(
                modifier = Modifier
                    .padding(innerPadding)
                    .verticalScroll(rememberScrollState())
            ) {
                AndroidFragment(clazz = FragmentA::class.java)
                AndroidFragment(clazz = FragmentB::class.java)
                AndroidFragment(clazz = FragmentD::class.java)
                AndroidFragment(clazz = FragmentC::class.java)
                AndroidFragment(clazz = FragmentD::class.java)
            }
        }
    }
}

只要把FragmentB里的CircularProgressIndicator注释掉,所有功能就完全正常了。

目前我已经尝试过两种临时方案,但都没解决问题:

  • 使用第三方的加载动画组件
  • 自定义加载动画,用LaunchEffect来实现动画逻辑,而不是依赖系统的动画remember机制

有没有大佬遇到过类似的问题?或者有什么其他的思路可以尝试?万分感谢!

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 08:08:04