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

Returning Swipeable reference #2105

Merged
merged 5 commits into from
Sep 20, 2022
Merged

Conversation

franck-nadeau
Copy link
Contributor

@franck-nadeau franck-nadeau commented Jun 15, 2022

Description

The following code allows me to do the following two things:

  1. Close any previously opened Swipeable views when one is opened
  const openedRow = useRef();
  function renderItem({item: payable, index, separators}) {
    return (
      <Swipeable
        onSwipeableWillOpen={() => openedRow.current?.close()} // Close a previously opened row
        onSwipeableOpen={(_, swipeable) => (openedRow.current = swipeable)} // Keep a link to the currenlty
  1. Close a Swipeable view when it is being deleted.
        renderRightActions={(_, __, swipeable) => {
          return (
             <TouchableOpacity
                onPress={() => {
                  swipeable.close(); // Close the Swipeable when the user presses the button

Resolves this issue: #764

Test plan

Made these changes in my own app and used patch-package. It has been working fine for my needs.

The following code allows me to do the following two things:

1. Close any previously opened Swipeable views when one is opened

````
  const openedRow = useRef();
  function renderItem({item: payable, index, separators}) {
    return (
      <Swipeable
        onSwipeableWillOpen={() => openedRow.current?.close()} // Close a previously opened row
        onSwipeableOpen={(_, swipeable) => (openedRow.current = swipeable)} // Keep a link to the currenlty
````

2. Close a Swipeable view when it is being deleted.
````
        renderRightActions={(_, __, swipeable) => {
          return (
             <TouchableOpacity
                onPress={() => {
                  swipeable.close(); // Close the Swipeable when the user presses the button
````
Copy link
Member

@j-piasecki j-piasecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! First of all, sorry for the delay, could you update formatting so it passes lint check?

@olivertylsar
Copy link

Any updates on this one?

src/components/Swipeable.tsx Outdated Show resolved Hide resolved
src/components/Swipeable.tsx Outdated Show resolved Hide resolved
src/components/Swipeable.tsx Show resolved Hide resolved
Copy link
Member

@j-piasecki j-piasecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't noticed I can edit your PR, sorry for the delay.

@j-piasecki j-piasecki merged commit 597fc81 into software-mansion:main Sep 20, 2022
j-piasecki pushed a commit that referenced this pull request Apr 5, 2023
## Description

<!--
Description and motivation for this PR.

Include 'Fixes #<number>' if this is fixing some issue.
-->


#2105
returned the Swipeable reference, but only for `renderRightActions`.

This MR aims to return that same reference on `renderLeftActions` also.
The use case is the same.

## Test plan

<!--
Describe how did you test this change here.
-->

I've been using my fork on a few personal projects and it's working as
expected.
@Sotatek-QuanDo
Copy link

Excuse me, isn't it ip you opened row 1 and close it, when you open it again, it will auto close? I'm facing this issue right now

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.

None yet

4 participants