react-native-sortable-list icon indicating copy to clipboard operation
react-native-sortable-list copied to clipboard

Sorting not working in Android

Open saransh-malik opened this issue 5 years ago • 9 comments

Hi,

I am using this package to render a sortable list, which works as intended in iOS but not on android. On Android on longpress it does get active but as soon as I try to move it the view scrolls and the item goes back to its place.

Here is my code :

<View style={styles.container}>
        <View style={styles.header}>
          <TextButton text={`+ ${I18n.t('activityType')}`} textStyle={styles.btnText} onPress={this.goToEditActivityType()} style={styles.button} />
          <View styles={styles.infoText}>
            <Text style={styles.textInfo}>{I18n.t('toggleInfo')}</Text>
            <Text style={styles.textInfo}>{I18n.t('dragInfo')}</Text>
          </View>
        </View>
        <SortableList
          data={this.props.activityTypes}
          renderRow={this.renderItem}
          sortingEnabled
          manuallyActivateRows
          scrollEnabled={true}
          onReleaseRow={this.onReleaseRow}
          onChangeOrder={this.onChangeOrder}
        />
      </View>

Here is the renderRow Code :

<Animated.View style={this._style}>
        <TouchableOpacity
          style={styles.row}
          onPress={this.props.onPress}
          onLongPress={this.props.toggleRowActive}
        >
          <View style={styles.nameNIcon}>
            <Image
              style={[styles.image, !data.active ? styles.inactive : {}]}
              resizeMode='contain'
              source={Images[imageName]}
            />
            <Text style={[styles.text, !data.active ? styles.inactive : {}]}>
              {data.name}
            </Text>
          </View>
          <Switch
            trackColor={{ false: Colors.lightGray, true: Colors.primary }}
            thumbTintColor={Platform.OS === 'ios' ? null : Colors.snow}
            value={data.active}
            onValueChange={this.props.onToggleState}
            style={styles.switch}
          />
        </TouchableOpacity>
      </Animated.View>

React Native Version : 0.59.10 SortableList Version : 0.0.22

saransh-malik avatar Feb 18 '20 08:02 saransh-malik

Also running into this on Android. Seems to be working fine on iOS for me. Overall just seeing pretty different behavior on Android and iOS.

emilionavarro avatar Feb 29 '20 21:02 emilionavarro

Do you have any workaround?

mikraus94 avatar Mar 25 '20 10:03 mikraus94

Okay, It seems like ScrollView is taking control of panResponder,

Setting ScrollEnabled={false} prop makes the reordering work.

Finding a workaround.

@gitim would you recommend anything?

will send a PR when I am able to fix this.

devagul93 avatar Mar 25 '20 22:03 devagul93

Any another workaround if I need use scrolling?

mikraus94 avatar Apr 03 '20 10:04 mikraus94

Adding another ScrollView around SortableList with controlled scrollEnabled works on Android. It is not scrolling when a draggable item on the top or bottom, but it is ok in my case.

<ScrollView scrollEnabled={this.state.scrollEnabled}>
   <SortableList
      scrollEnabled={false}
      onActivateRow={() => this.setState({ scrollEnabled: false })}
      onReleaseRow={() => this.setState({ scrollEnabled: true })}
      onChangeOrder={this.onChangeOrder}
      renderRow={this.renderRow}
   />
</ScrollView>

ivanzotov avatar Apr 03 '20 13:04 ivanzotov

these lines in componentDidUpdate of SortableListComponent are causing this issue :

if (prevProps.scrollEnabled !== scrollEnabled) {
	this.setState({ scrollEnabled: prevProps.scrollEnabled });
}

You can comment them.

billouboq avatar May 17 '20 07:05 billouboq

@ivanzotov I just copied your code, But still sorting is not working for me. Can you share this.renderRow to see how row implementation looks like. Do we need to provide anything to onLongpress or sorting works by default?

Yandamuri avatar Sep 17 '20 16:09 Yandamuri

Hey @sumnerwarren, thanks for your contribution: your fix is actually solving the Android sorting issue. Is there a reason why the PR wasn't merged?

caterinamennito avatar Aug 24 '21 15:08 caterinamennito

@caterinamennito Only because this package does not seem to be maintained anymore. We switched to react-native-draggable-list.

sumnerwarren avatar Sep 02 '21 18:09 sumnerwarren