Skip to content

feat: add viewer single-tap callbacks and tap events#158

Merged
saseungmin merged 5 commits into
mainfrom
feat/single-tap-events
Apr 18, 2026
Merged

feat: add viewer single-tap callbacks and tap events#158
saseungmin merged 5 commits into
mainfrom
feat/single-tap-events

Conversation

@saseungmin
Copy link
Copy Markdown
Owner

@saseungmin saseungmin commented Apr 18, 2026

This release adds onSingleTap to GestureViewer so you can handle confirmed single taps without overlaying an extra pressable on top of the viewer.

<GestureViewer
  data={images}
  renderItem={renderImage}
  onSingleTap={() => setShowControls((prev) => !prev)}
/>

It also adds a tap event to useGestureViewerEvent, currently emitting confirmed single taps with { kind: 'single', x, y, index }.

useGestureViewerEvent('tap', (event) => {
  if (event.kind === 'single') {
    console.log(`Tapped item ${event.index} at (${event.x}, ${event.y})`);
  }
});

This improves common viewer UI patterns such as toggling headers, toolbars, counters, or captions on tap while preserving swipe, pinch, dismiss, and double-tap zoom behavior.

Related discussion: #157

Summary by CodeRabbit

  • New Features

    • Added onSingleTap callback prop to detect single-tap interactions on the viewer with tap coordinates (x, y) and item index.
    • Added 'tap' event support to event subscriptions with confirmed single-tap data.
  • Documentation

    • Updated usage guides with examples for the new single-tap handling feature (English and Korean).
    • Added recommended patterns for fullscreen tap handling.
  • Tests

    • Added test coverage for tap event functionality.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 18, 2026

🦋 Changeset detected

Latest commit: ba80a15

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 18, 2026

Warning

Rate limit exceeded

@saseungmin has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 49 minutes and 42 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 49 minutes and 42 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 28263094-0779-4cf5-ba74-83fd9a91f5f8

📥 Commits

Reviewing files that changed from the base of the PR and between fb2c333 and ba80a15.

📒 Files selected for processing (1)
  • src/useGestureViewerPaging.web.ts
📝 Walkthrough

Walkthrough

This PR introduces single-tap event handling to GestureViewer via a new onSingleTap prop and corresponding 'tap' event system. Changes span type definitions, gesture recognition logic, web platform-specific implementation, event emission, testing, and documentation updates across English and Korean guides.

Changes

Cohort / File(s) Summary
Type Definitions & Exports
src/types.ts, src/index.tsx
Added GestureViewerSingleTapEvent<ItemT> exported type, onSingleTap prop to GestureViewerProps, 'tap' event type to GestureViewerEventType, and SingleTapEventData payload type for tap event structure.
Core Gesture & Event Logic
src/useGestureViewer.ts, src/GestureViewerManager.ts
Implemented single-tap gesture recognition using Gesture.Tap().numberOfTaps(1), added emitSingleTap handler with validation, integrated tap gesture into exclusive gesture hierarchy, and added emitTap method to manager for event dispatch.
Web Platform Implementation
src/useGestureViewerPaging.web.ts, src/useGestureViewerPaging.types.ts, src/useGestureViewerPaging.ts
Replaced onWebDoubleClick with onWebClick callback, added onSingleTap parameter with 250ms delayed execution for web single-tap handling, introduced WebClickTarget type for mouse event target typing, and updated event handler signatures.
Component & View Integration
src/GestureViewer.tsx
Switched from onWebDoubleClick to onWebClick handler binding on web builds.
Testing
src/__tests__/manager.test.ts
Added Jest test suite for GestureViewerManager tap event emission and subscription behavior, including listener attachment and unsubscribe verification.
English Documentation
docs/docs/2.x/en/guide/usage/basic-usage.mdx, docs/docs/2.x/en/guide/usage/gesture-viewer-props.mdx, docs/docs/2.x/en/guide/usage/handling-viewer-events.mdx, docs/docs/2.x/en/guide/usage/style-customization.mdx
Added onSingleTap prop documentation with usage examples, documented 'tap' event in event subscription guide, clarified tap handling vs. renderContainer usage, and included tap event payload reference.
Korean Documentation
docs/docs/2.x/ko/guide/usage/basic-usage.mdx, docs/docs/2.x/ko/guide/usage/gesture-viewer-props.mdx, docs/docs/2.x/ko/guide/usage/handling-viewer-events.mdx, docs/docs/2.x/ko/guide/usage/style-customization.mdx
Parallel Korean translations of single-tap documentation, onSingleTap prop usage guidance, and 'tap' event subscription examples.
Changeset & Examples
.changeset/single-tap-events.md, example/src/Example.tsx
Added changeset entry documenting single-tap feature addition, updated example to use onSingleTap for UI control toggling, added tap event subscription logging, and updated photo data structure with per-item notes.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

