Skip to content

Commit 600a8dc

Browse files
rozelemeta-codesync[bot]
authored andcommitted
Allow customization of requestChildFocus scroll behavior in ScrollView (facebook#54325)
Summary: Pull Request resolved: facebook#54325 Apps that override ScrollView may need to customize the auto scroll behavior on focus. This adds a protected method for apps that override ReactScrollView to customize focus behaviors. ## Changelog [Internal] Reviewed By: joevilches Differential Revision: D85779339 fbshipit-source-id: 1ba978ed14ceb224ddc1d0da97727ff9702972e7
1 parent 9693a2b commit 600a8dc

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5651,6 +5651,7 @@ public class com/facebook/react/views/scroll/ReactHorizontalScrollView : android
56515651
public fun pageScroll (I)Z
56525652
public fun reactSmoothScrollTo (II)V
56535653
public fun requestChildFocus (Landroid/view/View;Landroid/view/View;)V
5654+
protected fun requestChildFocusWithoutScroll (Landroid/view/View;Landroid/view/View;)V
56545655
protected fun restoreScrollTo (II)V
56555656
public fun scrollTo (II)V
56565657
public fun scrollToPreservingMomentum (II)V
@@ -5791,6 +5792,7 @@ public class com/facebook/react/views/scroll/ReactScrollView : android/widget/Sc
57915792
public fun onTouchEvent (Landroid/view/MotionEvent;)Z
57925793
public fun reactSmoothScrollTo (II)V
57935794
public fun requestChildFocus (Landroid/view/View;Landroid/view/View;)V
5795+
protected fun requestChildFocusWithoutScroll (Landroid/view/View;Landroid/view/View;)V
57945796
public fun scrollTo (II)V
57955797
public fun scrollToPreservingMomentum (II)V
57965798
public fun setBackgroundColor (I)V

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,15 @@ public void requestChildFocus(View child, View focused) {
542542
if (focused != null && !mPagingEnabled) {
543543
scrollToChild(focused);
544544
}
545+
requestChildFocusWithoutScroll(child, focused);
546+
}
547+
548+
/**
549+
* In rare cases where an app overrides the built-in ReactScrollView by overriding it, and also
550+
* needs to customize scroll into view on focus behaviors, this protected method can be used to
551+
* unblocks such customization.
552+
*/
553+
protected void requestChildFocusWithoutScroll(View child, View focused) {
545554
super.requestChildFocus(child, focused);
546555
}
547556

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,15 @@ public void requestChildFocus(View child, View focused) {
511511
if (focused != null) {
512512
scrollToChild(focused);
513513
}
514+
requestChildFocusWithoutScroll(child, focused);
515+
}
516+
517+
/**
518+
* In rare cases where an app overrides the built-in ReactScrollView by overriding it, and also
519+
* needs to customize scroll into view on focus behaviors, this protected method can be used to
520+
* unblocks such customization.
521+
*/
522+
protected void requestChildFocusWithoutScroll(View child, View focused) {
514523
super.requestChildFocus(child, focused);
515524
}
516525

0 commit comments

Comments
 (0)