react-native-draggable-flatlist icon indicating copy to clipboard operation
react-native-draggable-flatlist copied to clipboard

How to scroll when list longer than screen height?

Open fritzfr opened this issue 4 years ago • 28 comments

Hi,

I was wondering what the suggested approach is for lists longer than the screen height. The only way to scroll down seems to be dragging something further down. But I am wondering if it's possible to scroll without changing the order.

fritzfr avatar Jan 23 '20 16:01 fritzfr

The list should scroll like a normal FlatList. What is the behavior you are seeing?

curiousdustin avatar Jan 23 '20 16:01 curiousdustin

I have the same issue but only on android. Seems wipe up gesture is not captured. But if you press and hold for more than 10ms and swipe up scrolling happens.

csath avatar Jan 24 '20 13:01 csath

Are you nesting the flatlist in another scrollable?

computerjazz avatar Jan 24 '20 17:01 computerjazz

I do not.

fritzfr avatar Jan 24 '20 17:01 fritzfr

thanks looking into it now -- there may have been a bug recently introduced

computerjazz avatar Jan 24 '20 17:01 computerjazz

please try 2.1.2 and let me know if the issue is fixed

computerjazz avatar Jan 24 '20 17:01 computerjazz

I was seeing this same issue on iOS. Can confirm that 2.1.2 has fixed the problem for me. @computerjazz Thanks for the quick response!

jschwab923 avatar Jan 24 '20 19:01 jschwab923

I'm using computerjazz/react-native-swipeable-item with draggable flat list. I use latest versions of both libraries and you can find the versions below.

"react-native-draggable-flatlist": "^2.1.1", "react-native-swipeable-item": "^1.1.0", "react-native-gesture-handler": "^1.5.0", "react-native-reanimated": "^1.4.0"

Now application crashes with following error message.

image

csath avatar Jan 25 '20 04:01 csath

@csath That's an issue with react-native-swipeable-item and not related to this issue. I've fixed it in 1.1.1 but please open an issue on that repo if you have future problems with it.

computerjazz avatar Jan 25 '20 06:01 computerjazz

Yip, seems to be resolved for me. Thanks!

fritzfr avatar Feb 17 '20 09:02 fritzfr

I'm finding, Android only:

  • nested horizontal FlatLists will not scroll horizontally but vertical scrolling on the FlatList moves the screen as expected.

  • if I make them nested horizontal DraggableFlatLists (with no drag functionality), they will scroll through the list horizontally but seem to block any vertical scrolling. So if I have an item that is as long as the screen, there's no way to scroll vertically away from it.

iOS works fine.

wstock avatar Feb 23 '20 10:02 wstock

DraggableFlatLists nested in ScrollView. If the length of items in DraggableFlatLists so long, i can't scroll the items. Any solutions?

bkitduy avatar Mar 01 '20 08:03 bkitduy

I'm having the same issue. I have vertical scrollView inside of horizontal DraggableFlatLists. The vertical scrollView doesn't scroll. Does anyone find a solution?

sachix1001 avatar May 03 '20 06:05 sachix1001

I found the FlatList from the gesture handler library behaves as expected when nested in a Draggable FlatList.

import { FlatList } from 'react-native-gesture-handler';

wstock avatar May 03 '20 06:05 wstock

Thanks, wstock!! It worked with gesture handler!! You are legend!

sachix1001 avatar May 04 '20 03:05 sachix1001

Scroll works when touch above DraggableFlatList, but when tries to scroll from DraggableFlatList it does not work else working smooth as perfect

<ScrollView  style={{paddingTop:20}}>
            {this.state.progress ? (<View><Text> ... </Text></View>) :
                (                
                     
                    <DraggableFlatList
                        scrollEnabled={false}                               
                        data={this.state.tempSectionItems}
                        renderItem={this.renderItem}                               
                        keyExtractor={(item, index) => `draggable-item-${item.prior}`}
                        onDragEnd={({ data }) =>  this.reoderFn(data)  }
                      
                    />                        
                   
                )           
            }          
           </ScrollView>

10xamohan avatar May 13 '20 15:05 10xamohan

@10xamohan I'm having the exact same problem. Anybody have a solution?

JosephCon1998 avatar May 17 '20 04:05 JosephCon1998

