rename and extend new maintain visible content position feature

Summary:
Builds off of https://github.com/facebook/react-native/commit/cae7179c9459f12b1cb5e1a1d998a9dc45f927dc

- Make the prop a dictionary for more configuration options
- Rename `maintainPositionAtOrBeyondIndex` -> `maintainVisibleContentPosition` + `minIndexForVisible`
- Add autoscroll threshold feature

Given the async native of RN JS and background layout, there is no way to trigger the scrollTo from JS without risking a delay, so we add the feature in native code.

== Test Plan ==
ScrollViewExample:
https://youtu.be/pmY8pxC9PRs

Reviewed By: shergin

Differential Revision: D6729160

fbshipit-source-id: 70f9bae460ce84567857a4f696da78ce9b3b834c
This commit is contained in:
Spencer Ahrens
2018-01-18 14:01:50 -08:00
committed by Facebook Github Bot
parent 7e7d00aebe
commit 65184ec6b0
5 changed files with 56 additions and 22 deletions
+10 -4
View File
@@ -131,7 +131,7 @@ if (Platform.OS === 'ios') {
exports.examples.push({
title: '<ScrollView> smooth bi-directional content loading\n',
description:
'The `maintainPositionAtOrBeyondIndex` prop allows insertions to either end of the content ' +
'The `maintainVisibleContentPosition` prop allows insertions to either end of the content ' +
'without causing the visible content to jump. Re-ordering is not supported.',
render: function() {
let itemCount = 6;
@@ -146,7 +146,10 @@ if (Platform.OS === 'ios') {
<View>
<ScrollView
automaticallyAdjustContentInsets={false}
maintainPositionAtOrBeyondIndex={1}
maintainVisibleContentPosition={{
minIndexForVisible: 1,
autoscrollToTopThreshold: 10,
}}
style={styles.scrollView}>
<ActivityIndicator style={{height: 40}} />
{this.state.items.map(item =>
@@ -156,9 +159,12 @@ if (Platform.OS === 'ios') {
<ScrollView
horizontal={true}
automaticallyAdjustContentInsets={false}
maintainPositionAtOrBeyondIndex={1}
maintainVisibleContentPosition={{
minIndexForVisible: 1,
autoscrollToTopThreshold: 10,
}}
style={[styles.scrollView, styles.horizontalScrollView]}>
<ActivityIndicator style={{height: 40}} />
<ActivityIndicator style={{width: 40}} />
{this.state.items.map(item =>
React.cloneElement(item, {key: item.props.msg, style: null}),
)}