/** * Copyright (c) 2015-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format * @flow */ 'use strict'; const React = require('react'); const ReactNative = require('react-native'); const {Alert, Animated, Button, StyleSheet, Text, View} = ReactNative; const RNTesterPage = require('./RNTesterPage'); const infoLog = require('infoLog'); const { HeaderComponent, FooterComponent, ItemComponent, PlainInput, SeparatorComponent, Spindicator, genItemData, pressItem, renderSmallSwitchOption, renderStackedItem, } = require('./ListExampleShared'); const VIEWABILITY_CONFIG = { minimumViewTime: 3000, viewAreaCoveragePercentThreshold: 100, waitForInteraction: true, }; const renderSectionHeader = ({section}) => ( SECTION HEADER: {section.key} ); const renderSectionFooter = ({section}) => ( SECTION FOOTER: {section.key} ); const CustomSeparatorComponent = ({highlighted, text}) => ( {text} ); class SectionListExample extends React.PureComponent<{}, $FlowFixMeState> { static title = ''; static description = 'Performant, scrollable list of data.'; state = { data: genItemData(1000), debug: false, filterText: '', logViewable: false, virtualized: true, inverted: false, }; _scrollPos = new Animated.Value(0); _scrollSinkY = Animated.event( [{nativeEvent: {contentOffset: {y: this._scrollPos}}}], {useNativeDriver: true}, ); _sectionListRef: Animated.SectionList; _captureRef = ref => { this._sectionListRef = ref; }; _scrollToLocation(sectionIndex: number, itemIndex: number) { this._sectionListRef.getNode().scrollToLocation({sectionIndex, itemIndex}); } render() { const filterRegex = new RegExp(String(this.state.filterText), 'i'); const filter = item => filterRegex.test(item.text) || filterRegex.test(item.title); const filteredData = this.state.data.filter(filter); const filteredSectionData = []; let startIndex = 0; const endIndex = filteredData.length - 1; for (let ii = 10; ii <= endIndex + 10; ii += 10) { filteredSectionData.push({ key: `${filteredData[startIndex].key} - ${ filteredData[Math.min(ii - 1, endIndex)].key }`, data: filteredData.slice(startIndex, ii), }); startIndex = ii; } return ( { this.setState(() => ({filterText})); }} placeholder="Search..." value={this.state.filterText} /> {renderSmallSwitchOption(this, 'virtualized')} {renderSmallSwitchOption(this, 'logViewable')} {renderSmallSwitchOption(this, 'debug')} {renderSmallSwitchOption(this, 'inverted')} scroll to: