Scrollview bounces back to top button react native năm 2024

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Component that wraps platform ScrollView while providing integration with touch locking "responder" system.

Keep in mind that ScrollViews must have a bounded height in order to work, since they contain unbounded-height children into a bounded container (via a scroll interaction). In order to bound the height of a ScrollView, either set the height of the view directly (discouraged) or make sure all parent views have bounded height. Forgetting to transfer {flex: 1} down the view stack can lead to errors here, which the element inspector makes easy to debug.

Doesn't yet support other contained responders from blocking this scroll view from becoming the responder.

Props

Methods


Reference

Props

bounces

When true, the scroll view bounces when it reaches the end of the content if the content is larger then the scroll view along the axis of the scroll direction. When false, it disables all bouncing even if the `contentContainerStyle`3 props are true. The default value is true.

TypeRequiredPlatform boolNoiOS


contentContainerStyle

These styles will be applied to the scroll view content container which wraps all of the child views. Example:

return ( ); ... const styles = StyleSheet.create({ contentContainer: { paddingVertical: 20 } });

TypeRequired StyleSheetPropType(View Style props)No


keyboardDismissMode

Determines whether the keyboard gets dismissed in response to a drag.

  • 'none' (the default), drags do not dismiss the keyboard.
  • 'on-drag', the keyboard is dismissed when a drag begins.
  • 'interactive', the keyboard is dismissed interactively with the drag and moves in synchrony with the touch; dragging upwards cancels the dismissal. On android this is not supported and it will have the same behavior as 'none'. TypeRequired enum('none', 'interactive', 'on-drag')No

keyboardShouldPersistTaps

When false, tapping outside of the focused text input when the keyboard is up dismisses the keyboard. When true, the keyboard will not dismiss automatically, and the scroll view will not catch taps, but children of the scroll view can catch taps. The default value is false.

TypeRequired boolNo


onContentSizeChange

Called when scrollable content view of the ScrollView changes.

Handler function is passed the content width and content height as parameters: `contentContainerStyle`8

It's implemented using onLayout handler attached to the content container which this ScrollView renders.

TypeRequired functionNo


onScroll

Fires at most once per frame during scrolling. The frequency of the events can be controlled using the `bounces`3 prop.

TypeRequired functionNo


pagingEnabled

When true, the scroll view stops on multiples of the scroll view's size when scrolling. This can be used for horizontal pagination. The default value is false.

TypeRequired boolNo


scrollWithoutAnimationTo(y, x);

0

A RefreshControl component, used to provide pull-to-refresh functionality for the ScrollView.

See RefreshControl.

TypeRequired elementNo


scrollWithoutAnimationTo(y, x);

1

Experimental: When true, offscreen child views (whose `keyboardDismissMode`4 value is `keyboardDismissMode`5) are removed from their native backing superview when offscreen. This can improve scrolling performance on long lists. The default value is true.

TypeRequired boolNo


scrollWithoutAnimationTo(y, x);

2

When false, the content does not scroll. The default value is true.

TypeRequired boolNo


scrollWithoutAnimationTo(y, x);

3

When true, shows a horizontal scroll indicator. The default value is true.

TypeRequired boolNo


scrollWithoutAnimationTo(y, x);

4

When true, shows a vertical scroll indicator. The default value is true.

TypeRequired boolNo


scrollWithoutAnimationTo(y, x);

5

TypeRequired styleNo

  • `keyboardShouldPersistTaps`0: color
  • `keyboardShouldPersistTaps`1: enum('visible', 'hidden')
  • `keyboardShouldPersistTaps`2: color
  • `keyboardShouldPersistTaps`3: number
  • `keyboardShouldPersistTaps`4: number
  • `keyboardShouldPersistTaps`5: number
  • `keyboardShouldPersistTaps`6: color
  • `keyboardShouldPersistTaps`7: color
  • `keyboardShouldPersistTaps`8: number
  • `keyboardShouldPersistTaps`9: number
  • `onContentSizeChange`0: color
  • `onContentSizeChange`1: number
  • `onContentSizeChange`2: enum('solid', 'dotted', 'dashed')
  • `onContentSizeChange`3: color
  • `onContentSizeChange`4: number
  • `onContentSizeChange`5: number
  • `onContentSizeChange`6: number
  • `onContentSizeChange`7: number
  • `onContentSizeChange`8: number
  • `onContentSizeChange`9: number (Android) (Android-only) Sets the elevation of a view, using Android's underlying . This adds a drop shadow to the item and affects z-order for overlapping views. Only supported on Android 5.0+, has no effect on earlier versions.

