@@ -76,7 +76,9 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
7676 @Suppress(" UNCHECKED_CAST" )
7777 protected fun self (): ConcreteGestureHandlerT = this as ConcreteGestureHandlerT
7878
79- protected inline fun applySelf (block : ConcreteGestureHandlerT .() -> Unit ): ConcreteGestureHandlerT = self().apply { block() }
79+ protected inline fun applySelf (block : ConcreteGestureHandlerT .() -> Unit ): ConcreteGestureHandlerT = self().apply {
80+ block()
81+ }
8082
8183 // properties set and accessed only by the orchestrator
8284 var activationIndex = 0
@@ -115,7 +117,10 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
115117 return false
116118 }
117119
118- fun setShouldCancelWhenOutside (shouldCancelWhenOutside : Boolean ): ConcreteGestureHandlerT = applySelf { this .shouldCancelWhenOutside = shouldCancelWhenOutside }
120+ fun setShouldCancelWhenOutside (shouldCancelWhenOutside : Boolean ): ConcreteGestureHandlerT = applySelf {
121+ this .shouldCancelWhenOutside =
122+ shouldCancelWhenOutside
123+ }
119124
120125 fun setEnabled (enabled : Boolean ): ConcreteGestureHandlerT = applySelf {
121126 // Don't cancel handler when not changing the value of the isEnabled, executing it always caused
@@ -129,7 +134,10 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
129134 isEnabled = enabled
130135 }
131136
132- fun setManualActivation (manualActivation : Boolean ): ConcreteGestureHandlerT = applySelf { this .manualActivation = manualActivation }
137+ fun setManualActivation (manualActivation : Boolean ): ConcreteGestureHandlerT = applySelf {
138+ this .manualActivation =
139+ manualActivation
140+ }
133141
134142 fun setHitSlop (
135143 leftPad : Float ,
@@ -148,22 +156,36 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
148156 hitSlop!! [HIT_SLOP_BOTTOM_IDX ] = bottomPad
149157 hitSlop!! [HIT_SLOP_WIDTH_IDX ] = width
150158 hitSlop!! [HIT_SLOP_HEIGHT_IDX ] = height
151- require(! (hitSlopSet(width) && hitSlopSet(leftPad) && hitSlopSet(rightPad))) { " Cannot have all of left, right and width defined" }
152- require(! (hitSlopSet(width) && ! hitSlopSet(leftPad) && ! hitSlopSet(rightPad))) { " When width is set one of left or right pads need to be defined" }
153- require(! (hitSlopSet(height) && hitSlopSet(bottomPad) && hitSlopSet(topPad))) { " Cannot have all of top, bottom and height defined" }
154- require(! (hitSlopSet(height) && ! hitSlopSet(bottomPad) && ! hitSlopSet(topPad))) { " When height is set one of top or bottom pads need to be defined" }
159+ require(! (hitSlopSet(width) && hitSlopSet(leftPad) && hitSlopSet(rightPad))) {
160+ " Cannot have all of left, right and width defined"
161+ }
162+ require(! (hitSlopSet(width) && ! hitSlopSet(leftPad) && ! hitSlopSet(rightPad))) {
163+ " When width is set one of left or right pads need to be defined"
164+ }
165+ require(! (hitSlopSet(height) && hitSlopSet(bottomPad) && hitSlopSet(topPad))) {
166+ " Cannot have all of top, bottom and height defined"
167+ }
168+ require(! (hitSlopSet(height) && ! hitSlopSet(bottomPad) && ! hitSlopSet(topPad))) {
169+ " When height is set one of top or bottom pads need to be defined"
170+ }
155171 }
156172
157- fun setHitSlop (padding : Float ): ConcreteGestureHandlerT = setHitSlop(padding, padding, padding, padding, HIT_SLOP_NONE , HIT_SLOP_NONE )
173+ fun setHitSlop (padding : Float ): ConcreteGestureHandlerT =
174+ setHitSlop(padding, padding, padding, padding, HIT_SLOP_NONE , HIT_SLOP_NONE )
158175
159- fun setInteractionController (controller : GestureHandlerInteractionController ? ): ConcreteGestureHandlerT = applySelf { interactionController = controller }
176+ fun setInteractionController (controller : GestureHandlerInteractionController ? ): ConcreteGestureHandlerT = applySelf {
177+ interactionController =
178+ controller
179+ }
160180
161181 fun setMouseButton (mouseButton : Int ) = apply {
162182 this .mouseButton = mouseButton
163183 }
164184
165185 fun prepare (view : View ? , orchestrator : GestureHandlerOrchestrator ? ) {
166- check(! (this .view != null || this .orchestrator != null )) { " Already prepared or hasn't been reset" }
186+ check(! (this .view != null || this .orchestrator != null )) {
187+ " Already prepared or hasn't been reset"
188+ }
167189 Arrays .fill(trackedPointerIDs, - 1 )
168190 trackedPointersIDsCount = 0
169191 state = STATE_UNDETERMINED
@@ -246,7 +268,13 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
246268 actionIndex = event.actionIndex
247269 val actionPointer = event.getPointerId(actionIndex)
248270 action = if (trackedPointerIDs[actionPointer] != - 1 ) {
249- if (trackedPointersIDsCount == 1 ) MotionEvent .ACTION_DOWN else MotionEvent .ACTION_POINTER_DOWN
271+ if (trackedPointersIDsCount ==
272+ 1
273+ ) {
274+ MotionEvent .ACTION_DOWN
275+ } else {
276+ MotionEvent .ACTION_POINTER_DOWN
277+ }
250278 } else {
251279 MotionEvent .ACTION_MOVE
252280 }
@@ -282,7 +310,9 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
282310
283311 // introduced in 1.11.0, remove if crashes are not reported
284312 if (pointerProps.isEmpty() || pointerCoords.isEmpty()) {
285- throw IllegalStateException (" pointerCoords.size=${pointerCoords.size} , pointerProps.size=${pointerProps.size} " )
313+ throw IllegalStateException (
314+ " pointerCoords.size=${pointerCoords.size} , pointerProps.size=${pointerProps.size} " ,
315+ )
286316 }
287317
288318 val result: MotionEvent
@@ -312,12 +342,9 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
312342 }
313343
314344 // exception to help debug https://github.com/software-mansion/react-native-gesture-handler/issues/1188
315- class AdaptEventException (
316- handler : GestureHandler <* >,
317- event : MotionEvent ,
318- e : IllegalArgumentException ,
319- ) : Exception(
320- """
345+ class AdaptEventException (handler : GestureHandler <* >, event : MotionEvent , e : IllegalArgumentException ) :
346+ Exception (
347+ """
321348 handler: ${handler::class .simpleName}
322349 state: ${handler.state}
323350 view: ${handler.view}
@@ -328,9 +355,9 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
328355 trackedPointersCount: ${handler.trackedPointersIDsCount}
329356 trackedPointers: ${handler.trackedPointerIDs.joinToString(separator = " , " )}
330357 while handling event: $event
331- """ .trimIndent(),
332- e,
333- )
358+ """ .trimIndent(),
359+ e,
360+ )
334361
335362 fun handle (transformedEvent : MotionEvent , sourceEvent : MotionEvent ) {
336363 if (! isEnabled ||
@@ -371,7 +398,10 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
371398 lastEventOffsetX = adaptedTransformedEvent.rawX - adaptedTransformedEvent.x
372399 lastEventOffsetY = adaptedTransformedEvent.rawY - adaptedTransformedEvent.y
373400
374- if (sourceEvent.action == MotionEvent .ACTION_DOWN || sourceEvent.action == MotionEvent .ACTION_HOVER_ENTER || sourceEvent.action == MotionEvent .ACTION_HOVER_MOVE ) {
401+ if (sourceEvent.action == MotionEvent .ACTION_DOWN ||
402+ sourceEvent.action == MotionEvent .ACTION_HOVER_ENTER ||
403+ sourceEvent.action == MotionEvent .ACTION_HOVER_MOVE
404+ ) {
375405 setPointerType(sourceEvent)
376406 }
377407
@@ -466,10 +496,14 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
466496 }
467497
468498 fun updatePointerData (event : MotionEvent , sourceEvent : MotionEvent ) {
469- if (event.actionMasked == MotionEvent .ACTION_DOWN || event.actionMasked == MotionEvent .ACTION_POINTER_DOWN ) {
499+ if (event.actionMasked == MotionEvent .ACTION_DOWN ||
500+ event.actionMasked == MotionEvent .ACTION_POINTER_DOWN
501+ ) {
470502 dispatchTouchDownEvent(event, sourceEvent)
471503 dispatchTouchMoveEvent(event, sourceEvent)
472- } else if (event.actionMasked == MotionEvent .ACTION_UP || event.actionMasked == MotionEvent .ACTION_POINTER_UP ) {
504+ } else if (event.actionMasked == MotionEvent .ACTION_UP ||
505+ event.actionMasked == MotionEvent .ACTION_POINTER_UP
506+ ) {
473507 dispatchTouchMoveEvent(event, sourceEvent)
474508 dispatchTouchUpEvent(event, sourceEvent)
475509 } else if (event.actionMasked == MotionEvent .ACTION_MOVE ) {
@@ -547,7 +581,9 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
547581 }
548582
549583 // if there are tracked pointers and the gesture is about to end, send event cancelling all pointers
550- if (trackedPointersCount > 0 && (newState == STATE_END || newState == STATE_CANCELLED || newState == STATE_FAILED )) {
584+ if (trackedPointersCount > 0 &&
585+ (newState == STATE_END || newState == STATE_CANCELLED || newState == STATE_FAILED )
586+ ) {
551587 cancelPointers()
552588 }
553589
@@ -648,7 +684,11 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
648684 }
649685
650686 fun cancel () {
651- if (state == STATE_ACTIVE || state == STATE_UNDETERMINED || state == STATE_BEGAN || this .isAwaiting) {
687+ if (state == STATE_ACTIVE ||
688+ state == STATE_UNDETERMINED ||
689+ state == STATE_BEGAN ||
690+ this .isAwaiting
691+ ) {
652692 onCancel()
653693 moveToState(STATE_CANCELLED )
654694 }
@@ -724,9 +764,15 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
724764
725765 with (sourceEvent) {
726766 // To use actionButton, we need API >= 23.
727- if (getToolType(0 ) == MotionEvent .TOOL_TYPE_MOUSE && Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
767+ if (getToolType(0 ) == MotionEvent .TOOL_TYPE_MOUSE &&
768+ Build .VERSION .SDK_INT >= Build .VERSION_CODES .M
769+ ) {
728770 // While using mouse, we want to ignore default events for touch.
729- if (action == MotionEvent .ACTION_DOWN || action == MotionEvent .ACTION_UP || action == MotionEvent .ACTION_POINTER_UP || action == MotionEvent .ACTION_POINTER_DOWN ) {
771+ if (action == MotionEvent .ACTION_DOWN ||
772+ action == MotionEvent .ACTION_UP ||
773+ action == MotionEvent .ACTION_POINTER_UP ||
774+ action == MotionEvent .ACTION_POINTER_DOWN
775+ ) {
730776 return @shouldActivateWithMouse false
731777 }
732778
@@ -741,7 +787,9 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
741787 }
742788 } else if (Build .VERSION .SDK_INT < Build .VERSION_CODES .M ) {
743789 // We do not fully support mouse below API 23, so we will ignore BUTTON events.
744- if (action == MotionEvent .ACTION_BUTTON_PRESS || action == MotionEvent .ACTION_BUTTON_RELEASE ) {
790+ if (action == MotionEvent .ACTION_BUTTON_PRESS ||
791+ action == MotionEvent .ACTION_BUTTON_RELEASE
792+ ) {
745793 return @shouldActivateWithMouse false
746794 }
747795 }
@@ -758,11 +806,12 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
758806 *
759807 * This method modifies and transforms the received point.
760808 */
761- protected fun transformPoint (point : PointF ): PointF = orchestrator?.transformPointToViewCoords(this .view, point) ? : run {
762- point.x = Float .NaN
763- point.y = Float .NaN
764- point
765- }
809+ protected fun transformPoint (point : PointF ): PointF =
810+ orchestrator?.transformPointToViewCoords(this .view, point) ? : run {
811+ point.x = Float .NaN
812+ point.y = Float .NaN
813+ point
814+ }
766815 fun reset () {
767816 view = null
768817 orchestrator = null
0 commit comments