Skip to content

Commit 17c84f1

Browse files
committed
Enforce max line width to 120
1 parent 6756afa commit 17c84f1

32 files changed

Lines changed: 455 additions & 205 deletions

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ class RNGestureHandlerPackage :
4040

4141
override fun getViewManagerNames(reactContext: ReactApplicationContext) = viewManagers.keys.toList()
4242

43-
override fun getViewManagers(reactContext: ReactApplicationContext): MutableList<ModuleSpec> = viewManagers.values.toMutableList()
43+
override fun getViewManagers(reactContext: ReactApplicationContext): MutableList<ModuleSpec> =
44+
viewManagers.values.toMutableList()
4445

45-
override fun createViewManager(
46-
reactContext: ReactApplicationContext,
47-
viewManagerName: String,
48-
) = viewManagers[viewManagerName]?.provider?.get() as? ViewManager<*, *>
46+
override fun createViewManager(reactContext: ReactApplicationContext, viewManagerName: String) =
47+
viewManagers[viewManagerName]?.provider?.get() as? ViewManager<*, *>
4948

50-
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = if (name == RNGestureHandlerModule.NAME) {
49+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = if (name ==
50+
RNGestureHandlerModule.NAME
51+
) {
5152
RNGestureHandlerModule(reactContext)
5253
} else {
5354
null

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ class RNGestureHandlerPackage :
4040

4141
override fun getViewManagerNames(reactContext: ReactApplicationContext?) = viewManagers.keys.toList()
4242

43-
override fun getViewManagers(reactContext: ReactApplicationContext?): MutableList<ModuleSpec> = viewManagers.values.toMutableList()
43+
override fun getViewManagers(reactContext: ReactApplicationContext?): MutableList<ModuleSpec> =
44+
viewManagers.values.toMutableList()
4445

45-
override fun createViewManager(
46-
reactContext: ReactApplicationContext?,
47-
viewManagerName: String?,
48-
) = viewManagers[viewManagerName]?.provider?.get() as? ViewManager<*, *>
46+
override fun createViewManager(reactContext: ReactApplicationContext?, viewManagerName: String?) =
47+
viewManagers[viewManagerName]?.provider?.get() as? ViewManager<*, *>
4948

50-
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = if (name == RNGestureHandlerModule.NAME) {
49+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = if (name ==
50+
RNGestureHandlerModule.NAME
51+
) {
5152
RNGestureHandlerModule(reactContext)
5253
} else {
5354
null

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ fun ReactContext.dispatchEvent(event: Event<*>) {
88
try {
99
this.getNativeModule(UIManagerModule::class.java)!!.eventDispatcher.dispatchEvent(event)
1010
} catch (e: NullPointerException) {
11-
throw Exception("Couldn't get an instance of UIManagerModule. Gesture Handler is unable to send an event.", e)
11+
throw Exception(
12+
"Couldn't get an instance of UIManagerModule. Gesture Handler is unable to send an event.",
13+
e,
14+
)
1215
}
1316
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ fun ReactContext.dispatchEvent(event: Event<*>) {
88
try {
99
this.getNativeModule(UIManagerModule::class.java)!!.eventDispatcher.dispatchEvent(event)
1010
} catch (e: NullPointerException) {
11-
throw Exception("Couldn't get an instance of UIManagerModule. Gesture Handler is unable to send an event.", e)
11+
throw Exception(
12+
"Couldn't get an instance of UIManagerModule. Gesture Handler is unable to send an event.",
13+
e,
14+
)
1215
}
1316
}

packages/react-native-gesture-handler/android/spotless.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: "com.diffplug.spotless"
33
spotless {
44
kotlin {
55
target "**/*.kt"
6-
ktlint().editorConfigOverride([indent_size: 2])
6+
ktlint().editorConfigOverride([indent_size: 2, max_line_length: 120])
77
trimTrailingWhitespace()
88
leadingTabsToSpaces()
99
endWithNewline()

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ class FlingGestureHandler : GestureHandler<FlingGestureHandler>() {
3939

4040
val velocityVector = Vector.fromVelocity(velocityTracker!!)
4141

42-
fun getVelocityAlignment(
43-
direction: Int,
44-
maxDeviationCosine: Double,
45-
): Boolean = (
42+
fun getVelocityAlignment(direction: Int, maxDeviationCosine: Double): Boolean = (
4643
(this.direction and direction) == direction &&
4744
velocityVector.isSimilar(Vector.fromDirection(direction), maxDeviationCosine)
4845
)

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

Lines changed: 83 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)