Skip to content

Move hitSlop normalization to JS - #4388

Merged
coado merged 10 commits into
mainfrom
@coado/hitslop
Aug 12, 2026
Merged

Move hitSlop normalization to JS#4388
coado merged 10 commits into
mainfrom
@coado/hitslop

Conversation

@coado

@coado coado commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Description

This moves the parsing and validation of hitSlop into one shared JS module and reduces the platforms to reading a fixed shape.

JS now sends a normalized [left, top, right, bottom, width, height] array, where null marks an unspecified edge. That layout matches what the platforms already stored internally (FloatArray(6) on Android, RNGHHitSlop on Apple), so the native parsers shrink to mapping null → NaN, plus the DIP→px conversion on Android.

Applied at all four producers: filterConfig (v1 and v2), prepareConfigForNativeSide (v3), bindSharedValues (v3's UI-thread path) and the button's web wrapper.

Test plan

Tested on Android, iOS and Web

Copilot AI review requested due to automatic review settings August 5, 2026 16:01
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 82c92ff0-10f7-4a1f-8aaa-9ceb9e349158

📥 Commits

Reviewing files that changed from the base of the PR and between 101980a and f7584bc.

📒 Files selected for processing (2)
  • packages/react-native-gesture-handler/src/__tests__/hitSlop.test.ts
  • packages/react-native-gesture-handler/src/__tests__/hitSlopSharedValue.test.ts
💤 Files with no reviewable changes (1)
  • packages/react-native-gesture-handler/src/tests/hitSlop.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-native-gesture-handler/src/tests/hitSlopSharedValue.test.ts

📝 Walkthrough

Summary by CodeRabbit

  • Improvements

    • Standardized hitSlop handling across native, web, and gesture APIs.
    • Added consistent support for numeric, shorthand, per-edge, width, and height configurations.
    • Preserved omitted, undefined, and explicit null values appropriately.
    • Improved handling of shared and animated configuration updates.
  • Bug Fixes

    • Ensured hit-slop settings apply consistently during setup and subsequent updates.
    • Added validation for invalid dimensions and conflicting constraints with clearer error handling.

Walkthrough

The change normalizes hit-slop inputs into a canonical six-element array. Legacy, v3, web, Android, and Apple paths now consume this format. Tests cover normalization, validation, shared values, wiring, and nullish behavior.

Changes

Hit-slop normalization

Layer / File(s) Summary
Canonical hit-slop contract and validation
packages/react-native-gesture-handler/src/handlers/hitSlop.ts, packages/react-native-gesture-handler/src/handlers/utils.ts, packages/react-native-gesture-handler/src/v3/types/ConfigTypes.ts, packages/react-native-gesture-handler/src/web/interfaces.ts
normalizeHitSlop converts numeric and object inputs into [left, top, right, bottom, width, height]. Configuration types use CanonicalHitSlop.
Configuration and shared-value wiring
packages/react-native-gesture-handler/src/v3/hooks/utils/*, packages/react-native-gesture-handler/src/components/GestureHandlerButton.web.tsx, packages/react-native-gesture-handler/src/__tests__/hitSlopWiring.test.ts, packages/react-native-gesture-handler/src/__tests__/hitSlopSharedValue.test.ts
Configuration paths normalize hit-slop values. Tests cover normalized values, nullish values, and unchanged non-hit-slop values.
Native tuple consumption
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt, packages/react-native-gesture-handler/apple/RNGestureHandler.mm, packages/react-native-gesture-handler/apple/RNGestureHandlerButtonComponentView.mm
Android and Apple code consume the six-element array. Android converts DIP values to pixels.
Web bounds calculation
packages/react-native-gesture-handler/src/web/handlers/GestureHandler.ts, packages/react-native-gesture-handler/src/web/interfaces.ts
The web handler stores canonical tuples and calculates bounds from nullable edges, width, and height values.
Normalization and wiring tests
packages/react-native-gesture-handler/src/__tests__/hitSlop.test.ts, packages/react-native-gesture-handler/src/__tests__/hitSlopWiring.test.ts
Tests cover shorthand expansion, explicit-edge precedence, dimensions, validation, and nullish handling.

Sequence Diagram(s)

sequenceDiagram
  participant GestureConfig
  participant normalizeHitSlop
  participant NativeConfig
  participant GestureHandler
  GestureConfig->>normalizeHitSlop: raw hitSlop value
  normalizeHitSlop-->>GestureConfig: canonical six-element array
  GestureConfig->>NativeConfig: normalized hitSlop
  NativeConfig->>GestureHandler: apply hit-slop tuple
  GestureHandler-->>GestureConfig: updated gesture bounds
Loading

Suggested reviewers: m-bert, j-piasecki

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: moving hitSlop normalization from native code to JavaScript.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR centralizes hitSlop parsing/validation in a shared JS module and changes the native/web consumers to accept a single canonical shape ([left, top, right, bottom, width, height] with null for “unset”), reducing platform-specific parsing logic.

Changes:

  • Introduces normalizeHitSlop + CanonicalHitSlop in JS and updates config producers (v1/v2 filterConfig, v3 native config prep, v3 shared-value UI-thread updates, and the web button wrapper) to emit the canonical array.
  • Simplifies native (Android/iOS) hitSlop parsing to fixed-index reads, plus DIP→px conversion on Android.
  • Updates web handler types and hit-testing logic to consume the canonical array and adds targeted Jest tests to lock the wire contract.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/react-native-gesture-handler/src/web/interfaces.ts Switches web config types from object HitSlop to CanonicalHitSlop.
packages/react-native-gesture-handler/src/web/handlers/GestureHandler.ts Updates web handler to store/consume canonical hitSlop arrays; removes local validation.
packages/react-native-gesture-handler/src/v3/hooks/utils/reanimatedUtils.ts Normalizes hitSlop when pushed via UI-thread shared value updates.
packages/react-native-gesture-handler/src/v3/hooks/utils/configUtils.ts Normalizes hitSlop in v3 config preparation (including shared values).
packages/react-native-gesture-handler/src/utils.ts Adds isWorkletRuntime helper for worklet-vs-RN runtime detection.
packages/react-native-gesture-handler/src/handlers/utils.ts Normalizes hitSlop in v1/v2 filterConfig.
packages/react-native-gesture-handler/src/handlers/hitSlop.ts Adds shared canonical hitSlop type + normalization/validation logic (worklet-safe).
packages/react-native-gesture-handler/src/components/GestureHandlerButton.web.tsx Normalizes button hitSlop before passing to the web module.
packages/react-native-gesture-handler/src/tests/hitSlopWiring.test.ts Adds wiring tests for normalization at multiple producers.
packages/react-native-gesture-handler/src/tests/hitSlopSharedValue.test.ts Adds test ensuring UI-thread shared-value path normalizes hitSlop.
packages/react-native-gesture-handler/src/tests/hitSlop.test.ts Adds unit tests for normalizeHitSlop, including worklet-runtime behavior.
packages/react-native-gesture-handler/apple/RNGestureHandlerButtonComponentView.mm Updates button hitSlop config emission to the canonical array shape.
packages/react-native-gesture-handler/apple/RNGestureHandler.mm Updates iOS handler hitSlop parsing to read canonical array indices.
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt Updates Android hitSlop parsing to read canonical array indices and convert DIP→px.
Suppressed comments (1)

packages/react-native-gesture-handler/src/tests/hitSlop.test.ts:205

  • These assignments also rely on globalThis.__RUNTIME_KIND / _WORKLET typings. Once a local g is introduced, use it consistently here to avoid TS errors.
    test('reports instead of throwing', () => {
      // 2 is the UI runtime.
      globalThis.__RUNTIME_KIND = 2;
      expectReported();
    });

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/react-native-gesture-handler/src/handlers/hitSlop.ts Outdated
Comment thread packages/react-native-gesture-handler/src/utils.ts Outdated
Comment thread packages/react-native-gesture-handler/src/__tests__/hitSlop.test.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/react-native-gesture-handler/src/v3/hooks/utils/configUtils.ts (1)

110-117: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse maybeUnpackValue for the shared-value unwrapping.

Line 102 in the same function already unwraps through maybeUnpackValue. The inline Reanimated?.isSharedValue(value) ? value.value : value duplicates that rule. Use the helper so both call sites stay in sync.

♻️ Proposed refactor
-      const unpackedValue = Reanimated?.isSharedValue(value)
-        ? value.value
-        : value;
+      const unpackedValue = maybeUnpackValue(value);
 
       (filteredConfig as Record<string, unknown>)[key] =
         key === 'hitSlop'
           ? normalizeHitSlop(unpackedValue as HitSlop)
           : unpackedValue;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/react-native-gesture-handler/src/v3/hooks/utils/configUtils.ts`
around lines 110 - 117, In the config filtering logic, replace the inline
Reanimated shared-value check and value access before the hitSlop handling with
the existing maybeUnpackValue helper already used earlier in the same function.
Keep the subsequent normalizeHitSlop and filteredConfig assignment behavior
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt`:
- Around line 988-1003: Update the hitSlop reader around the local edge function
and handler.setHitSlop call to validate each tuple entry before accessing it:
treat out-of-bounds or non-numeric values as GestureHandler.HIT_SLOP_NONE,
matching Apple behavior for malformed arrays. Use ReadableArray bounds/type
checks before getDouble so malformed hitSlop configuration cannot crash native
updates.

In `@packages/react-native-gesture-handler/src/web/handlers/GestureHandler.ts`:
- Around line 879-915: Add web hit-slop coverage in GestureHandler.test.ts for
zero-valued edges, explicitly null edges, and combinations of
left/right/top/bottom with width/height sizing. Ensure the tests validate the
bounds computed by the hit-slop logic in GestureHandler, then run yarn lint:js,
yarn format:js, yarn ts-check, and yarn test GestureHandler.test.ts with
dependencies installed.

---

Nitpick comments:
In `@packages/react-native-gesture-handler/src/v3/hooks/utils/configUtils.ts`:
- Around line 110-117: In the config filtering logic, replace the inline
Reanimated shared-value check and value access before the hitSlop handling with
the existing maybeUnpackValue helper already used earlier in the same function.
Keep the subsequent normalizeHitSlop and filteredConfig assignment behavior
unchanged.
🪄 Autofix

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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 68c6aa8c-5054-4c13-bc42-508a04972fe0

📥 Commits

Reviewing files that changed from the base of the PR and between e58c43a and c19ebcd.

📒 Files selected for processing (14)
  • packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt
  • packages/react-native-gesture-handler/apple/RNGestureHandler.mm
  • packages/react-native-gesture-handler/apple/RNGestureHandlerButtonComponentView.mm
  • packages/react-native-gesture-handler/src/__tests__/hitSlop.test.ts
  • packages/react-native-gesture-handler/src/__tests__/hitSlopSharedValue.test.ts
  • packages/react-native-gesture-handler/src/__tests__/hitSlopWiring.test.ts
  • packages/react-native-gesture-handler/src/components/GestureHandlerButton.web.tsx
  • packages/react-native-gesture-handler/src/handlers/hitSlop.ts
  • packages/react-native-gesture-handler/src/handlers/utils.ts
  • packages/react-native-gesture-handler/src/utils.ts
  • packages/react-native-gesture-handler/src/v3/hooks/utils/configUtils.ts
  • packages/react-native-gesture-handler/src/v3/hooks/utils/reanimatedUtils.ts
  • packages/react-native-gesture-handler/src/web/handlers/GestureHandler.ts
  • packages/react-native-gesture-handler/src/web/interfaces.ts

@coado
coado marked this pull request as ready for review August 7, 2026 12:02
Comment thread packages/react-native-gesture-handler/apple/RNGestureHandler.mm Outdated
Comment thread packages/react-native-gesture-handler/apple/RNGestureHandler.mm Outdated
Comment thread packages/react-native-gesture-handler/src/handlers/hitSlop.ts Outdated
Comment thread packages/react-native-gesture-handler/src/handlers/hitSlop.ts Outdated
Comment thread packages/react-native-gesture-handler/src/v3/hooks/utils/configUtils.ts Outdated
Comment thread packages/react-native-gesture-handler/src/v3/hooks/utils/reanimatedUtils.ts Outdated
Comment thread packages/react-native-gesture-handler/src/utils.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/react-native-gesture-handler/src/v3/types/ConfigTypes.ts`:
- Line 77: Resolve the failing Jest cases in hitSlop.test.ts and
hitSlopSharedValue.test.ts by tracing the hitSlop type and runtime handling from
ConfigTypes.ts, then update the implementation or tests so both regular and
shared-value hitSlop behavior passes. Verify the package test suite succeeds
without regressing the existing lint, formatting, or TypeScript checks.
🪄 Autofix

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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: efb67868-57be-440a-be3e-8b1de90b58f9

📥 Commits

Reviewing files that changed from the base of the PR and between c19ebcd and 881869a.

📒 Files selected for processing (5)
  • packages/react-native-gesture-handler/apple/RNGestureHandler.mm
  • packages/react-native-gesture-handler/src/handlers/hitSlop.ts
  • packages/react-native-gesture-handler/src/v3/hooks/utils/configUtils.ts
  • packages/react-native-gesture-handler/src/v3/hooks/utils/reanimatedUtils.ts
  • packages/react-native-gesture-handler/src/v3/types/ConfigTypes.ts
💤 Files with no reviewable changes (1)
  • packages/react-native-gesture-handler/apple/RNGestureHandler.mm
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/react-native-gesture-handler/src/v3/hooks/utils/configUtils.ts
  • packages/react-native-gesture-handler/src/v3/hooks/utils/reanimatedUtils.ts
  • packages/react-native-gesture-handler/src/handlers/hitSlop.ts

Comment thread packages/react-native-gesture-handler/src/v3/types/ConfigTypes.ts Outdated
Comment thread packages/react-native-gesture-handler/apple/RNGestureHandler.mm
Comment thread packages/react-native-gesture-handler/apple/RNGestureHandler.mm Outdated
@m-bert

m-bert commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

@coderabbitai can this be merged?

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

repo="software-mansion/react-native-gesture-handler"
pr_number="4388"

echo "== Pull request metadata =="
gh pr view "$pr_number" --repo "$repo" \
  --json url,state,isDraft,mergeable,mergeStateStatus,reviewDecision,statusCheckRollup,latestReviews \
  --jq '{
    url,
    state,
    isDraft,
    mergeable,
    mergeStateStatus,
    reviewDecision,
    checks: [
      .statusCheckRollup[]? | {
        name: .name,
        status: .status,
        conclusion: .conclusion,
        detailsUrl: .detailsUrl
      }
    ],
    latestReviews: [
      .latestReviews[]? | {
        author: .author.login,
        state: .state,
        submittedAt: .submittedAt
      }
    ]
  }'

echo
echo "== Unresolved review threads =="
gh api graphql \
  -F owner="software-mansion" \
  -F name="react-native-gesture-handler" \
  -F number="$pr_number" \
  -f query='
query($owner: String!, $name: String!, $number: Int!) {
  repository(owner: $owner, name: $name) {
    pullRequest(number: $number) {
      reviewThreads(first: 100) {
        nodes {
          isResolved
          comments(first: 1) {
            nodes {
              author { login }
              body
              path
              line
            }
          }
        }
      }
    }
  }
}' --jq '.data.repository.pullRequest.reviewThreads.nodes[]
  | select(.isResolved == false)
  | {
      author: .comments.nodes[0].author.login,
      path: .comments.nodes[0].path,
      line: .comments.nodes[0].line,
      body: .comments.nodes[0].body
    }'

Length of output: 4094


@m-bert No. PR #4388 is blocked by a CHANGES_REQUESTED review decision.

All reported CI checks passed. GitHub reports no unresolved review threads. The current CHANGES_REQUESTED review must be dismissed or changed before the PR can merge.

You are interacting with an AI system.

@coado
coado merged commit ecf706c into main Aug 12, 2026
10 checks passed
@coado
coado deleted the @coado/hitslop branch August 12, 2026 12:36
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