Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 336a6c8a authored by Lucas Silva's avatar Lucas Silva
Browse files

Update workaround for background widget loading

Instead of removing and re-adding the views, we instead wait for the
view layout to occur and then add the widget as a child view to the
container.

Bug: 356393319
Test: flashed and scrolled through widgets, verified they render
correctly
Flag: com.android.systemui.communal_hub

Change-Id: I1f522cebbaf7561cfbfb00c57af64dea386a2605
parent cd6cccb5
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -21,10 +21,13 @@ import android.util.SizeF
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.core.view.doOnLayout
import com.android.app.tracing.coroutines.launch
import com.android.systemui.communal.domain.model.CommunalContentModel
import com.android.systemui.communal.util.WidgetViewFactory
import com.android.systemui.util.kotlin.DisposableHandles
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DisposableHandle

@@ -44,13 +47,8 @@ object CommunalAppWidgetHostViewBinder {
        val loadingJob =
            applicationScope.launch("$TAG#createWidgetView") {
                val widget = factory.createWidget(context, model, size)
                // TODO(b/358662507): Remove this workaround
                (container.parent as? ViewGroup)?.let { parent ->
                    val index = parent.indexOfChild(container)
                    parent.removeView(container)
                    parent.addView(container, index)
                }
                container.setView(widget)
                waitForLayout(container)
                container.post { container.setView(widget) }
            }

        disposables += DisposableHandle { loadingJob.cancel() }
@@ -58,6 +56,10 @@ object CommunalAppWidgetHostViewBinder {

        return disposables
    }

    private suspend fun waitForLayout(container: FrameLayout) = suspendCoroutine { cont ->
        container.doOnLayout { cont.resume(Unit) }
    }
}

private fun ViewGroup.setView(view: View) {