11package io.github.hdcodedev.composegif.ksp
22
3+ import io.github.hdcodedev.composegif.annotations.GifGestureType
4+ import io.github.hdcodedev.composegif.annotations.GifInteractionTarget
5+ import io.github.hdcodedev.composegif.annotations.GifInteractionType
6+ import io.github.hdcodedev.composegif.annotations.GifSwipeDirection
7+ import io.github.hdcodedev.composegif.annotations.GifSwipeDistance
38import kotlin.test.Test
49import kotlin.test.assertEquals
510import kotlin.test.assertTrue
@@ -10,13 +15,13 @@ class InteractionGestureExpanderTest {
1015 val gestures =
1116 InteractionGestureExpander .expand(
1217 InteractionSpec (
13- type = " PAUSE" ,
18+ type = GifInteractionType . PAUSE .name ,
1419 frames = 12 ,
1520 ),
1621 )
1722
1823 assertEquals(1 , gestures.size)
19- assertEquals(" PAUSE" , gestures.single().type)
24+ assertEquals(GifGestureType . PAUSE .name , gestures.single().type)
2025 assertEquals(12 , gestures.single().frames)
2126 }
2227
@@ -25,15 +30,15 @@ class InteractionGestureExpanderTest {
2530 val gestures =
2631 InteractionGestureExpander .expand(
2732 InteractionSpec (
28- type = " TAP" ,
29- target = " RIGHT" ,
33+ type = GifInteractionType . TAP .name ,
34+ target = GifInteractionTarget . RIGHT .name ,
3035 frames = 7 ,
3136 framesAfter = 0 ,
3237 ),
3338 )
3439
3540 val tap = gestures.single()
36- assertEquals(" TAP" , tap.type)
41+ assertEquals(GifGestureType . TAP .name , tap.type)
3742 assertEquals(0.70f , tap.xFraction)
3843 assertEquals(0.5f , tap.yFraction)
3944 assertEquals(7 , tap.framesAfter)
@@ -44,10 +49,10 @@ class InteractionGestureExpanderTest {
4449 val gestures =
4550 InteractionGestureExpander .expand(
4651 InteractionSpec (
47- type = " SWIPE" ,
48- target = " TOP" ,
49- direction = " RIGHT_TO_LEFT" ,
50- distance = " LONG" ,
52+ type = GifInteractionType . SWIPE .name ,
53+ target = GifInteractionTarget . TOP .name ,
54+ direction = GifSwipeDirection . RIGHT_TO_LEFT .name ,
55+ distance = GifSwipeDistance . LONG .name ,
5156 travelFrames = 9 ,
5257 holdStartFrames = 4 ,
5358 releaseFrames = 3 ,
@@ -57,14 +62,14 @@ class InteractionGestureExpanderTest {
5762
5863 assertEquals(2 , gestures.size)
5964 val drag = gestures[0 ]
60- assertEquals(" DRAG_PATH" , drag.type)
65+ assertEquals(GifGestureType . DRAG_PATH .name , drag.type)
6166 assertEquals(4 , drag.holdStartFrames)
6267 assertEquals(9 , drag.framesPerWaypoint)
6368 assertEquals(3 , drag.releaseFrames)
6469 assertEquals(2 , drag.points.size)
6570 assertTrue(drag.points[0 ].x > drag.points[1 ].x)
6671 assertEquals(0.30f , drag.points[0 ].y)
67- assertEquals(" PAUSE" , gestures[1 ].type)
72+ assertEquals(GifGestureType . PAUSE .name , gestures[1 ].type)
6873 assertEquals(5 , gestures[1 ].frames)
6974 }
7075
@@ -73,22 +78,34 @@ class InteractionGestureExpanderTest {
7378 val leftToRight =
7479 InteractionGestureExpander
7580 .expand(
76- InteractionSpec (type = " SWIPE" , direction = " LEFT_TO_RIGHT" ),
81+ InteractionSpec (
82+ type = GifInteractionType .SWIPE .name,
83+ direction = GifSwipeDirection .LEFT_TO_RIGHT .name,
84+ ),
7785 ).first()
7886 val rightToLeft =
7987 InteractionGestureExpander
8088 .expand(
81- InteractionSpec (type = " SWIPE" , direction = " RIGHT_TO_LEFT" ),
89+ InteractionSpec (
90+ type = GifInteractionType .SWIPE .name,
91+ direction = GifSwipeDirection .RIGHT_TO_LEFT .name,
92+ ),
8293 ).first()
8394 val topToBottom =
8495 InteractionGestureExpander
8596 .expand(
86- InteractionSpec (type = " SWIPE" , direction = " TOP_TO_BOTTOM" ),
97+ InteractionSpec (
98+ type = GifInteractionType .SWIPE .name,
99+ direction = GifSwipeDirection .TOP_TO_BOTTOM .name,
100+ ),
87101 ).first()
88102 val bottomToTop =
89103 InteractionGestureExpander
90104 .expand(
91- InteractionSpec (type = " SWIPE" , direction = " BOTTOM_TO_TOP" ),
105+ InteractionSpec (
106+ type = GifInteractionType .SWIPE .name,
107+ direction = GifSwipeDirection .BOTTOM_TO_TOP .name,
108+ ),
92109 ).first()
93110
94111 assertTrue(leftToRight.points.first().x < leftToRight.points.last().x)
@@ -102,17 +119,26 @@ class InteractionGestureExpanderTest {
102119 val shortSwipe =
103120 InteractionGestureExpander
104121 .expand(
105- InteractionSpec (type = " SWIPE" , distance = " SHORT" ),
122+ InteractionSpec (
123+ type = GifInteractionType .SWIPE .name,
124+ distance = GifSwipeDistance .SHORT .name,
125+ ),
106126 ).first()
107127 val mediumSwipe =
108128 InteractionGestureExpander
109129 .expand(
110- InteractionSpec (type = " SWIPE" , distance = " MEDIUM" ),
130+ InteractionSpec (
131+ type = GifInteractionType .SWIPE .name,
132+ distance = GifSwipeDistance .MEDIUM .name,
133+ ),
111134 ).first()
112135 val longSwipe =
113136 InteractionGestureExpander
114137 .expand(
115- InteractionSpec (type = " SWIPE" , distance = " LONG" ),
138+ InteractionSpec (
139+ type = GifInteractionType .SWIPE .name,
140+ distance = GifSwipeDistance .LONG .name,
141+ ),
116142 ).first()
117143
118144 val shortDelta = shortSwipe.points.last().x - shortSwipe.points.first().x
@@ -123,6 +149,96 @@ class InteractionGestureExpanderTest {
123149 assertTrue(mediumDelta < longDelta)
124150 }
125151
152+ @Test
153+ fun horizontalSwipeUsesTopBottomTargetLaneAndIgnoresLeftRightTarget () {
154+ val topLane =
155+ InteractionGestureExpander
156+ .expand(
157+ InteractionSpec (
158+ type = GifInteractionType .SWIPE .name,
159+ direction = GifSwipeDirection .LEFT_TO_RIGHT .name,
160+ target = GifInteractionTarget .TOP .name,
161+ ),
162+ ).first()
163+ val bottomLane =
164+ InteractionGestureExpander
165+ .expand(
166+ InteractionSpec (
167+ type = GifInteractionType .SWIPE .name,
168+ direction = GifSwipeDirection .LEFT_TO_RIGHT .name,
169+ target = GifInteractionTarget .BOTTOM .name,
170+ ),
171+ ).first()
172+ val leftTarget =
173+ InteractionGestureExpander
174+ .expand(
175+ InteractionSpec (
176+ type = GifInteractionType .SWIPE .name,
177+ direction = GifSwipeDirection .LEFT_TO_RIGHT .name,
178+ target = GifInteractionTarget .LEFT .name,
179+ ),
180+ ).first()
181+ val rightTarget =
182+ InteractionGestureExpander
183+ .expand(
184+ InteractionSpec (
185+ type = GifInteractionType .SWIPE .name,
186+ direction = GifSwipeDirection .LEFT_TO_RIGHT .name,
187+ target = GifInteractionTarget .RIGHT .name,
188+ ),
189+ ).first()
190+
191+ assertEquals(0.30f , topLane.points.first().y)
192+ assertEquals(0.70f , bottomLane.points.first().y)
193+ assertEquals(0.5f , leftTarget.points.first().y)
194+ assertEquals(0.5f , rightTarget.points.first().y)
195+ }
196+
197+ @Test
198+ fun verticalSwipeUsesLeftRightTargetLaneAndIgnoresTopBottomTarget () {
199+ val leftLane =
200+ InteractionGestureExpander
201+ .expand(
202+ InteractionSpec (
203+ type = GifInteractionType .SWIPE .name,
204+ direction = GifSwipeDirection .TOP_TO_BOTTOM .name,
205+ target = GifInteractionTarget .LEFT .name,
206+ ),
207+ ).first()
208+ val rightLane =
209+ InteractionGestureExpander
210+ .expand(
211+ InteractionSpec (
212+ type = GifInteractionType .SWIPE .name,
213+ direction = GifSwipeDirection .TOP_TO_BOTTOM .name,
214+ target = GifInteractionTarget .RIGHT .name,
215+ ),
216+ ).first()
217+ val topTarget =
218+ InteractionGestureExpander
219+ .expand(
220+ InteractionSpec (
221+ type = GifInteractionType .SWIPE .name,
222+ direction = GifSwipeDirection .TOP_TO_BOTTOM .name,
223+ target = GifInteractionTarget .TOP .name,
224+ ),
225+ ).first()
226+ val bottomTarget =
227+ InteractionGestureExpander
228+ .expand(
229+ InteractionSpec (
230+ type = GifInteractionType .SWIPE .name,
231+ direction = GifSwipeDirection .TOP_TO_BOTTOM .name,
232+ target = GifInteractionTarget .BOTTOM .name,
233+ ),
234+ ).first()
235+
236+ assertEquals(0.30f , leftLane.points.first().x)
237+ assertEquals(0.70f , rightLane.points.first().x)
238+ assertEquals(0.5f , topTarget.points.first().x)
239+ assertEquals(0.5f , bottomTarget.points.first().x)
240+ }
241+
126242 @Test
127243 fun unknownInteractionTypeProducesNoGestures () {
128244 val gestures =
0 commit comments