Skip to content

Commit 25efa9b

Browse files
authored
Merge pull request #1 from NoriginMedia/descendentsfocus
fix focus
2 parents 0e964f9 + dddb7a6 commit 25efa9b

File tree

1 file changed

+22
-0
lines changed
  • android/src/main/java/com/swmansion/rnscreens

1 file changed

+22
-0
lines changed

android/src/main/java/com/swmansion/rnscreens/Screen.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,30 @@ public Screen(ReactContext context) {
7878
setLayoutParams(new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_APPLICATION));
7979
}
8080

81+
private boolean iSChildrenFocus(View view) {
82+
Object tag = view.getTag(R.id.view_tag_native_id);
83+
//workaround to allow child focusing in case of problems like on the player
84+
if (tag instanceof String && ((String) tag).contains("descendentsfocus")) {
85+
return true;
86+
}
87+
if (view instanceof ViewGroup) {
88+
ViewGroup viewGroup = (ViewGroup) view;
89+
for(int i = 0; i < viewGroup.getChildCount(); i++) {
90+
View v = viewGroup.getChildAt(i);
91+
if (v != null && iSChildrenFocus(v)) {
92+
return true;
93+
}
94+
}
95+
}
96+
return false;
97+
}
98+
8199
@Override
82100
protected boolean onRequestFocusInDescendants(final int dir, final Rect rect) {
101+
boolean isChildFocus = iSChildrenFocus(this);
102+
if (isChildFocus) {
103+
return super.onRequestFocusInDescendants(dir, rect);
104+
}
83105
return false;
84106
}
85107

0 commit comments

Comments
 (0)