scrollWithoutAnimationTo(y, x);

6

Sometimes a scrollview takes up more space than its content fills. When this is the case, this prop will fill the rest of the scrollview with a color to avoid setting a background and creating unnecessary overdraw. This is an advanced optimization that is not needed in the general case.

TypeRequiredPlatform colorNoAndroid


scrollWithoutAnimationTo(y, x);

7

Tag used to log scroll performance on this scroll view. Will force momentum events to be turned on (see sendMomentumEvents). This doesn't do anything out of the box and you need to implement a custom native FpsListener for it to be useful.

TypeRequiredPlatform stringNoAndroid


scrollWithoutAnimationTo(y, x);

8

When true, the scroll view bounces horizontally when it reaches the end even if the content is smaller than the scroll view itself. The default value is true when `onScroll`3 and false otherwise.

TypeRequiredPlatform boolNoiOS


scrollWithoutAnimationTo(y, x);

9

When true, the scroll view bounces vertically when it reaches the end even if the content is smaller than the scroll view itself. The default value is false when `onScroll`3 and true otherwise.

TypeRequiredPlatform boolNoiOS


`{flex: 1}`0

Controls whether iOS should automatically adjust the content inset for scroll views that are placed behind a navigation bar or tab bar/ toolbar. The default value is true.

TypeRequiredPlatform boolNoiOS


`{flex: 1}`1

When true, the scroll view's children are arranged horizontally in a row instead of vertically in a column. The default value is false.

TypeRequired boolNo


`{flex: 1}`2

When true, gestures can drive zoom past min/max and the zoom will animate to the min/max value at gesture end, otherwise the zoom will not exceed the limits.

TypeRequiredPlatform boolNoiOS


`{flex: 1}`3

When false, once tracking starts, won't try to drag if the touch moves. The default value is true.

TypeRequiredPlatform boolNoiOS


`{flex: 1}`4

When true, the scroll view automatically centers the content when the content is smaller than the scroll view bounds; when the content is larger than the scroll view, this property has no effect. The default value is false.

TypeRequiredPlatform boolNoiOS


`{flex: 1}`5

The amount by which the scroll view content is inset from the edges of the scroll view. Defaults to `pagingEnabled`2.

TypeRequiredPlatform object: {top: number, left: number, bottom: number, right: number}NoiOS


`{flex: 1}`6

Used to manually set the starting scroll offset. The default value is `pagingEnabled`4.

TypeRequiredPlatform PointPropTypeNoiOS


`{flex: 1}`7

A floating-point number that determines how quickly the scroll view decelerates after the user lifts their finger. You may also use string shortcuts `pagingEnabled`6 and `pagingEnabled`7 which match the underlying iOS settings for `pagingEnabled`8 and `pagingEnabled`9 respectively.

  • normal: 0.998 (the default)
  • fast: 0.99 TypeRequiredPlatform enum('fast', 'normal'), ,numberNoiOS

`{flex: 1}`8

When true, the ScrollView will try to lock to only vertical or horizontal scrolling while dragging. The default value is false.

TypeRequiredPlatform boolNoiOS


`{flex: 1}`9

The style of the scroll indicators.

  • scrollWithoutAnimationTo(y, x);

    02 (the default), same as

    scrollWithoutAnimationTo(y, x);

    03.
  • scrollWithoutAnimationTo(y, x);

    03, scroll indicator is black. This style is good against a white content background.
  • scrollWithoutAnimationTo(y, x);

    05, scroll indicator is white. This style is good against a black content background. TypeRequiredPlatform enum('default', 'black', 'white')NoiOS

