[Android] setDimens on ViewNodes for autofill (flutter/engine#18444)

This commit is contained in:
LongCatIsLooong 2020-05-18 10:23:33 -07:00 committed by GitHub
parent a7a95bb530
commit e5c70f9996
2 changed files with 21 additions and 0 deletions

View File

@ -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);
}
}
}

View File

@ -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)