Skip to content
Open
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 @@ -2442,6 +2442,46 @@ class AccessibilityNodeProviderImpl extends AccessibilityNodeProvider {

private int mAccessibilityFocusedView = UNDEFINED;

/**
* Check if the NumberPicker is visible to the user in a React Native-compatible way.
* This avoids issues with the platform's isVisibleToUser() method in RN context.
*/
private boolean isPickerVisibleToUser() {
// Check if the view and all its parents are visible
if (!NumberPicker.this.isShown()) {
return false;
}

// Check if the view has positive dimensions
if (NumberPicker.this.getWidth() <= 0 || NumberPicker.this.getHeight() <= 0) {
return false;
}

// Check if the view is actually attached to a window
if (NumberPicker.this.getWindowVisibility() != View.VISIBLE) {
return false;
}

return true;
}

/**
* Check if a child element with given bounds is visible to the user.
*/
private boolean isPickerVisibleToUser(Rect bounds) {
// First check if the picker itself is visible
if (!isPickerVisibleToUser()) {
return false;
}

// Check if the bounds have positive dimensions
if (bounds == null || bounds.isEmpty()) {
return false;
}

return true;
}

@Override
public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
switch (virtualViewId) {
Expand Down Expand Up @@ -2740,7 +2780,7 @@ private AccessibilityNodeInfo createAccessibiltyNodeInfoForInputText(
}
Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom);
// info.setVisibleToUser(isVisibleToUser(boundsInParent));
info.setVisibleToUser(isPickerVisibleToUser(boundsInParent));
info.setBoundsInParent(boundsInParent);
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
Expand All @@ -2764,7 +2804,7 @@ private AccessibilityNodeInfo createAccessibilityNodeInfoForVirtualButton(int vi
info.setAccessibilityFocused(mAccessibilityFocusedView == virtualViewId);
Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom);
// info.setVisibleToUser(isVisibleToUser(boundsInParent));
info.setVisibleToUser(isPickerVisibleToUser(boundsInParent));
info.setBoundsInParent(boundsInParent);
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
Expand Down Expand Up @@ -2813,8 +2853,8 @@ private AccessibilityNodeInfo createAccessibilityNodeInfoForNumberPicker(int lef
// boundsInParent.scale(applicationScale);
info.setBoundsInParent(boundsInParent);

// info.setVisibleToUser(isVisibleToUser());

info.setVisibleToUser(isPickerVisibleToUser());
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen);
Expand Down Expand Up @@ -2887,4 +2927,4 @@ public static android.view.accessibility.AccessibilityManager getInstance(Contex
(android.view.accessibility.AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
return accessibilityManager;
}
}
}
Loading