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

How to recentered "All swipeable" when user press/touch outside the swipeable container? #86

Open
Steffi3rd opened this issue Sep 12, 2019 · 3 comments

Comments

@Steffi3rd
Copy link

I have a Flatlist with Swipeable Item.

When I swipe one item, how to recenter() when I click anywhere on the Flatlist?

The behavior is like "Clock" app in iOS

@AdrianoRuberto
Copy link

AdrianoRuberto commented Sep 16, 2019

You can have the ref on each object that you have, and call recenter() on each one when you need it:

// Object containing an index to each ref
swipeablesRef = Object.create(null);

// Set the ref somehow, for example:
if (!swipeablesRef[index]) swipeablesRef[index] = React.createRef();
<Swipeable ref={swipeablesRef[index]}>...</Swipeable>

// Call this when you need to recenter each swipeable
recenterAll = () => {
  Object.values(swipeablesRef).filter(s => s.current).forEach(s => s.current.recenter());
}

// Call this when you delete one swipeable
deleteSwipeable = index => delete swipeablesRef[index];

@maykonmeier
Copy link

You can have the ref on each object that you have, and call recenter() on each one when you need it:

// Object containing an index to each ref
swipeablesRef = Object.create(null);

// Set the ref somehow, for example:
if (!swipeablesRef[index]) swipeablesRef[index] = React.createRef();
<Swipeable ref={swipeablesRef[index]}>...</Swipeable>

// Call this when you need to recenter each swipeable
recenterAll = () => {
  Object.values(swipeablesRef).filter(s => s.current).forEach(s => s.current.recenter());
}

// Call this when you delete one swipeable
deleteSwipeable = index => delete swipeablesRef[index];

It works for me. Thanks

@renankanu
Copy link

You can have the ref on each object that you have, and call recenter() on each one when you need it:

// Object containing an index to each ref
swipeablesRef = Object.create(null);

// Set the ref somehow, for example:
if (!swipeablesRef[index]) swipeablesRef[index] = React.createRef();
<Swipeable ref={swipeablesRef[index]}>...</Swipeable>

// Call this when you need to recenter each swipeable
recenterAll = () => {
  Object.values(swipeablesRef).filter(s => s.current).forEach(s => s.current.recenter());
}

// Call this when you delete one swipeable
deleteSwipeable = index => delete swipeablesRef[index];

It works for me. Thanks

Working, nice!

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

4 participants