react-native-gesture-handler icon indicating copy to clipboard operation
react-native-gesture-handler copied to clipboard

Performance issue when using Swipable in flatlist

Open UsamaIkraam0099 opened this issue 3 years ago • 23 comments

Performance issue when using Swipable in Flatlist

Description

Screenshots

Steps To Reproduce

Expected behavior

Actual behavior

Snack or minimal code example

Package versions

  • React: 17.0.1
  • React Native: 0.64.2
  • React Native Gesture Handler: 1.10.3

UsamaIkraam0099 avatar Aug 02 '21 11:08 UsamaIkraam0099

Could you please expand on this one? Preferably with benchmarks and the code you used to show performance issues with Swipeables.

jakub-gonet avatar Aug 02 '21 13:08 jakub-gonet

Basically i apply this on FlatList and when changing on any FlatList item like backgroundcolor or borderColor its slow and taking time but when I remove Swipeable FlatList working fine no issue there. I'll share some code

UsamaIkraam0099 avatar Aug 08 '21 18:08 UsamaIkraam0099

I'm seeing poor performance with Swipeable in a Flatlist too. It can be observed by using the swipeable demo from the example in this repo and increasing the number of data items in the Flatlist (There is an older issue here with users reporting the same). For now I've had to switch over to react-native-interactable but I'd much rather be using this library.

Relevant packages: "react-native": "^0.64.2", "react-native-reanimated": "^2.2.0", "react-native-gesture-handler": "^1.10.3",

astanb avatar Aug 12 '21 12:08 astanb

I'm having this issue too.

As soon as I introduce Swipeable in my Flatlist items the list scrolls much less smoothly. I have a couple of 100 items with a thumbnail and av SVG pie chart. The list scrolls perfectly smooth without Swipeable.

I thought that maybe the flatlist had trouble measuring the height of Swipeable, so I wrapped it with a View with a constant height. This didn't solve the issue. I tried setting height on containerStyle as well as childrenContainerStyle, no difference.

I console.log:ed in the Swipeable source to see if it was re-rendering all the time, but it wasn't. Each Swipeable is rendered twice, but after that no more render is logged while I'm scrolling. I don't know why it renders twice, but this is not the problem anyway.

I'll go ahead and try https://github.com/wix/react-native-interactable instead.

I'd rather use react-native-gesture-handler since I'm using this lib in other places in my app. It would be really awesome if this issue could be solved somehow.

msageryd avatar Dec 28 '21 17:12 msageryd

To illustrate the problem I have made two screen recordings from my iPhone X. The first recording is with a Swipeable wrapping the list items. When I scroll slowly, the performance problem is very visible. Actually, when looking at this I don't know if this really is a performance problem. It looks more lika some kind of layout problem.

The second recording is without Swipeable. Buttery smooth, as you can see.

I appologize for the crappy blurring. This is live client data which I cannot show. I have never used iMovie before, so it looks like sh-t.

With Swipeable https://user-images.githubusercontent.com/4483085/147594877-91e6384b-dee4-41c4-99dc-cb22593de30f.mp4

Without Swipeable https://user-images.githubusercontent.com/4483085/147594895-4eb82773-eca0-4b76-a5c2-03c193399afc.mp4

Edit: I think GitHub might have compressed the video. The second video looks a bit jumpy as well, but I assure you that it is buttery smooth without Swipeable.

msageryd avatar Dec 28 '21 18:12 msageryd

Hi @msageryd, I am running into same performance issues.... have you solved this anyhow?

Haider3iq avatar Feb 03 '22 02:02 Haider3iq

I also have this issue, and I think it may be related to some re-renders due to state changes that I am not causing.

2022-12-01 18 56 32

tylercote avatar Dec 01 '22 23:12 tylercote

Is there any update about this performance issue? Swipeable as of now is not usable in flatlist.

pierroo avatar Jan 15 '23 12:01 pierroo

@jakub-gonet @kkafar

We are also facing the same issue. We are using Swipeable in Shopify's FlashList. Is there any update regarding the performance issue?

9903SV avatar Aug 18 '23 05:08 9903SV

Same issue here, any solution or alternative to Swipeable ?

MensurRasic avatar Aug 23 '23 22:08 MensurRasic