`bounces`0

The maximum allowed zoom scale. The default value is 1.0.

TypeRequiredPlatform numberNoiOS


`bounces`1

The minimum allowed zoom scale. The default value is 1.0.

TypeRequiredPlatform numberNoiOS


`bounces`2

Called when a scrolling animation ends.

TypeRequiredPlatform functionNoiOS


`bounces`3

This controls how often the scroll event will be fired while scrolling (as a time interval in ms). A lower number yields better accuracy for code that is tracking the scroll position, but can lead to scroll performance problems due to the volume of information being send over the bridge. You will not notice a difference between values set between 1-16 as the JS run loop is synced to the screen refresh rate. If you do not need precise scroll position tracking, set this value higher to limit the information being sent across the bridge. The default value is zero, which results in the scroll event being sent only once each time the view is scrolled.

TypeRequiredPlatform numberNoiOS


`bounces`4

The amount by which the scroll view indicators are inset from the edges of the scroll view. This should normally be set to the same value as the `{flex: 1}`5. Defaults to

scrollWithoutAnimationTo(y, x);

12.

TypeRequiredPlatform object: {top: number, left: number, bottom: number, right: number}NoiOS


`bounces`5

When true, the scroll view scrolls to top when the status bar is tapped. The default value is true.

TypeRequiredPlatform boolNoiOS


`bounces`6

When `bounces`7 is set, `bounces`6 will define the relationship of the snapping to the scroll view.

  • scrollWithoutAnimationTo(y, x);

    17 (the default) will align the snap at the left (horizontal) or top (vertical)
  • scrollWithoutAnimationTo(y, x);

    18 will align the snap in the center
  • scrollWithoutAnimationTo(y, x);

    19 will align the snap at the right (horizontal) or bottom (vertical) TypeRequiredPlatform enum('start', 'center', 'end')NoiOS

`bounces`7

When set, causes the scroll view to stop at multiples of the value of `bounces`7. This can be used for paginating through children that have lengths smaller than the scroll view. Used in combination with `bounces`6.

TypeRequiredPlatform numberNoiOS


`bounces`8

An array of child indices determining which children get docked to the top of the screen when scrolling. For example, passing

scrollWithoutAnimationTo(y, x);

24 will cause the first child to be fixed to the top of the scroll view. This property is not supported in conjunction with `onScroll`3.

TypeRequiredPlatform array of numberNoiOS


`bounces`9

The current scale of the scroll view content. The default value is 1.0.

TypeRequiredPlatform numberNoiOS

Methods

scrollWithoutAnimationTo(y, x);

27

scrollTo(([y]: number), object, ([x]: number), ([animated]: boolean));

Scrolls to a given x, y offset, either immediately or with a smooth animation.

Syntax:

scrollWithoutAnimationTo(y, x);

28

Note: The weird argument signature is due to the fact that, for historical reasons, the function also accepts separate arguments as as alternative to the options object. This is deprecated due to ambiguity (y before x), and SHOULD NOT BE USED.

How do I stop scroll bouncing in react native?

To prevent the bounce effect and provide a more consistent scrolling experience, you can set alwaysBounceVertical={false} on your ScrollView component.

How to improve ScrollView performance?

My current approach is to load items in batches and then remove items in batches that are no longer visible, and re-load them when the user is scrolling back up, etc. Essentially, it's a form of pagination where I always have one page behind and one page ahead of the currently loaded page in memory.

How do I set scrollTo top in react native?

Scroll to the Top or Bottom of the ListView in React Native.

To take you to the top of the ListView by using : listViewRef. scrollTo({ x: 0, y: 0, animated: true });.

To take you to the Bottom of the ListView by using : listViewRef. scrollToEnd({ animated: true });.

How do I add a ScrollView in react?

The ScrollView component for ReactJS requires the following imports. import React from 'react'; import ReactDOM from 'react-dom'; import JqxScrollView from 'jqwidgets-react/react_jqxscrollview.