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

V2 #81

Merged
merged 100 commits into from
Dec 13, 2019
Merged

V2 #81

merged 100 commits into from
Dec 13, 2019

Conversation

computerjazz
Copy link
Owner

@computerjazz computerjazz commented Aug 22, 2019

@lafiosca
Copy link

Ok because I'm too curious and couldn't leave well enough alone, I simplified the test more to just be color blocks of text, and I'm still having the issues:

draggable-v2-simple

The list code looks like:

						<DraggableFlatList<string>
							data={['foo', 'bar', 'baz']}
							renderItem={renderDraggableCard}
							keyExtractor={(item) => item}
							refreshControl={refreshControl}
							ListEmptyComponent={emptyView}
							onDragBegin={(index) => {
								console.log(`Begin dragging index ${index}`);
							}}
							onDragEnd={({ from, to }) => {
								console.log(`End dragging from index ${from} to index ${to}`);
							}}
						/>

The render function:

		const renderDraggableCard = ({
			item,
			index,
			drag,
			isActive,
		}: {
			item: string,
			index: number,
			drag: () => void,
			isActive: boolean,
		}) => (
			<TouchableOpacity onLongPress={drag}>
				<Text style={[
					{
						width: '100%',
						height: 150,
						margin: 8,
						padding: 12,
						fontSize: 36,
						backgroundColor: index === 0 ? 'blue' : index === 1 ? 'green' : 'red',
					},
					isActive ? { borderWidth: 8, borderColor: 'magenta' } : {},
				]}>
					{item}
				</Text>
			</TouchableOpacity>
		);

And then piece by piece I ripped everything out of the app and brought this up to the top level, surrounded only by a container view of flex: 1 and no context providers. Still behaved like this.

I'm going to have to cut off the investigation here, but for reference, here are the relevant library versions I am using:

react-native 0.61.4
react-native-gesture-handler 1.5.0
react-native-reanimated 1.4.0
react-native-draggable-flatlist 2.0.1

@computerjazz
Copy link
Owner Author

@lafiosca thanks so much for the example! I can repro on my end now, but only when I do not set state on drag end. This wasn't a use case I was planning for, since usually you want to update your list data in response to the drag, but agree it's definitely a bug. I will look into it — I'm hoping it's as easy as forcing a rerender on drag end, whether data prop changes or not.

Can you verify that it works when you set new data in onDragEnd?
Example here:
https://gist.github.com/computerjazz/436f513ef40d37dd7da0c4fbfd93c732

@computerjazz
Copy link
Owner Author

@lafiosca should be fixed in 2.0.2. Thanks!

@computerjazz
Copy link
Owner Author

computerjazz commented Nov 22, 2019

Oh and I should probably make the docs more clear, but if you are not setting updated data as your data source after a drag, your list will jump back to its original position. In other words -- the component tells you what happened as a result of the drag, but you are responsible for updating the data source. Usually it's as simple as onDragEnd={({ data }) => this.setState({ data })} (or whatever state container you use)

@lafiosca
Copy link

Glad that helped. I was definitely assuming the latter and intended on wiring up the data update later, just didn’t expect the lack of updating during my trial to cause a bug.

There was also the separate problem with something in the full-blown version of my app conflicting with the smooth item animations and positioning, but I’m probably not going to have time to dig in on that.

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

Successfully merging this pull request may close these issues.

4 participants