Skip to content

Commit

Permalink
fix(android): textInput may throw IllegalStateException (#2957)
Browse files Browse the repository at this point in the history
* fix(android): textInput may throw IllegalStateException

* fix(android): textInput may throw IllegalStateException

---------

Co-authored-by: OpenHippy <[email protected]>
  • Loading branch information
2 people authored and zoomchan-cxj committed Mar 16, 2023
1 parent 4c772fe commit ded1a57
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.tencent.mtt.hippy.views.hippylist.recyclerview.helper.skikcy.IHeaderAttachListener;
import com.tencent.mtt.hippy.views.hippylist.recyclerview.helper.skikcy.IHeaderHost;
import com.tencent.mtt.hippy.views.hippylist.recyclerview.helper.skikcy.StickyHeaderHelper;
import java.util.ArrayList;

/**
* Created on 2020/12/22. Description
Expand Down Expand Up @@ -67,6 +68,7 @@ public class HippyRecyclerView<ADP extends HippyRecyclerListAdapter> extends Hip
Priority.NOT_SET, Priority.NOT_SET, Priority.NOT_SET};
private int mNestedScrollAxesTouch;
private int mNestedScrollAxesNonTouch;
private ArrayList<View> mFocusableViews;

public HippyRecyclerView(Context context) {
super(context);
Expand Down Expand Up @@ -553,7 +555,33 @@ public View focusSearch(View focused, int direction) {
if (isTvPlatform) {
return mFocusHelper.focusSearch(focused, direction);
}
return super.focusSearch(focused, direction);
View result = super.focusSearch(focused, direction);
// {@link RecyclerView#focusSearch} may return not focusable view,
// cause IllegalStateException, so we verify again.
if (result == null || !verifyFocusable(result, direction)) {
return null;
}
return result;
}

private boolean verifyFocusable(@NonNull View view, int direction) {
boolean inTouchMode = isInTouchMode();
// first check whether self is able to take focus
if (inTouchMode ? view.isFocusableInTouchMode() : view.isFocusable()) {
return true;
}
// then check whether has focusable descendants
if (!(view instanceof ViewGroup)) {
return false;
}
if (mFocusableViews == null) {
mFocusableViews = new ArrayList<>();
}
view.addFocusables(mFocusableViews, direction, inTouchMode ? FOCUSABLES_TOUCH_MODE : FOCUSABLES_ALL);
boolean result = !mFocusableViews.isEmpty();
// clear up the temp array
mFocusableViews.clear();
return result;
}

@Override
Expand Down

0 comments on commit ded1a57

Please sign in to comment.