question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FlatList inside ScrollView Container in order to support large title

See original GitHub issue

This is mostly an iOS issue.

I’ve been using the Grid component in the zoom sample project as an example.

I have a FlatList that I want to render inside a screen that has:

  • a big title
  • a search bar

To achieve that, I have it wrapped in a ScrollView per the example.

The first thing I receive is a warning:

VirtualizedLists should never be nested inside plain ScrollViews with the same orientation - use another VirtualizedList-backed container instead

Replacing the ScrollView container with a FlatList was a no-go, but admittedly I haven’t tried much else.

Back to the ScrollView: When I pull to refresh the FlatList, the wrapping ScrollView moves instead, and the refresh is never triggered.

If I attempt to attach the RefreshControl to the container ScrollView, I get some undefined behaviour.

Here’s a snippet of what I’m trying out (this is a replacement for the Colors component):

const Colors = ({colors, children, filter}) => {
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    setTimeout(() => setLoading(false), 2000);
  }, [loading]);

  const suffix = filter != null ? '_search' : '';
  const matchedColors = colors.filter(
    color => !filter || color.indexOf(filter.toLowerCase()) !== -1,
  );
  return (
    <NavigationContext.Consumer>
      {({stateNavigator}) => (
        <FlatList
          contentInsetAdjustmentBehavior="automatic"
          data={matchedColors}
          renderItem={({item: color}) => (
            <TouchableHighlight
              key={color}
              style={styles.color}
              underlayColor={color}
              onPress={() => {
                stateNavigator.navigate('detail', {
                  color,
                  name: color + suffix,
                  filter,
                  search: filter != null,
                });
              }}>
              <SharedElement name={color + suffix} style={{flex: 1}}>
                <View style={{backgroundColor: color, flex: 1}} />
              </SharedElement>
            </TouchableHighlight>
          )}
          keyExtractor={item => item}
          onRefresh={() => setLoading(true)}
          refreshing={loading}
        />
      )}
    </NavigationContext.Consumer>
  );
};

Is it possible to get the behaviour that I am after?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
salockhartcommented, Nov 27, 2019

Hey @grahammendick, I haven’t had a chance yet, but I should be able to in the next week or two. I’ll let you know how it goes

0reactions
grahammendickcommented, Nov 27, 2019

@salockhart did you give this a go? I’m keen to know how it worked out

Read more comments on GitHub >

github_iconTop Results From Across the Web

FlatList exceeds its container with its content - Stack Overflow
When you nest a <FlatList /> within a <ScrollView /> you get this warning: Virtualized lists should never be nested inside plain ScrollViews...
Read more >
Display a List Using the FlatList Component in React Native
React Native's `FlatList` component renders list items that can be displayed on the screen, and has features like scrolling, header/footer ...
Read more >
Displaying a List in React Native: Map Method or FlatList ...
The ScrollView is a generic React Native scrolling container that allows both vertical and horizontal direction scrolling. By default, it displays its children ......
Read more >
FlatList - React Native
FlatList. A performant interface for rendering basic, flat lists, supporting the most handy features: Fully cross-platform.
Read more >
React Native Scrollview 101: The Best Practices Guide - Waldo
Read this deep and comprehensive guide on React Native's scrolling containers, which are called ScrollViews.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found