Skip to content

Conversation

@Coooder-Crypto
Copy link

Added useTapAway and docs for issue #7

  • Implemented background-only useTapAway: listens to GlobalEventEmitter tap events (default bindtap), checks targets via equality/contains/uid/id, and invokes the callback when the tap is outside; exported from src/index.ts.
  • Added tests (tests/useTapAway.test.tsx) covering inside/outside taps, cleanup on unmount, and custom event names; all passing locally.
  • Added Chinese docs at docs/zh/events/useTapAway.md and linked from the events README.

Type notes: the hook uses a minimal event shape (target/detail.target) instead of MainThread.TouchEvent because it runs in the background and consumes GlobalEventEmitter payloads, which may not match MTS touch events; consumers can supply a narrower type via the generic if needed. Default event name is bindtap; adjust if runtime uses a different tap event.

@gaoachao gaoachao self-requested a review December 2, 2025 12:00
};

events.forEach((eventName) => {
emitter?.addListener?.(eventName, handler);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The bindtap event is not being captured by the global GlobalEventEmitter.

@gaoachao
Copy link
Collaborator

gaoachao commented Dec 2, 2025

Hi, @Coooder-Crypto, thanks for your contribution! However, the current implementation doesn't seem to achieve the goal of useTapAway. Here's my proposed solution:

  • Set trigger-global-event on the root node to forward tap events to GlobalEventEmitter
  • Extract the node path (clicked node → root) using uid from event.target
  • Retrieve the target node's uid via ref
  • Iterate through the path comparing uids to check if the target node exists in the path; trigger callback if absent

@Coooder-Crypto
Copy link
Author

Hi @gaoachao , sorry about my first PR — I really didn’t understand Lynx well enough at that time. I’ve been digging into it more seriously over the past few days to close the gaps.

One thing I found from the Lynx source: path() / targetPath currently don’t expose uid at all. event.target.uid exists, but the path data returned by getPathInfo only includes tag/id/dataSet/index/class, so there’s no uid chain to compare against.

Any guidance would be really appreciated.

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.

2 participants