Removed scrollView and its works fine for me one more thing I am not sure if it's because of that but I replaced RNFlatList with FlatList used in react-native-gesture-handler under node modules

whole code is

<SafeAreaView style={{flex: 1}}>
           <Header onPressBack={this.handleBackPress} title={LocalizedStrings.label.labelReordering}  />
              <View
                  style={{paddingVertical:20,backgroundColor:"#EAF3FA", marginBottom:25}}
                  >
                  <View style={{flexDirection:"row",  marginLeft:20 }}>
                      <Image source={assets.reorderScreen.arrow}  />
                      <Text style={{fontSize:18,marginLeft:15, fontWeight:"500" ,color:'#1C3865'}}>Drag and drop to reorder items</Text>
                  </View>
                 
              </View>
          <DraggableFlatList
            data={this.state.tempSectionItems}
            renderItem={this.renderItem}
            keyExtractor={(item, index) => `draggable-item-${item.prior}`}
            onDragEnd={({ data }) => this.reoderFn(data) }
          />
          <TouchableHighlight onPress={this.saveList}
              style={{margin:20, justifyContent: 'center', backgroundColor:'rgb(28, 56, 101)',height: 50,borderRadius: 25 }} underlayColor={'#6EC8E6'} >
               <Text style={{alignSelf: 'center',color:"white",fontSize: 20}}>{LocalizedStrings.button.save}</Text>
          </TouchableHighlight>
           </SafeAreaView>

10xamohan avatar May 19 '20 08:05 10xamohan

@10xamohan I'm having the exact same problem. Anybody have a solution?

You can check my code

10xamohan avatar May 19 '20 08:05 10xamohan

Hi, I still have a problem on Android, here is the structure of my code:

      `<ScrollView
               refreshControl={
                    <RefreshControl refreshing={this.state.refreshing} onRefresh={() => onRefresh()}/>
                 }
         >

              <View style={styles.viewButonPlus}>
                    <Weather_info ref="weatherInfo" {...this.props} />

                     <ShortTermWeather callBackRefresh={(data) => 
                          this.refs.weatherInfo.refreshData(data)
                      }/>
              </view>

              <DraggableFlatList 
                   scrollEnabled={false}
                   data={this.state.data}
                   renderItem={this.renderItem}
                   keyExtractor={(item, index) => `draggable-item-${item.key}`}
                   onDragEnd={({ data }) => { this.changeDisposition(data) }}
              />
             </View>
      </ScrollView>`

<Weather_info /> contains a flatlist with an horizontal scroll that works perfectly with my structure. My problem comes from the fact that I can't scroll from the elements of my DraggableFlatList. I can't find a solution to my problem, does anyone have the solution ? Big thanks.

gael-explose avatar Jun 17 '20 14:06 gael-explose

I can't scroll either. If I use a <FlatList /> or <SectionList /> everything works correctly. But with <DraggableFlatList /> I can basically only scroll if I drag an item.

EDIT: I was able to resolve this by using activationDistance={100} on the DraggableFlatlist. Maybe it was because I have the list within a tab navigator with swipe gestures.

bill-pairaktaridis avatar Jun 26 '20 07:06 bill-pairaktaridis

Any update on this?

I have a the DraggableFlatlist inside a Scrollview (this is a bigger screen, the DraggableFlatlist is just one list out of many), and vertical scrolls are consumed by the DraggableFlatlist and you can't scroll away if the list is longer than the screen.

activationDistance doesn't work for me, as it breaks dragging the list items - it enables scrolling vertically on the draggableFlatlist items but it breaks the actual dragging and reordering of the list items.

Hope I make sense, anyone managed to solve this? I can't change the ScrollView to gesture-handler version as I am using a KeyboardAwareScrollView...

Svarto avatar Oct 13 '20 06:10 Svarto

I can't scroll either. If I use a <FlatList /> or <SectionList /> everything works correctly. But with <DraggableFlatList /> I can basically only scroll if I drag an item.

EDIT: I was able to resolve this by using activationDistance={100} on the DraggableFlatlist. Maybe it was because I have the list within a tab navigator with swipe gestures.

After adding activationDistance my list can scroll but then unable to drag..

chengsam avatar Dec 17 '20 08:12 chengsam

The simultaneousHandlers attribute can now be used, this was added here https://github.com/computerjazz/react-native-draggable-flatlist/pull/273. Dragging and dropping will work. It will be the same with FlatList, but you need to create a ref in a slightly different way. Here's my example:

