Skip to content

Commit 0f4ffd7

Browse files
committed
Allow hooks to listen to handler updates and state changes
1 parent 0bbd40f commit 0f4ffd7

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/NativeViewGestureHandler.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,15 @@ class NativeViewGestureHandler : GestureHandler() {
212212
}
213213
lastActiveUpdate = snapshot
214214
super.dispatchHandlerUpdate(event)
215+
216+
hook.onHandlerUpdate(this)
215217
}
216218

217219
override fun dispatchStateChange(newState: Int, prevState: Int) {
218220
lastActiveUpdate = null
219221
super.dispatchStateChange(newState, prevState)
222+
223+
hook.onHandlerStateChange(this, newState, prevState)
220224
}
221225

222226
override fun wantsToAttachDirectlyToView() = true
@@ -356,6 +360,16 @@ class NativeViewGestureHandler : GestureHandler() {
356360
* Passes the event down to the underlying view using the correct method.
357361
*/
358362
fun sendTouchEvent(view: View?, event: MotionEvent) = view?.onTouchEvent(event)
363+
364+
/*
365+
* Called when the handler processes a new update event.
366+
*/
367+
fun onHandlerUpdate(handler: NativeViewGestureHandler) = Unit
368+
369+
/*
370+
* Called when the handler moves to a new state.
371+
*/
372+
fun onHandlerStateChange(handler: NativeViewGestureHandler, newState: Int, prevState: Int) = Unit
359373
}
360374

361375
private class TextViewHook : NativeViewGestureHandlerHook {

0 commit comments

Comments
 (0)