Skip to content

Commit

Permalink
Declare shared interface for accessibility delegate methods (#48543)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #48543

Introduces a shared interface for methods that need to be called by the `ReactScrollViewAccessibilityDelegate`

Changelog: [Internal]

Reviewed By: alanleedev

Differential Revision: D67948151

fbshipit-source-id: 9bafaa0b5f9ad5ba2fd73b7b1929d784fa4951c9
  • Loading branch information
Abbondanzo authored and facebook-github-bot committed Jan 16, 2025
1 parent b1938e9 commit 8a12672
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
5 changes: 3 additions & 2 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -6673,7 +6673,7 @@ public final class com/facebook/react/views/scroll/ReactHorizontalScrollContaine
public final class com/facebook/react/views/scroll/ReactHorizontalScrollContainerViewManager$Companion {
}

public class com/facebook/react/views/scroll/ReactHorizontalScrollView : android/widget/HorizontalScrollView, android/view/View$OnLayoutChangeListener, android/view/ViewGroup$OnHierarchyChangeListener, com/facebook/react/uimanager/ReactClippingViewGroup, com/facebook/react/uimanager/ReactOverflowViewWithInset, com/facebook/react/views/scroll/ReactScrollViewHelper$HasFlingAnimator, com/facebook/react/views/scroll/ReactScrollViewHelper$HasScrollEventThrottle, com/facebook/react/views/scroll/ReactScrollViewHelper$HasScrollState, com/facebook/react/views/scroll/ReactScrollViewHelper$HasSmoothScroll, com/facebook/react/views/scroll/ReactScrollViewHelper$HasStateWrapper {
public class com/facebook/react/views/scroll/ReactHorizontalScrollView : android/widget/HorizontalScrollView, android/view/View$OnLayoutChangeListener, android/view/ViewGroup$OnHierarchyChangeListener, com/facebook/react/uimanager/ReactClippingViewGroup, com/facebook/react/uimanager/ReactOverflowViewWithInset, com/facebook/react/views/scroll/ReactAccessibleScrollView, com/facebook/react/views/scroll/ReactScrollViewHelper$HasFlingAnimator, com/facebook/react/views/scroll/ReactScrollViewHelper$HasScrollEventThrottle, com/facebook/react/views/scroll/ReactScrollViewHelper$HasScrollState, com/facebook/react/views/scroll/ReactScrollViewHelper$HasSmoothScroll, com/facebook/react/views/scroll/ReactScrollViewHelper$HasStateWrapper {
public fun <init> (Landroid/content/Context;)V
public fun <init> (Landroid/content/Context;Lcom/facebook/react/views/scroll/FpsListener;)V
public fun abortAnimation ()V
Expand Down Expand Up @@ -6798,7 +6798,7 @@ public class com/facebook/react/views/scroll/ReactHorizontalScrollViewManager :
public fun updateState (Lcom/facebook/react/views/scroll/ReactHorizontalScrollView;Lcom/facebook/react/uimanager/ReactStylesDiffMap;Lcom/facebook/react/uimanager/StateWrapper;)Ljava/lang/Object;
}

public class com/facebook/react/views/scroll/ReactScrollView : android/widget/ScrollView, android/view/View$OnLayoutChangeListener, android/view/ViewGroup$OnHierarchyChangeListener, com/facebook/react/uimanager/ReactClippingViewGroup, com/facebook/react/uimanager/ReactOverflowViewWithInset, com/facebook/react/views/scroll/ReactScrollViewHelper$HasFlingAnimator, com/facebook/react/views/scroll/ReactScrollViewHelper$HasScrollEventThrottle, com/facebook/react/views/scroll/ReactScrollViewHelper$HasScrollState, com/facebook/react/views/scroll/ReactScrollViewHelper$HasSmoothScroll, com/facebook/react/views/scroll/ReactScrollViewHelper$HasStateWrapper {
public class com/facebook/react/views/scroll/ReactScrollView : android/widget/ScrollView, android/view/View$OnLayoutChangeListener, android/view/ViewGroup$OnHierarchyChangeListener, com/facebook/react/uimanager/ReactClippingViewGroup, com/facebook/react/uimanager/ReactOverflowViewWithInset, com/facebook/react/views/scroll/ReactAccessibleScrollView, com/facebook/react/views/scroll/ReactScrollViewHelper$HasFlingAnimator, com/facebook/react/views/scroll/ReactScrollViewHelper$HasScrollEventThrottle, com/facebook/react/views/scroll/ReactScrollViewHelper$HasScrollState, com/facebook/react/views/scroll/ReactScrollViewHelper$HasSmoothScroll, com/facebook/react/views/scroll/ReactScrollViewHelper$HasStateWrapper {
public fun <init> (Landroid/content/Context;)V
public fun <init> (Landroid/content/Context;Lcom/facebook/react/views/scroll/FpsListener;)V
public fun abortAnimation ()V
Expand All @@ -6821,6 +6821,7 @@ public class com/facebook/react/views/scroll/ReactScrollView : android/widget/Sc
public fun getScrollEventThrottle ()I
public fun getStateWrapper ()Lcom/facebook/react/uimanager/StateWrapper;
protected fun handleInterceptedTouchEvent (Landroid/view/MotionEvent;)V
public fun isPartiallyScrolledInView (Landroid/view/View;)Z
protected fun onAttachedToWindow ()V
public fun onChildViewAdded (Landroid/view/View;Landroid/view/View;)V
public fun onChildViewRemoved (Landroid/view/View;Landroid/view/View;)V
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.views.scroll

import android.view.View

/** Shared interface for the [ReactScrollViewAccessibilityDelegate] */
internal interface ReactAccessibleScrollView {

val scrollEnabled: Boolean

/** Returns whether the given descendent is partially scrolled in view */
fun isPartiallyScrolledInView(view: View): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
implements ReactClippingViewGroup,
ViewGroup.OnHierarchyChangeListener,
View.OnLayoutChangeListener,
ReactAccessibleScrollView,
ReactOverflowViewWithInset,
HasScrollState,
HasStateWrapper,
Expand Down Expand Up @@ -456,6 +457,7 @@ private boolean isScrolledInView(View descendent) {
}

/** Returns whether the given descendent is partially scrolled in view */
@Override
public boolean isPartiallyScrolledInView(View descendent) {
int scrollDelta = getScrollDelta(descendent);
descendent.getDrawingRect(mTempRect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class ReactScrollView extends ScrollView
implements ReactClippingViewGroup,
ViewGroup.OnHierarchyChangeListener,
View.OnLayoutChangeListener,
ReactAccessibleScrollView,
ReactOverflowViewWithInset,
HasScrollState,
HasStateWrapper,
Expand Down Expand Up @@ -380,7 +381,8 @@ private int getScrollDelta(View descendent) {
}

/** Returns whether the given descendent is partially scrolled in view */
boolean isPartiallyScrolledInView(View descendent) {
@Override
public boolean isPartiallyScrolledInView(View descendent) {
int scrollDelta = getScrollDelta(descendent);
descendent.getDrawingRect(mTempRect);
return scrollDelta != 0 && Math.abs(scrollDelta) < mTempRect.width();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ internal class ReactScrollViewAccessibilityDelegate : AccessibilityDelegateCompa

override fun onInitializeAccessibilityEvent(host: View, event: AccessibilityEvent) {
super.onInitializeAccessibilityEvent(host, event)
if (host is ReactScrollView || host is ReactHorizontalScrollView) {
if (host is ReactAccessibleScrollView) {
onInitializeAccessibilityEventInternal(host, event)
} else {
ReactSoftExceptionLogger.logSoftException(
TAG,
AssertionException(
"ReactScrollViewAccessibilityDelegate should only be used with ReactScrollView or ReactHorizontalScrollView, not with class: ${host.javaClass.simpleName}"))
"ReactScrollViewAccessibilityDelegate should only be used with ReactAccessibleScrollView, not with class: ${host.javaClass.simpleName}"))
}
}

override fun onInitializeAccessibilityNodeInfo(host: View, info: AccessibilityNodeInfoCompat) {
super.onInitializeAccessibilityNodeInfo(host, info)
if (host is ReactScrollView || host is ReactHorizontalScrollView) {
if (host is ReactAccessibleScrollView) {
onInitializeAccessibilityNodeInfoInternal(host, info)
} else {
ReactSoftExceptionLogger.logSoftException(
TAG,
AssertionException(
"ReactScrollViewAccessibilityDelegate should only be used with ReactScrollView or ReactHorizontalScrollView, not with class: ${host.javaClass.simpleName}"))
"ReactScrollViewAccessibilityDelegate should only be used with ReactAccessibleScrollView, not with class: ${host.javaClass.simpleName}"))
}
}

Expand All @@ -61,9 +61,7 @@ internal class ReactScrollViewAccessibilityDelegate : AccessibilityDelegateCompa
for (index in 0..<contentView.childCount) {
val nextChild = contentView.getChildAt(index)
val isVisible: Boolean =
if (view is ReactScrollView) {
view.isPartiallyScrolledInView(nextChild)
} else if (view is ReactHorizontalScrollView) {
if (view is ReactAccessibleScrollView) {
view.isPartiallyScrolledInView(nextChild)
} else {
return
Expand Down Expand Up @@ -127,9 +125,7 @@ internal class ReactScrollViewAccessibilityDelegate : AccessibilityDelegateCompa
info.setCollectionInfo(collectionInfoCompat)
}

if (view is ReactScrollView) {
info.isScrollable = view.scrollEnabled
} else if (view is ReactHorizontalScrollView) {
if (view is ReactAccessibleScrollView) {
info.isScrollable = view.scrollEnabled
}
}
Expand Down

0 comments on commit 8a12672

Please sign in to comment.