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.

[v4] Dynamic height with FlatList not scrolling.

See original GitHub issue

Bug

When using the useBottomSheetDynamicSnapPoints together with BottomSheetFlatList, it’s not possible to scroll the list anymore.

https://user-images.githubusercontent.com/16881226/134593038-28bd8fc6-841c-4e91-a380-b0a231b7e70d.MP4

Environment info

Library Version
@gorhom/bottom-sheet 4.0.3
react-native 0.64.2
react-native-reanimated 2.2.2
react-native-gesture-handler 1.10.3

Steps To Reproduce

  1. add a BottomSheet with the animatedSnapPoints, animatedContentHeight and animatedHandleHeight provided by useBottomSheetDynamicSnapPoints
  2. set the handleContentLayout to the child
  3. add a big enough list to overflow the screen

Describe what you expected to happen:

  1. it’s not possible to scroll anymore

Reproducible sample code

Here’s a Snack to reproduce: https://snack.expo.dev/@alexisloiselle/dynamic-height-with-flatlist-not-scrolling

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:23
  • Comments:22 (1 by maintainers)

github_iconTop GitHub Comments

22reactions
VyacheslavAAcommented, Sep 28, 2021

Hello @alexisloiselle !

I had the same issue with BottomSheetScrollView.

As a temporary solution you can use BottomSheetScrollView and change height property for BottomSheetScrollView using useAnimatedStyle to constraint height of BottomSheetScrollView . Also, to prevent infinity loop for handleContentLayout you need to add additional View with onLayout handler as BottomSheetScrollView child.

Here is example:

import BottomSheet, {
  BottomSheetScrollView,
  useBottomSheetDynamicSnapPoints
} from '@gorhom/bottom-sheet';
import React, { useMemo } from 'react';
import { useWindowDimensions, View } from 'react-native';
import { useAnimatedStyle } from 'react-native-reanimated';

export const YourComponent = () => {
  const { height: windowHeight } = useWindowDimensions();

  const initialSnapPoints = useMemo(() => [350, 'CONTENT_HEIGHT'], []);
  const {
    animatedHandleHeight,
    animatedSnapPoints,
    animatedContentHeight,
    handleContentLayout,
  } = useBottomSheetDynamicSnapPoints(initialSnapPoints);

  const scrollViewAnimatedStyles = useAnimatedStyle(() => {
    const contentHeight = animatedContentHeight.value;
    const handleHeight = animatedHandleHeight.value;
    const bottomSheetHeight = handleHeight + contentHeight;

    return {
      height:
        bottomSheetHeight > windowHeight
          ? windowHeight - handleHeight
          : bottomSheetHeight,
    };
  });

  return (
    <BottomSheet
      snapPoints={animatedSnapPoints}
      handleHeight={animatedHandleHeight}
      contentHeight={animatedContentHeight}
    >
      <BottomSheetScrollView style={scrollViewAnimatedStyles}>
        <View onLayout={handleContentLayout}>{/* Children here */}</View>
      </BottomSheetScrollView>
    </BottomSheet>
  );
};
15reactions
gorhomcommented, Oct 3, 2021

dynamic snap points currently working only with views, there are still some work to get it working with scrollables

Read more comments on GitHub >

github_iconTop Results From Across the Web

FlatList not scrolling due to items not having a fixed height
I have noticed that my FlatList won't scroll unless I set a fixed height to my items being rendered. I do not want...
Read more >
Dynamic height with FlatList not scrolling - Expo Snack
Dynamic height with FlatList not scrolling. Reproducible issue template for Bottom Sheet v4. Open with Expo Go. Open in editor ...
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 >
react native flatlist dynamic height, flatlist not scrolling to end, flatlist ...
The dynamic height will be managed by the ScollView parent. React Native FlatList with columns, Last item width. 4. flatlist with dynamic numColumns....
Read more >
8 ways to optimize React native FlatList performance
If your list items have dynamic height then you won't be able to use this method. Try to modify your list items design...
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