diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/communal/ui/binder/CommunalAppWidgetHostViewBinder.kt | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/binder/CommunalAppWidgetHostViewBinder.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/binder/CommunalAppWidgetHostViewBinder.kt index 7a0567190bd0..5f421fd19550 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/ui/binder/CommunalAppWidgetHostViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/ui/binder/CommunalAppWidgetHostViewBinder.kt @@ -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) { |