diff --git a/android/src/main/java/com/henninghall/date_picker/generated/NumberPicker.java b/android/src/main/java/com/henninghall/date_picker/generated/NumberPicker.java index e4b48efc..cf588160 100644 --- a/android/src/main/java/com/henninghall/date_picker/generated/NumberPicker.java +++ b/android/src/main/java/com/henninghall/date_picker/generated/NumberPicker.java @@ -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) { @@ -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; @@ -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; @@ -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); @@ -2887,4 +2927,4 @@ public static android.view.accessibility.AccessibilityManager getInstance(Contex (android.view.accessibility.AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); return accessibilityManager; } -} \ No newline at end of file +}