Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Avoid erratic scrolling on submit #5026

Merged
merged 6 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,6 @@ else if (m_action.GetElementType() == ActionType.ToggleVisibility)
{
if (m_action.GetElementType() == ActionType.Submit || m_renderedAdaptiveCard.isActionSubmitable(view))
{
// If an input is in focus before submit, and the same input is focused on error,
// the input would not be scrolled into view. Instead, clearing focus first ensures scroll.
Util.clearFocus(view);

if (!m_renderedAdaptiveCard.areInputsValid(Util.getViewId(view)))
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,17 @@ public static byte[] getBytes(CharVector charVector)
}

/**
* Clear any existing focus by temporarily adding then removing focus to a given helper View.
* @param v The helper View that will temporarily grab and release focus.
* Force focus when requestFocus is not sufficient.
* @param v The target View to focus
*/
public static void clearFocus(View v) {
boolean focusable = v.isFocusable();
public static void forceFocus(View v) {
boolean focusableInTouchMode = v.isFocusableInTouchMode();

v.setFocusable(true);
v.setFocusableInTouchMode(true);

v.requestFocusFromTouch();
v.clearFocus();

v.setFocusable(focusable);
v.setFocusableInTouchMode(focusableInTouchMode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.adaptivecards.objectmodel.BaseInputElement;
import io.adaptivecards.objectmodel.ChoiceInputVector;
import io.adaptivecards.objectmodel.ChoiceSetInput;
import io.adaptivecards.renderer.Util;

import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -77,8 +78,7 @@ public void setFocusToView()
{
if (m_checkBoxList.size() > 0)
{
m_checkBoxList.get(0).setFocusableInTouchMode(true);
m_checkBoxList.get(0).requestFocus();
Util.forceFocus(m_checkBoxList.get(0));
m_checkBoxList.get(0).sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.adaptivecards.objectmodel.ChoiceInput;
import io.adaptivecards.objectmodel.ChoiceInputVector;
import io.adaptivecards.objectmodel.ChoiceSetInput;
import io.adaptivecards.renderer.Util;
import io.adaptivecards.renderer.input.customcontrols.ValidatedSpinnerLayout;

import java.text.ParseException;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void setInput(String value)
@Override
public void setFocusToView()
{
m_view.requestFocus();
Util.forceFocus(m_view);
m_view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.adaptivecards.objectmodel.ChoiceInput;
import io.adaptivecards.objectmodel.ChoiceInputVector;
import io.adaptivecards.objectmodel.ChoiceSetInput;
import io.adaptivecards.renderer.Util;

import java.text.ParseException;
import java.util.Map;
Expand Down Expand Up @@ -80,8 +81,7 @@ public void setFocusToView()
{
RadioButton radioButton = (RadioButton)(radioGroup.getChildAt(0));

radioButton.setFocusableInTouchMode(true);
radioButton.requestFocus();
Util.forceFocus(radioButton);
radioButton.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public boolean isValidOnSpecifics(String textInputValue)

public void setFocusToView()
{
m_view.requestFocus();
Util.forceFocus(m_view);
m_view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io.adaptivecards.objectmodel.BaseInputElement;
import io.adaptivecards.objectmodel.ToggleInput;
import io.adaptivecards.renderer.Util;

import java.text.ParseException;
import java.util.Map;
Expand Down Expand Up @@ -59,8 +60,7 @@ public boolean isValid()
@Override
public void setFocusToView()
{
m_view.setFocusableInTouchMode(true);
m_view.requestFocus();
Util.forceFocus(m_view);
m_view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void setInput(String input)
@Override
public void setFocusToView()
{
m_view.requestFocus();
m_view.requestFocusFromTouch();
m_view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
}
}
Expand Down