Same here, I detected this using Shopify's FlashList with Swipeable. When they are together a fast scroll will generate blank areas, while removing Swipeable it works very smooth. Any suggestion or any replacement for Swipeable component?

smfunder avatar Sep 15 '23 18:09 smfunder

Same, are there any alternatives

Acetyld avatar Oct 13 '23 19:10 Acetyld

I got same issue, any solution for it?

ngocle2497 avatar Dec 20 '23 04:12 ngocle2497

after i take out swipable the perfomance back to normal, are there any alternatives?

crusherblack avatar Feb 12 '24 03:02 crusherblack

@crusherblack @ngocle2497 @Acetyld @smfunder @UsamaIkraam0099 hello guys, check please code below, works much more smoothly for me <Swipeable onSwipeableWillClose={() => setShowRightAction(false)} onActivated={() => setShowRightAction(true)} renderLeftActions={showRightAction ? renderLeftActions : undefined}> ... </Swipeable>

StasSokolov1 avatar Mar 07 '24 21:03 StasSokolov1

@crusherblack @ngocle2497 @Acetyld @smfunder @UsamaIkraam0099 hello guys, check please code below, works much more smoothly for me <Swipeable onSwipeableWillClose={() => setShowRightAction(false)} onActivated={() => setShowRightAction(true)} renderLeftActions={showRightAction ? renderLeftActions : undefined}> ... </Swipeable>

Did you check performance / fps after implementing this For me it dropped to 30/40fps

Acetyld avatar Mar 08 '24 09:03 Acetyld

@Acetyld

Yes, I'm using FlashList and when i pass undefined to renderLeftActions it works more smoothly but not smooth like without Swipeable, which list you use?

StasSokolov1 avatar Mar 08 '24 10:03 StasSokolov1

hey @Acetyld @stassokolov1 and all the people here. I ended up using Interactable.View. And I use it in combination of FlashList and it is super smooth.

import Interactable from 'react-native-interactable'

  const leftSwipe = (item) => {
    // NOTE: We are no longer using TouchableOpacity in a flat list because it created this issue:
    // https://github.com/facebook/react-native/issues/34376#issuecomment-1231324454
    return (
      <View>
        <Pressable onPress={handlePinUnPinCallback}>
          <FastImage style={styles.pinUnpinMsg} source={item?.isFavorite ? Images.UNPIN_MSG : Images.PIN_MSG} />
        </Pressable>
      </View>
    )
  }

return (
    <View>
      {leftSwipe(groupDetail)}
      <Interactable.View
        ref={swipeRef}
        horizontalOnly={true}
        dragEnabled={isEnableSwipe}
        snapPoints={[{ x: 100 }, { x: 0 }, { x: -150 }]}
        alertAreas={[{ id: 'leftArea', influenceArea: { left: 5 } }, { id: 'rightArea', influenceArea: { right: 5 } }]}
        onAlert={handleOnSwipeAlert}
       >
       <View> Content of the cell </View>
     </Interactable.View>
</View>

smfunder avatar Mar 08 '24 15:03 smfunder

I ended up using Interactable.View. And I use it in combination of FlashList and it is super smooth.

This is exciting. Which specific react-native-interactable package are you using?

rparrett avatar Mar 08 '24 15:03 rparrett

I ended up using Interactable.View. And I use it in combination of FlashList and it is super smooth.

This is exciting. Which specific react-native-interactable package are you using?

@rparrett I'm using "react-native-interactable": "^2.0.1" https://github.com/wix-incubator/react-native-interactable

smfunder avatar Mar 08 '24 16:03 smfunder

I ended up using Interactable.View. And I use it in combination of FlashList and it is super smooth.

This is exciting. Which specific react-native-interactable package are you using?

@rparrett I'm using "react-native-interactable": "^2.0.1" https://github.com/wix-incubator/react-native-interactable

Does it work in expo dev build?

Acetyld avatar Mar 08 '24 16:03 Acetyld

I ended up using Interactable.View. And I use it in combination of FlashList and it is super smooth.

This is exciting. Which specific react-native-interactable package are you using?

@rparrett I'm using "react-native-interactable": "^2.0.1" https://github.com/wix-incubator/react-native-interactable

Does it work in expo dev build?

@Acetyld sorry I don't know, I'm not using expo.

smfunder avatar Mar 08 '24 17:03 smfunder