size/XL

Poem

🐰 A single tap now finds its way,
Through gestures swift, both night and day,
No double-checks to slow the pace,
Just one small touch—oh what grace!
The rabbit hops with joy supreme,
This tapping feature is a dream. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main feature addition: introducing single-tap callbacks and tap events to the GestureViewer component.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/single-tap-events

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.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying react-native-gesture-image-viewer with  Cloudflare Pages  Cloudflare Pages

Latest commit: fb2c333
Status: ✅  Deploy successful!
Preview URL: https://30f1a317.react-native-gesture-image-viewer.pages.dev
Branch Preview URL: https://feat-single-tap-events.react-native-gesture-image-viewer.pages.dev

View logs

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fb2c333291

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/useGestureViewerPaging.web.ts Outdated
Comment thread src/useGestureViewerPaging.web.ts
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: 4

🧹 Nitpick comments (2)
src/useGestureViewerPaging.web.ts (1)

366-425: Consider extracting the 250ms double-tap arbitration window into a named constant.

The setTimeout(..., 250) at Line 410 is the single-tap arbitration delay used when enableDoubleTapZoom is enabled. A named constant (e.g. WEB_SINGLE_TAP_DOUBLE_CLICK_WINDOW_MS = 250) at module scope would make the intent self-documenting and make it easy to tune later if browser double-click thresholds become an issue in practice.

Also worth noting for reviewers: browsers fire click with detail: 1 then detail: 2 on a double-click, and the 2nd event arrives after the 1st. The current cancel-then-schedule ordering correctly handles that cascade (detail===2 clears the pending detail===1 timer before applying zoom). No change needed there — just calling it out as an invariant worth a short inline comment if you want to document it.

♻️ Suggested refactor
+const WEB_SINGLE_TAP_DOUBLE_CLICK_WINDOW_MS = 250;
+
 type WebScrollActor = 'idle' | 'user' | 'autoplay';
