Skip to content

Commit 1610fc1

Browse files
authored
Simplify Android event builders (#3603)
## Description Merges declaration and initialization of fields in the event builder classes ## Test plan Build android
1 parent 8a8b506 commit 1610fc1

9 files changed

+40
-107
lines changed

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@ import com.swmansion.gesturehandler.core.FlingGestureHandler
66

77
class FlingGestureHandlerEventDataBuilder(handler: FlingGestureHandler) :
88
GestureHandlerEventDataBuilder<FlingGestureHandler>(handler) {
9-
private val x: Float
10-
private val y: Float
11-
private val absoluteX: Float
12-
private val absoluteY: Float
13-
14-
init {
15-
x = handler.lastRelativePositionX
16-
y = handler.lastRelativePositionY
17-
absoluteX = handler.lastPositionInWindowX
18-
absoluteY = handler.lastPositionInWindowY
19-
}
9+
private val x: Float = handler.lastRelativePositionX
10+
private val y: Float = handler.lastRelativePositionY
11+
private val absoluteX: Float = handler.lastPositionInWindowX
12+
private val absoluteY: Float = handler.lastPositionInWindowY
2013

2114
override fun buildEventData(eventData: WritableMap) {
2215
super.buildEventData(eventData)

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@ import com.facebook.react.bridge.WritableMap
44
import com.swmansion.gesturehandler.core.GestureHandler
55

66
abstract class GestureHandlerEventDataBuilder<T : GestureHandler>(handler: T) {
7-
private val numberOfPointers: Int
8-
private val handlerTag: Int
9-
private val state: Int
10-
private val pointerType: Int
11-
12-
init {
13-
numberOfPointers = handler.numberOfPointers
14-
handlerTag = handler.tag
15-
state = handler.state
16-
pointerType = handler.pointerType
17-
}
7+
private val handlerTag: Int = handler.tag
8+
private val state: Int = handler.state
9+
private val pointerType: Int = handler.pointerType
10+
private val numberOfPointers: Int = handler.numberOfPointers
1811

1912
open fun buildEventData(eventData: WritableMap) {
2013
eventData.putInt("numberOfPointers", numberOfPointers)

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,11 @@ import com.swmansion.gesturehandler.core.StylusData
77

88
class HoverGestureHandlerEventDataBuilder(handler: HoverGestureHandler) :
99
GestureHandlerEventDataBuilder<HoverGestureHandler>(handler) {
10-
private val x: Float
11-
private val y: Float
12-
private val absoluteX: Float
13-
private val absoluteY: Float
14-
private val stylusData: StylusData
15-
16-
init {
17-
x = handler.lastRelativePositionX
18-
y = handler.lastRelativePositionY
19-
absoluteX = handler.lastPositionInWindowX
20-
absoluteY = handler.lastPositionInWindowY
21-
stylusData = handler.stylusData
22-
}
10+
private val x: Float = handler.lastRelativePositionX
11+
private val y: Float = handler.lastRelativePositionY
12+
private val absoluteX: Float = handler.lastPositionInWindowX
13+
private val absoluteY: Float = handler.lastPositionInWindowY
14+
private val stylusData: StylusData = handler.stylusData
2315

2416
override fun buildEventData(eventData: WritableMap) {
2517
super.buildEventData(eventData)

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,11 @@ import com.swmansion.gesturehandler.core.LongPressGestureHandler
66

77
class LongPressGestureHandlerEventDataBuilder(handler: LongPressGestureHandler) :
88
GestureHandlerEventDataBuilder<LongPressGestureHandler>(handler) {
9-
private val x: Float
10-
private val y: Float
11-
private val absoluteX: Float
12-
private val absoluteY: Float
13-
private val duration: Int
14-
15-
init {
16-
x = handler.lastRelativePositionX
17-
y = handler.lastRelativePositionY
18-
absoluteX = handler.lastPositionInWindowX
19-
absoluteY = handler.lastPositionInWindowY
20-
duration = handler.duration
21-
}
9+
private val x: Float = handler.lastRelativePositionX
10+
private val y: Float = handler.lastRelativePositionY
11+
private val absoluteX: Float = handler.lastPositionInWindowX
12+
private val absoluteY: Float = handler.lastPositionInWindowY
13+
private val duration: Int = handler.duration
2214

2315
override fun buildEventData(eventData: WritableMap) {
2416
super.buildEventData(eventData)

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import com.swmansion.gesturehandler.core.NativeViewGestureHandler
55

66
class NativeGestureHandlerEventDataBuilder(handler: NativeViewGestureHandler) :
77
GestureHandlerEventDataBuilder<NativeViewGestureHandler>(handler) {
8-
private val pointerInside: Boolean
9-
10-
init {
11-
pointerInside = handler.isWithinBounds
12-
}
8+
private val pointerInside: Boolean = handler.isWithinBounds
139

1410
override fun buildEventData(eventData: WritableMap) {
1511
super.buildEventData(eventData)

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

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,15 @@ import com.swmansion.gesturehandler.core.StylusData
77

88
class PanGestureHandlerEventDataBuilder(handler: PanGestureHandler) :
99
GestureHandlerEventDataBuilder<PanGestureHandler>(handler) {
10-
private val x: Float
11-
private val y: Float
12-
private val absoluteX: Float
13-
private val absoluteY: Float
14-
private val translationX: Float
15-
private val translationY: Float
16-
private val velocityX: Float
17-
private val velocityY: Float
18-
private val stylusData: StylusData
19-
20-
init {
21-
x = handler.lastRelativePositionX
22-
y = handler.lastRelativePositionY
23-
absoluteX = handler.lastPositionInWindowX
24-
absoluteY = handler.lastPositionInWindowY
25-
translationX = handler.translationX
26-
translationY = handler.translationY
27-
velocityX = handler.velocityX
28-
velocityY = handler.velocityY
29-
stylusData = handler.stylusData
30-
}
10+
private val x: Float = handler.lastRelativePositionX
11+
private val y: Float = handler.lastRelativePositionY
12+
private val absoluteX: Float = handler.lastPositionInWindowX
13+
private val absoluteY: Float = handler.lastPositionInWindowY
14+
private val translationX: Float = handler.translationX
15+
private val translationY: Float = handler.translationY
16+
private val velocityX: Float = handler.velocityX
17+
private val velocityY: Float = handler.velocityY
18+
private val stylusData: StylusData = handler.stylusData
3119

3220
override fun buildEventData(eventData: WritableMap) {
3321
super.buildEventData(eventData)

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@ import com.swmansion.gesturehandler.core.PinchGestureHandler
66

77
class PinchGestureHandlerEventDataBuilder(handler: PinchGestureHandler) :
88
GestureHandlerEventDataBuilder<PinchGestureHandler>(handler) {
9-
private val scale: Double
10-
private val focalX: Float
11-
private val focalY: Float
12-
private val velocity: Double
13-
14-
init {
15-
scale = handler.scale
16-
focalX = handler.focalPointX
17-
focalY = handler.focalPointY
18-
velocity = handler.velocity
19-
}
9+
private val scale: Double = handler.scale
10+
private val focalX: Float = handler.focalPointX
11+
private val focalY: Float = handler.focalPointY
12+
private val velocity: Double = handler.velocity
2013

2114
override fun buildEventData(eventData: WritableMap) {
2215
super.buildEventData(eventData)

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@ import com.swmansion.gesturehandler.core.RotationGestureHandler
66

77
class RotationGestureHandlerEventDataBuilder(handler: RotationGestureHandler) :
88
GestureHandlerEventDataBuilder<RotationGestureHandler>(handler) {
9-
private val rotation: Double
10-
private val anchorX: Float
11-
private val anchorY: Float
12-
private val velocity: Double
13-
14-
init {
15-
rotation = handler.rotation
16-
anchorX = handler.anchorX
17-
anchorY = handler.anchorY
18-
velocity = handler.velocity
19-
}
9+
private val rotation: Double = handler.rotation
10+
private val anchorX: Float = handler.anchorX
11+
private val anchorY: Float = handler.anchorY
12+
private val velocity: Double = handler.velocity
2013

2114
override fun buildEventData(eventData: WritableMap) {
2215
super.buildEventData(eventData)

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@ import com.swmansion.gesturehandler.core.TapGestureHandler
66

77
class TapGestureHandlerEventDataBuilder(handler: TapGestureHandler) :
88
GestureHandlerEventDataBuilder<TapGestureHandler>(handler) {
9-
private val x: Float
10-
private val y: Float
11-
private val absoluteX: Float
12-
private val absoluteY: Float
13-
14-
init {
15-
x = handler.lastRelativePositionX
16-
y = handler.lastRelativePositionY
17-
absoluteX = handler.lastPositionInWindowX
18-
absoluteY = handler.lastPositionInWindowY
19-
}
9+
private val x: Float = handler.lastRelativePositionX
10+
private val y: Float = handler.lastRelativePositionY
11+
private val absoluteX: Float = handler.lastPositionInWindowX
12+
private val absoluteY: Float = handler.lastPositionInWindowY
2013

2114
override fun buildEventData(eventData: WritableMap) {
2215
super.buildEventData(eventData)

0 commit comments

Comments
 (0)