From e5c70f9996cad64afdd90891fb2e7fbddd01cfd9 Mon Sep 17 00:00:00 2001 From: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Date: Mon, 18 May 2020 10:23:33 -0700 Subject: [PATCH] [Android] setDimens on ViewNodes for autofill (flutter/engine#18444) --- .../flutter/plugin/editing/TextInputPlugin.java | 15 +++++++++++++++ .../plugin/editing/TextInputPluginTest.java | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index f7072003855..698a44cccfd 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -506,6 +506,21 @@ public class TextInputPlugin { child.setAutofillHints(autofill.hints); child.setAutofillType(View.AUTOFILL_TYPE_TEXT); child.setVisibility(View.VISIBLE); + + // Some autofill services expect child structures to be visible. + // Reports the real size of the child if it's the current client. + if (triggerIdentifier.hashCode() == autofillId && lastClientRect != null) { + child.setDimens( + lastClientRect.left, + lastClientRect.top, + 0, + 0, + lastClientRect.width(), + lastClientRect.height()); + } else { + // Reports a fake dimension that's still visible. + child.setDimens(0, 0, 0, 0, 1, 1); + } } } diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java index b515d80b430..37196133835 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -3,6 +3,7 @@ package io.flutter.plugin.editing; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.AdditionalMatchers.aryEq; +import static org.mockito.AdditionalMatchers.geq; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.any; import static org.mockito.Mockito.eq; @@ -479,8 +480,11 @@ public class TextInputPluginTest { verify(children[0]).setAutofillId(any(), eq("1".hashCode())); verify(children[0]).setAutofillHints(aryEq(new String[] {"HINT1"})); + verify(children[0]).setDimens(anyInt(), anyInt(), anyInt(), anyInt(), geq(0), geq(0)); + verify(children[1]).setAutofillId(any(), eq("2".hashCode())); verify(children[1]).setAutofillHints(aryEq(new String[] {"HINT2", "EXTRA"})); + verify(children[1]).setDimens(anyInt(), anyInt(), anyInt(), anyInt(), geq(0), geq(0)); } @Test @@ -523,6 +527,8 @@ public class TextInputPluginTest { verify(children[0]).setAutofillId(any(), eq("1".hashCode())); verify(children[0]).setAutofillHints(aryEq(new String[] {"HINT1"})); + // Verifies that the child has a non-zero size. + verify(children[0]).setDimens(anyInt(), anyInt(), anyInt(), anyInt(), geq(0), geq(0)); } @Implements(InputMethodManager.class)