-      webSingleTapTimerRef.current = setTimeout(() => {
-        onSingleTap(resolvedX, resolvedY);
-        webSingleTapTimerRef.current = null;
-      }, 250);
+      webSingleTapTimerRef.current = setTimeout(() => {
+        onSingleTap(resolvedX, resolvedY);
+        webSingleTapTimerRef.current = null;
+      }, WEB_SINGLE_TAP_DOUBLE_CLICK_WINDOW_MS);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/useGestureViewerPaging.web.ts` around lines 366 - 425, Extract the
hard-coded 250ms timeout in onWebClick into a module-scope named constant (e.g.
WEB_SINGLE_TAP_DOUBLE_CLICK_WINDOW_MS = 250) and replace the setTimeout delay
with that constant; update the dependency comments or add a short inline comment
near onWebClick/webSingleTapTimerRef.current explaining the click detail
(detail:1 then detail:2) arbitration so the intent is self-documenting and easy
to tune later when using enableDoubleTapZoom and webSingleTapTimerRef.
src/__tests__/manager.test.ts (1)

18-38: Consider covering a couple more tap-specific cases.

The test validates the basic dispatch + unsubscribe path well. A couple of small additions would tighten the contract around emitTap:

  • Multiple 'tap' listeners: ensure all are invoked (and each unsubscribe is independent).
  • Payload independence: emit two different tap payloads and verify each listener receives the exact object it was emitted with (guards against accidental shared-object mutation if emitEvent ever gets refactored).

Not blocking — current test already validates the new emitTap surface.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/__tests__/manager.test.ts` around lines 18 - 38, Add assertions to cover
multiple 'tap' listeners and payload independence: instantiate
GestureViewerManager, register two distinct tap listeners via addEventListener
(e.g., tapListener and secondTapListener), emit two different tap payloads with
emitTap and assert both listeners were called for each emission and received the
exact payload objects passed; also unsubscribe one listener and verify the other
still receives subsequent taps to confirm independent unsubscription (use
unsubscribeTap and unsubscribeSecondTap variables to track).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/docs/2.x/en/guide/usage/gesture-viewer-props.mdx`:
- Around line 112-123: The example uses useState in the App component but the
import list only includes GestureViewer; update the example's imports to also
import useState from 'react' (add useState to the import directives before the
GestureViewer import) so the App function can call useState without error.

In `@docs/docs/2.x/en/guide/usage/handling-viewer-events.mdx`:
- Around line 61-65: The table for the viewer events incorrectly shows
previousScale and previousRotation as always numbers; update the documentation
for the zoomChange and rotationChange events to indicate that previousScale and
previousRotation can be null (e.g., `{ scale: number, previousScale: number |
null }` and `{ rotation: number, previousRotation: number | null }`) so the
signatures in the docs match the exported event types; locate the rows for
`zoomChange` and `rotationChange` in handling-viewer-events.mdx and change the
Callback Data cells to reflect the nullable types.

In `@docs/docs/2.x/ko/guide/usage/gesture-viewer-props.mdx`:
- Around line 112-123: The example uses the React hook useState but does not
import it; update the example to add an import for useState (e.g., import {
useState } from 'react') alongside the existing GestureViewer import so the
component function App can reference useState without error; ensure you update
both the Korean and English documentation files and keep the import line grouped
with the other imports.

In `@docs/docs/2.x/ko/guide/usage/handling-viewer-events.mdx`:
- Around line 61-65: Update the event table rows for zoomChange and
rotationChange to indicate that previousScale and previousRotation can be
nullable (number | null) instead of always number; locate the zoomChange and
rotationChange rows in the table and change the "콜백 데이터" column entries to `{
scale: number, previousScale: number | null }` and `{ rotation: number,
previousRotation: number | null }` respectively so the docs match the actual
types.

---

Nitpick comments:
In `@src/__tests__/manager.test.ts`:
- Around line 18-38: Add assertions to cover multiple 'tap' listeners and
payload independence: instantiate GestureViewerManager, register two distinct
tap listeners via addEventListener (e.g., tapListener and secondTapListener),
emit two different tap payloads with emitTap and assert both listeners were
called for each emission and received the exact payload objects passed; also
unsubscribe one listener and verify the other still receives subsequent taps to
confirm independent unsubscription (use unsubscribeTap and unsubscribeSecondTap
variables to track).

In `@src/useGestureViewerPaging.web.ts`:
- Around line 366-425: Extract the hard-coded 250ms timeout in onWebClick into a
module-scope named constant (e.g. WEB_SINGLE_TAP_DOUBLE_CLICK_WINDOW_MS = 250)
and replace the setTimeout delay with that constant; update the dependency
comments or add a short inline comment near
onWebClick/webSingleTapTimerRef.current explaining the click detail (detail:1
then detail:2) arbitration so the intent is self-documenting and easy to tune
later when using enableDoubleTapZoom and webSingleTapTimerRef.
🪄 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: c9e2c576-2f8b-4f94-bece-ae6ef8188507

📥 Commits

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

📒 Files selected for processing (20)
  • .changeset/single-tap-events.md
  • docs/docs/2.x/en/guide/usage/basic-usage.mdx
  • docs/docs/2.x/en/guide/usage/gesture-viewer-props.mdx
  • docs/docs/2.x/en/guide/usage/handling-viewer-events.mdx
  • docs/docs/2.x/en/guide/usage/style-customization.mdx
  • docs/docs/2.x/ko/guide/usage/basic-usage.mdx
  • docs/docs/2.x/ko/guide/usage/gesture-viewer-props.mdx
  • docs/docs/2.x/ko/guide/usage/handling-viewer-events.mdx
  • docs/docs/2.x/ko/guide/usage/style-customization.mdx
  • example/src/Example.tsx
  • src/GestureViewer.tsx
  • src/GestureViewerManager.ts
  • src/__tests__/manager.test.ts
  • src/index.tsx
  • src/types.ts
  • src/useGestureViewer.ts
  • src/useGestureViewerEvent.ts
  • src/useGestureViewerPaging.ts
  • src/useGestureViewerPaging.types.ts
  • src/useGestureViewerPaging.web.ts

Comment thread docs/docs/2.x/en/guide/usage/gesture-viewer-props.mdx
Comment thread docs/docs/2.x/en/guide/usage/handling-viewer-events.mdx
Comment thread docs/docs/2.x/ko/guide/usage/gesture-viewer-props.mdx
Comment thread docs/docs/2.x/ko/guide/usage/handling-viewer-events.mdx
@saseungmin saseungmin merged commit 7999145 into main Apr 18, 2026
5 checks passed
@saseungmin saseungmin deleted the feat/single-tap-events branch April 18, 2026 09:04
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.

1 participant