Skip to content

fix: support bidirectional (up & down) swipe-to-dismiss#156

Merged
saseungmin merged 3 commits into
saseungmin:mainfrom
cljamal:main
Apr 19, 2026
Merged

fix: support bidirectional (up & down) swipe-to-dismiss#156
saseungmin merged 3 commits into
saseungmin:mainfrom
cljamal:main

Conversation

@cljamal
Copy link
Copy Markdown
Contributor

@cljamal cljamal commented Apr 15, 2026

Problem

Currently the dismiss gesture only triggers when swiping down (translationY > threshold). Swiping up does nothing, which feels unnatural β€” most image viewers (Instagram, Telegram, etc.) dismiss on both directions.

Fix

Two minimal changes in useGestureViewer.ts:

  1. Use Math.abs(event.translationY) in the dismiss condition so both up and down swipes trigger dismiss.
  2. Use Math.abs(translateY.value) in the backdrop opacity interpolation so the background fades correctly when swiping upward.

Changes

  • onEnd: event.translationY > threshold β†’ Math.abs(event.translationY) > threshold
  • backdropStyle: interpolate(translateY.value, ...) β†’ interpolate(Math.abs(translateY.value), ...)

Summary by CodeRabbit

  • Bug Fixes
    • Gesture viewer dismissal now recognizes vertical drags in both upward and downward directions, improving reliability of swipe-to-dismiss interactions.
    • Backdrop fade animation updated to respond symmetrically to upward and downward drags, ensuring consistent visual feedback while dragging.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 15, 2026

⚠️ No Changeset found

Latest commit: e138e86

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 15, 2026

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ff25ad76-a10a-4151-9abe-4bcfac66a992

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 5273b53 and e138e86.

πŸ“’ Files selected for processing (1)
  • src/useGestureViewer.ts
βœ… Files skipped from review due to trivial changes (1)
  • src/useGestureViewer.ts

πŸ“ Walkthrough

Walkthrough

Updated dismiss gesture and backdrop fade in src/useGestureViewer.ts to use absolute vertical translation so dismissal and backdrop opacity respond symmetrically to upward or downward drags when the translation magnitude exceeds the threshold.

Changes

Cohort / File(s) Summary
Gesture Dismissal Logic
src/useGestureViewer.ts
Change dismissal check to use Math.abs(event.translationY) so both upward and downward drags can trigger dismissal; backdrop opacity interpolation now uses Math.abs(translateY.value) for symmetric fading.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • PR #32: Modifies src/useGestureViewer.ts to make vertical-dismiss and backdrop-opacity logic direction-agnostic.
  • PR #84: Adjusts dismiss-pan gesture logic in src/useGestureViewer.ts related to dismiss behavior and configuration handling.

Suggested labels

size/S

Poem

🐰 A hop up, a hop down, I sway,

With numbers absolute, I find my way.
Threshold crossed, the curtain falls,
A symmetric fade across the walls.
Hooray for gestures β€” come what may!

πŸš₯ Pre-merge checks | βœ… 3
βœ… Passed checks (3 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title 'fix: support bidirectional (up & down) swipe-to-dismiss' directly and clearly summarizes the main change: enabling dismiss gestures in both upward and downward directions.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

πŸ€– Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/useGestureViewer.ts`:
- Around line 478-479: The docs in src/types.ts for the dismiss API (references:
onDismiss and fadeBackdrop) still describe downward-only dismissal, but the
runtime (useGestureViewer.ts β€” check the canDismiss branch and
scheduleOnRN(handleDismiss) using event.translationY and
dismissOptions.threshold) now dismisses on both upward and downward swipes;
update the comment block describing onDismiss/fadeBackdrop (the existing doc
lines ~185-211) to state that dismissal is bidirectional (both positive and
negative translationY beyond threshold) and mention any related behavior (e.g.,
backdrop fade applies for either direction) so the API docs match the
implemented logic.
πŸͺ„ Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 49d57fac-9584-42db-982a-521f3c0b5e9d

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between d463527 and 5273b53.

πŸ“’ Files selected for processing (1)
  • src/useGestureViewer.ts

Comment thread src/useGestureViewer.ts
@saseungmin
Copy link
Copy Markdown
Owner

saseungmin commented Apr 19, 2026

@cljamal
Thanks for opening this PR β€” I think this is a good change, and I had actually been planning work around this area as well.

That said, changing the current behavior from downward-only dismiss to bidirectional dismiss by default could be a little confusing from a library/API perspective, since it changes the existing behavior users may already rely on.

So I’m going to merge this PR, and then follow it up with an API update so users can choose the dismiss direction explicitly through:

dismiss?: {
  direction?: 'down' | 'up' | 'both';
}

This way, users will be able to choose the dismiss direction explicitly, while we keep the behavior clear and predictable.

This is planned for v2.3.0. Once that work is finished and released, I’ll leave another comment here with the update.
Thanks again for the contribution.

@saseungmin saseungmin merged commit 63c258f into saseungmin:main Apr 19, 2026
5 checks passed
Copy link
Copy Markdown
Owner

Quick update: this has now been released in v2.3.0.

As a follow-up, I added configurable dismiss directions via:

dismiss.direction?: 'down' | 'up' | 'both'

The default remains down for backward compatibility, and users can now explicitly choose the dismiss direction they want.

Release: https://github.com/saseungmin/react-native-gesture-image-viewer/releases/tag/react-native-gesture-image-viewer%402.3.0

Thanks again for the contribution!

@cljamal
Copy link
Copy Markdown
Contributor Author

cljamal commented Apr 21, 2026

@saseungmin

Really glad my suggestion was helpful! The changes you made are honestly really elegant β€” thanks for that. And thank you for the package itself, it's been super useful to me. It felt great to finally contribute even a small piece back! πŸ™Œ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants