-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds a listener to the react native event bridge to handle touches
- Loading branch information
1 parent
fb65cab
commit 495cd65
Showing
3 changed files
with
219 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import ReactNativePrivateInterface from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' | ||
import { bridge } from './dom' | ||
|
||
function receiveEvent(rootNodeID, topLevelType, nativeEventParam) { | ||
// TODO: need to handle other events | ||
console.log({ rootNodeID, topLevelType, nativeEventParam }) | ||
} | ||
|
||
function receiveTouches(eventTopLevelType, touches, changedIndices) { | ||
if (!touches.length) { | ||
return | ||
} | ||
|
||
const touch = touches[0] | ||
|
||
const nativeEvent = touch | ||
let nodeId = nativeEvent.target < 1 ? null : touch.target | ||
|
||
if (!nodeId) { | ||
return | ||
} | ||
|
||
executeTouchEvent(nodeId, eventTopLevelType, nativeEvent) | ||
} | ||
|
||
function executeTouchEvent(nodeId, eventTopLevelType, nativeEvent = {}) { | ||
bridge.enqueue('event', [nodeId, eventTopLevelType, nativeEvent]) | ||
} | ||
|
||
ReactNativePrivateInterface.RCTEventEmitter.register({ | ||
receiveEvent: receiveEvent, | ||
receiveTouches: receiveTouches, | ||
}) |