From a695631475b36d73c799c8363eea0d1f10b26a61 Mon Sep 17 00:00:00 2001 From: Mark Punzalan Date: Thu, 26 May 2022 21:46:29 +0000 Subject: [PATCH] Don't clear translation state on temporary detachment. Change I97cc418a8 broke translation on apps which use ListView; messages were re-translated with the animation even while on-screen. A new message arrival triggers a re-layout which causes the temporary detachment, which caused translation to be cleared, and the views get translated again later. The solution is to NOT clear translation in the case of temporary detachment. When Views are actually recycled (e.g., by ListView and RecyclerView), the detachment is permanent/non-temporary. Bug: 232178488 Test: atest UiTranslationManagerTest Test: Manual - Verified scrolling and new messages arriving when translation is enabled. Tested on apps that use ListView and RecyclerView. Change-Id: Ibf1be58219c43252e00b06d4c9e27def5bd36fc2 --- core/java/android/view/View.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 90497e7adbf73..ba6ba63e4ed05 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -10000,7 +10000,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, // We reset any translation state as views may be re-used (e.g., as in ListView and // RecyclerView). We only need to do this for views important for content capture since // views unimportant for content capture won't be translated anyway. - clearTranslationState(); + if (!isTemporarilyDetached()) { + clearTranslationState(); + } } }