mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-15 12:12:31 +08:00
fix crash with onEndReached={null}
Reviewed By: bvaughn Differential Revision: D4815310 fbshipit-source-id: 69d4a5a6fd247bdf877465a7cd07924a0dd6584b
This commit is contained in:
committed by
Facebook Github Bot
parent
e0bd35f76f
commit
b12f6db0ef
@@ -62,7 +62,7 @@ class FlatListExample extends React.PureComponent {
|
||||
static description = 'Performant, scrollable list of data.';
|
||||
|
||||
state = {
|
||||
data: genItemData(1000),
|
||||
data: genItemData(100),
|
||||
debug: false,
|
||||
horizontal: false,
|
||||
filterText: '',
|
||||
@@ -142,6 +142,7 @@ class FlatListExample extends React.PureComponent {
|
||||
}
|
||||
legacyImplementation={false}
|
||||
numColumns={1}
|
||||
onEndReached={this._onEndReached}
|
||||
onRefresh={this._onRefresh}
|
||||
onScroll={this.state.horizontal ? this._scrollSinkX : this._scrollSinkY}
|
||||
onViewableItemsChanged={this._onViewableItemsChanged}
|
||||
@@ -157,6 +158,11 @@ class FlatListExample extends React.PureComponent {
|
||||
_getItemLayout = (data: any, index: number) => {
|
||||
return getItemLayout(data, index, this.state.horizontal);
|
||||
};
|
||||
_onEndReached = () => {
|
||||
this.setState((state) => ({
|
||||
data: state.data.concat(genItemData(100, state.data.length)),
|
||||
}));
|
||||
};
|
||||
_onRefresh = () => alert('onRefresh: nothing to refresh :P');
|
||||
_renderItemComponent = ({item}) => {
|
||||
return (
|
||||
|
||||
@@ -39,9 +39,9 @@ const {
|
||||
|
||||
type Item = {title: string, text: string, key: number, pressed: boolean, noImage?: ?boolean};
|
||||
|
||||
function genItemData(count: number): Array<Item> {
|
||||
function genItemData(count: number, start: number = 0): Array<Item> {
|
||||
const dataBlob = [];
|
||||
for (let ii = 0; ii < count; ii++) {
|
||||
for (let ii = start; ii < count + start; ii++) {
|
||||
const itemHash = Math.abs(hashCode('Item ' + ii));
|
||||
dataBlob.push({
|
||||
title: 'Item ' + ii,
|
||||
|
||||
Reference in New Issue
Block a user