Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting not working in Android #188

Open
saransh-malik opened this issue Feb 18, 2020 · 9 comments
Open

Sorting not working in Android #188

saransh-malik opened this issue Feb 18, 2020 · 9 comments

Comments

@saransh-malik
Copy link

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

@emilionavarro
Copy link

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.

@mikraus94
Copy link

Do you have any workaround?

@devagul93
Copy link

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.

@mikraus94
Copy link

Any another workaround if I need use scrolling?

@ivanzotov
Copy link

ivanzotov commented Apr 3, 2020

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>

@billouboq
Copy link

these lines in componentDidUpdate of SortableListComponent are causing this issue :

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

You can comment them.

@Yandamuri
Copy link

@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?

@caterinamennito
Copy link

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?

@sumnerwarren
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants