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.

focusHook causes list to become unscrollable

See original GitHub issue

Bug

There is an issue when using the focusHook prop on a BottomSheetFlatList. Opening the bottom sheet works fine and the list is scrollable, however when the BottomSheet component re-renders it locks the scrolling of the list.

Some investigation reveals that the re-rendering of BottomSheet causes ContentWrapper to also re-render, re-setting maxDeltaY. I can see that without focusHook, the function refreshUIElements is usually called which sets the maxDeltaY to 0 and enables scrolling. For some reason this is not happening with focusHook.

Environment info

Both iOS and Android

Library Version
@gorhom/bottom-sheet 1.4.1
react-native 0.63.3
react-native-reanimated 2.0.0-alpha.7
react-native-gesture-handler 1.8.0

Steps To Reproduce

  1. Load the example
  2. Open the bottom sheet and scroll the list
  3. Tap on a list item which triggers a re-render of the parent component.
  4. Attempt to scroll the list

Reproducible sample code

import React from 'react';
import BottomSheet, { BottomSheetFlatList, TouchableOpacity } from '@gorhom/bottom-sheet';
import { useFocusEffect, NavigationContainer } from '@react-navigation/native';

import { View, AppRegistry, LogBox } from 'react-native';
import { useState } from 'react';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { createStackNavigator } from '@react-navigation/stack';

const Stack = createStackNavigator();

function Test() {
    const [, reRender] = useState(-1);

    return (
        <SafeAreaProvider>
            <BottomSheet snapPoints={[100, 600]}>
                <NavigationContainer>
                    <Stack.Navigator>
                        <Stack.Screen name="List">
                            {(props) => (
                                <BottomSheetFlatList
                                    focusHook={useFocusEffect}
                                    data={[...new Array(20)]}
                                    keyExtractor={(_, i) => i.toString()}
                                    renderItem={({ index }) => (
                                        <TouchableOpacity onPress={() => reRender(index)}>
                                            <View
                                                style={{
                                                    backgroundColor: 'red',
                                                    height: 50,
                                                    marginTop: 10
                                                }}
                                            />
                                        </TouchableOpacity>
                                    )}
                                />
                            )}
                        </Stack.Screen>
                    </Stack.Navigator>
                </NavigationContainer>
            </BottomSheet>
        </SafeAreaProvider>
    );
}

AppRegistry.registerComponent('Test', () => Test);

Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fcandicommented, Nov 12, 2020

@tankers746 thx!

I have the same problem with a BottomSheetFlatList inside a Navigator inside the Sheet. “Most” of the times (but not always), the FlatList is not scrollable. In my case, it does not make any difference, if I pass on focusHook to the List or not. I am not sure if I experience the same bug or if I maybe made some other mistake using the component…

Andreas

0reactions
tankers746commented, Dec 8, 2020

Fixed in V2

Read more comments on GitHub >

github_iconTop Results From Across the Web

DSMC2 GEMINI Operation Guide v7.1 - RED camera
Install only the focus hook screw to this mounting point. Damage to the media bay or other components of the camera system caused...
Read more >
WeeChat ChangeLog
New features. core: check bar conditions in root bars and on each update of a bar item. core: fully evaluate commands bound to...
Read more >
RED RAVEN Operation Guide - Cinequipt
Install only the focus hook or set screw to this mounting point. Damage to the media bay or other components of the camera...
Read more >
Scrollview scroll to bottom react native
Props focusHook This needed when bottom sheet used with. ... [0]} will cause the first child to be fixed to the top of...
Read more >
The react-native-bottom-sheet from gorhom - Coder Social
Regular views in bottom sheet become unresponsive to gestures after list has been scrolled ... focusHook causes list to become unscrollable ...
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