import React, { useState, useCallback, useRef } from 'react'
import { View, Text, StyleSheet } from 'react-native'
import { FlatList } from 'react-native-gesture-handler'
import DraggableFlatList from 'react-native-draggable-flatlist'
import SectionHeader from '../common/SectionHeader'


const DraggableSectionList = ({ sections, keyExtractor, onEndReached, onRefresh, refreshing,
  ListEmptyComponent, ListFooterComponent, onScroll, onScrollEndDrag, onMomentumScrollEnd }) => {

  const parentRef = useRef(null)
  const [stopScroll, setStopScroll] = useState(false)

  const renderSection = useCallback(({ item: section, index }) => {
    return (
      <DraggableFlatList data={section.data}
                         renderItem={section.renderItem}
                         keyExtractor={keyExtractor}
                         simultaneousHandlers={parentRef}
                         onDragBegin={() => setStopScroll(true)}
                         onRelease={() => setStopScroll(false)}
                         onDragEnd={section.onDragEnd}
      />
    )
  }, [])

  const _keyExtractor = (item, index) => item.key
  const _separator = () => <SectionHeader date={''}/>
  return (
    <FlatList data={sections}
              renderItem={renderSection}
              keyExtractor={_keyExtractor}
              onEndReached={onEndReached}
              onRefresh={onRefresh}
              refreshing={refreshing}
              ListEmptyComponent={ListEmptyComponent}
              ListFooterComponent={ListFooterComponent}
              ItemSeparatorComponent={_separator}
              initialNumToRender={15}
              onEndReachedThreshold={0.5}
              scrollEventThrottle={5}
              onScroll={onScroll}
              onScrollEndDrag={onScrollEndDrag}
              onMomentumScrollEnd={onMomentumScrollEnd}
              ref={(f) => f && (parentRef.current = f._listRef._scrollRef)}
              scrollEnabled={!stopScroll}
    />
  )
}

export default React.memo(DraggableSectionList)

From the important points, I note that ScrollView and FlatList must be imported from the 'react-native-gesture-handler' library of version 1.10.0 or higher.

Also, unfortunately, there is a bug related to the 'react-native-gesture-handler' library - onRefresh will not work on android. (bug) But maybe it will help someone anyway.

JerakRus avatar Jul 18 '21 16:07 JerakRus

Thanks for great library. I found pretty easy solution without simultaneousHandlers

const [scrollEnable, setScrollEnable] = useState(true);
const renderItem = useCallback(({ item, index, drag, isActive }) => {
    return (
      <View
        style={{
          height: 100,
          backgroundColor: isActive ? 'red' : item.backgroundColor,
          alignItems: 'center',
          justifyContent: 'center',
        }}>
        <Text
          style={{
            fontWeight: 'bold',
            color: 'white',
            fontSize: 32,
          }}>
          {item.label}
        </Text>
        <TouchableOpacity onPressIn={drag}>
          <Text>drag</Text>
        </TouchableOpacity>
      </View>
    );
  }, []);
  return (
<DraggableFlatList
        data={data}
        renderItem={renderItem}
        activationDistance={scrollEnable ? 100 : 1}
        keyExtractor={(item, index) => `draggable-item-${item.key}`}
        onDragBegin={() => setScrollEnable(false)}
        onDragEnd={({ data: item }) => {
          setData(item);
          setScrollEnable(true);
        }}
      />)

dreamkyr avatar Aug 10 '21 04:08 dreamkyr

Still no luck of using DraggableFlatList inside ScrollView, when content of flatList goes beyond the screen. Autoscroll autoscrollSpeed and autoscrollThreshold also doesn't work. Has anyone figure out stable solution to this?

Andriiklymiuk avatar Mar 16 '22 11:03 Andriiklymiuk

I was able to get scrolling, dragging, and auto scrolling working by providing the ListHeaderComponent and ListFooterComponent props with the content I needed to be above and below the draggable items.

Instead of nesting DraggableFlatList inside a ScrollView I used it as the top level scroll view, with extra content above and below

sliptype avatar Mar 21 '22 23:03 sliptype

im facing a issue where the items always scrolls to the top when the item is bigger than the DraggableFlatlist height

rohankm avatar Mar 15 '24 22:03 rohankm