Skip to content
New issue

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.

Already on GitHub? Sign in to your account

[Flatlist] getItemLayout fires multiple times upon every frame scrolled manually #20467

Closed
newah opened this issue Jul 31, 2018 · 9 comments
Closed
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@newah
Copy link

newah commented Jul 31, 2018

Environment

Environment:
OS: macOS High Sierra 10.13.6
Node: 8.9.4
Yarn: 1.3.2
npm: 5.5.1
Watchman: 4.9.0
Xcode: Xcode 9.4.1 Build version 9F2000
Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
react: 16.4.0 => 16.4.0
react-native: ^0.55.4 => 0.55.4

iOS

Description

Without getItemLayout flatlist works as expected - fast. With getItemLayout we started noticing rows aren't loading instantly when scrolling manually. After removing getItemLayout performance is good again.

We are using shouldComponentUpdate (also tried PureComponent).

In the gif you can see logs that getItemLayout is firing constantly when using flatlist manually - which seems to be why performance is suffering. Is this to be expected?

ezgif com-video-to-gif

Reproducible Demo

Simplified my use-case with reusing part of someone else's demo :)

class MyListItem extends React.PureComponent {
    render() {
        return (
            <View
                style={{
                    paddingVertical: 10,
                }}>
                <TouchableOpacity onPress={() => null}>
                    <Text
                        style={{
                            color: '#000',
                            height: 40,
                            justifyContent: 'center'
                        }}>
                        lalalalaal
                      </Text>
                </TouchableOpacity>
            </View>
        )
    }
}

_renderItem = ({ item }) => (
    <MyListItem
        produto={item.produto}
    />
);

render() {
                    return <FlatList
                    data={['one', 'two', 'three', 'one', 'two', 'three', 'one', 'two', 'three', 'one', 'two', 'three', 'one', 'two', 'three', 'one', 'two', 'three', 'one', 'two', 'three', 'one', 'two', 'three', 'one', 'two', 'three', 'one', 'two', 'three']}
                    showsVerticalScrollIndicator={false}
                    initialListSize={4}
                    renderItem={_renderItem}
                    keyExtractor={(item, index) => '' + index}
                    ref={(ref) => { this.flatListRef = ref }}
                    getItemLayout={(data, index) => {
                        console.log("get item layout " + index)
                        return { length: 40, offset: 40 * index, index }
                    }}
                />
}

Expected behavior

getItemLayout only fires when scrollToIndex or similar methods are fired. Or at most when rows are actually re-rendering - though it doesn't look like it's used when simply rendering visible rows.

@react-native-bot
Copy link
Collaborator

    It looks like your issue may be missing some necessary information. Can you run `react-native info` and edit your issue to include these results under the **Environment** section?

If you believe this information is irrelevant to the reported issue, you may write [skip envinfo] under Environment to let us know.

@srameshr
Copy link

srameshr commented Aug 2, 2018

Even I experience this. getItemLayout gets triggered on scroll

@react-native-bot
Copy link
Collaborator

Have you been able to reproduce this on the latest release, 0.56?

@srameshr
Copy link

srameshr commented Aug 2, 2018

Have not tried it on 0.56. Im on 0.55

@react-native-bot react-native-bot added the Ran Commands One of our bots successfully processed a command. label Aug 10, 2018
@react-native-bot
Copy link
Collaborator

I am closing this issue because it does not contain the necessary environment info, and there has been no followup in a while.

If you found this thread after encountering the same issue in the latest release, please feel free to create a new issue with up-to-date information by clicking here.

@newah
Copy link
Author

newah commented Aug 10, 2018

@react-native-bot what environment info is missing? Provided it as requested, along with a detailed example and visuals to clearly understand the problem.

@newah
Copy link
Author

newah commented Aug 10, 2018

@react-native-bot tested with 0.56. Issues still exists.

@srameshr
Copy link

@react-native-bot bad bot

@sesam
Copy link

sesam commented Oct 9, 2018

the bot closed because of this: #20467 (comment)

(Maybe add a bot feature request that it should warn it might close the issue if the environment info is not filled in, OR not complain about that part when closing and just reference the issue being seemingly stale.)

@facebook facebook locked as resolved and limited conversation to collaborators Aug 10, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Aug 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants