Skip to content

Commit 84b1fe0

Browse files
committed
Renamings
1 parent 7831554 commit 84b1fe0

File tree

9 files changed

+66
-66
lines changed

9 files changed

+66
-66
lines changed

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ dependencyResolutionManagement {
2020
}
2121

2222
rootProject.name = "SwipeableItem"
23-
include(":swipeableitem")
23+
include(":swipe_to_reveal")
File renamed without changes.

swipeableitem/build.gradle.kts renamed to swipe_to_reveal/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
android {
8-
namespace = "nikmax.swipeableitem"
8+
namespace = "nikmax.swipe_to_reveal"
99
compileSdk = 35
1010

1111
defaultConfig {
File renamed without changes.
File renamed without changes.

swipeableitem/src/androidTest/java/nikmax/swipeableitem/SwipeableItemKtTest.kt renamed to swipe_to_reveal/src/androidTest/java/nikmax/swipe_to_reveal/SwipeableItemKtTest.kt

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package nikmax.swipeableitem
1+
package nikmax.swipe_to_reveal
22

33
import androidx.compose.animation.core.snap
44
import androidx.compose.foundation.background
@@ -40,11 +40,11 @@ class SwipeableItemKtTest {
4040

4141
@Composable
4242
private fun TestComposable(
43-
position: MutableState<SwipeableItemPosition>,
43+
position: MutableState<Position>,
4444
onFullyExpanded: () -> Unit = {},
4545
onFullyCollapsed: () -> Unit = {},
4646
) {
47-
SwipeableItem(
47+
SwipeToRevealContainer(
4848
position = position,
4949
leftActions = { Box(Modifier.size(actionsWidth)) },
5050
rightActions = { Box(Modifier.size(actionsWidth)) },
@@ -65,29 +65,29 @@ class SwipeableItemKtTest {
6565

6666
@Test
6767
fun changePosition_onStateUpdate() {
68-
val position = mutableStateOf(SwipeableItemPosition.COLLAPSED)
68+
val position = mutableStateOf(Position.COLLAPSED)
6969
rule.setContent {
7070
TestComposable(position)
7171
}
7272
//LTR
73-
assert(position.value == SwipeableItemPosition.COLLAPSED)
74-
position.value = SwipeableItemPosition.RIGHT
75-
assert(position.value == SwipeableItemPosition.RIGHT)
73+
assert(position.value == Position.COLLAPSED)
74+
position.value = Position.RIGHT
75+
assert(position.value == Position.RIGHT)
7676
rule.onNodeWithTag(Tags.CONTENT)
7777
.assertLeftPositionInRootIsEqualTo(actionsWidth)
7878
//reset
79-
position.value = SwipeableItemPosition.COLLAPSED
79+
position.value = Position.COLLAPSED
8080
//RTL
81-
assert(position.value == SwipeableItemPosition.COLLAPSED)
82-
position.value = SwipeableItemPosition.LEFT
83-
assert(position.value == SwipeableItemPosition.LEFT)
81+
assert(position.value == Position.COLLAPSED)
82+
position.value = Position.LEFT
83+
assert(position.value == Position.LEFT)
8484
rule.onNodeWithTag(Tags.CONTENT)
8585
.assertLeftPositionInRootIsEqualTo(-actionsWidth)
8686
}
8787

8888
@Test
8989
fun changePosition_onSwipe() {
90-
val position = mutableStateOf(SwipeableItemPosition.COLLAPSED)
90+
val position = mutableStateOf(Position.COLLAPSED)
9191
rule.setContent {
9292
TestComposable(position)
9393
}
@@ -123,7 +123,7 @@ class SwipeableItemKtTest {
123123

124124
@Test
125125
fun collapseBack_after_shiftedForLessThanHalfActionsWidth() {
126-
val position = mutableStateOf(SwipeableItemPosition.COLLAPSED)
126+
val position = mutableStateOf(Position.COLLAPSED)
127127
rule.setContent {
128128
TestComposable(position)
129129
}
@@ -136,7 +136,7 @@ class SwipeableItemKtTest {
136136
)
137137
}.assertLeftPositionInRootIsEqualTo(0.dp)
138138
//reset
139-
position.value = SwipeableItemPosition.COLLAPSED
139+
position.value = Position.COLLAPSED
140140
//RTL
141141
rule.onNodeWithTag(Tags.CONTENT)
142142
.assertLeftPositionInRootIsEqualTo(0.dp)
@@ -149,7 +149,7 @@ class SwipeableItemKtTest {
149149

150150
@Test
151151
fun fullyExpands_after_shiftedMoreThanHalfActionsWidth() {
152-
val position = mutableStateOf(SwipeableItemPosition.COLLAPSED)
152+
val position = mutableStateOf(Position.COLLAPSED)
153153
rule.setContent {
154154
TestComposable(position)
155155
}
@@ -162,7 +162,7 @@ class SwipeableItemKtTest {
162162
)
163163
}.assertLeftPositionInRootIsEqualTo(actionsWidth)
164164
//reset
165-
position.value = SwipeableItemPosition.COLLAPSED
165+
position.value = Position.COLLAPSED
166166
//RTL
167167
rule.onNodeWithTag(Tags.CONTENT)
168168
.assertLeftPositionInRootIsEqualTo(0.dp)
@@ -175,7 +175,7 @@ class SwipeableItemKtTest {
175175

176176
@Test
177177
fun callbackCalled_on_fullLeftOrRightPosition() {
178-
val position = mutableStateOf(SwipeableItemPosition.COLLAPSED)
178+
val position = mutableStateOf(Position.COLLAPSED)
179179
var callbackIsCalled = false
180180
rule.setContent {
181181
TestComposable(
@@ -196,7 +196,7 @@ class SwipeableItemKtTest {
196196
rule.waitForIdle()
197197
assertTrue(callbackIsCalled)
198198
//state set
199-
position.value = SwipeableItemPosition.COLLAPSED
199+
position.value = Position.COLLAPSED
200200
assertTrue(callbackIsCalled)
201201
//reset
202202
callbackIsCalled = false
@@ -210,13 +210,13 @@ class SwipeableItemKtTest {
210210
rule.waitForIdle()
211211
assertTrue(callbackIsCalled)
212212
//state set
213-
position.value = SwipeableItemPosition.COLLAPSED
213+
position.value = Position.COLLAPSED
214214
assertTrue(callbackIsCalled)
215215
}
216216

217217
@Test
218218
fun callbackIsCalled_on_centerPosition() {
219-
val position = mutableStateOf(SwipeableItemPosition.COLLAPSED)
219+
val position = mutableStateOf(Position.COLLAPSED)
220220
var callbackIsCalled = false
221221
rule.setContent {
222222
TestComposable(
@@ -242,9 +242,9 @@ class SwipeableItemKtTest {
242242
//reset
243243
callbackIsCalled = false
244244
//state set
245-
position.value = SwipeableItemPosition.LEFT
245+
position.value = Position.LEFT
246246
rule.waitForIdle()
247-
position.value = SwipeableItemPosition.COLLAPSED
247+
position.value = Position.COLLAPSED
248248
rule.waitForIdle()
249249
assertTrue(callbackIsCalled)
250250
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package nikmax.swipe_to_reveal
2+
3+
enum class Position {
4+
COLLAPSED,
5+
MOVING,
6+
LEFT,
7+
RIGHT
8+
}

swipeableitem/src/main/java/nikmax/swipeableitem/SwipeableItem.kt renamed to swipe_to_reveal/src/main/java/nikmax/swipe_to_reveal/SwipeToRevealContainer.kt

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package nikmax.swipeableitem
1+
package nikmax.swipe_to_reveal
22

33
import android.widget.Toast
44
import androidx.compose.animation.core.Animatable
@@ -46,16 +46,16 @@ import kotlin.math.roundToInt
4646

4747

4848
/**
49-
* Left [SwipeableItem] with actions on the right side
49+
* Left [SwipeToRevealContainer] with actions on the right side
5050
* @param isRevealed is actions fully expanded
5151
* @param actions row-scoped menu hidden under the content right side and appears on right-to-left swipe
5252
* @param onFullyExpanded is called when actions are fully expanded
5353
* @param onFullyCollapsed is called when actions are fully collapsed
5454
* @param content item main content
5555
* */
5656
@Composable
57-
fun LeftSwipeableItem(
58-
position: MutableState<SwipeableItemPosition>,
57+
fun SwipeToRevealContainerRTL(
58+
position: MutableState<Position>,
5959
actions: @Composable RowScope.() -> Unit,
6060
modifier: Modifier = Modifier,
6161
onFullyExpanded: () -> Unit = {},
@@ -64,7 +64,7 @@ fun LeftSwipeableItem(
6464
animationSpec: AnimationSpec<Float> = spring(),
6565
content: @Composable () -> Unit
6666
) {
67-
SwipeableItem(
67+
SwipeToRevealContainer(
6868
position = position,
6969
leftActions = {},
7070
rightActions = actions,
@@ -78,15 +78,15 @@ fun LeftSwipeableItem(
7878

7979
@Preview
8080
@Composable
81-
private fun LeftSwipeableItemPreview() {
81+
private fun RTLPreview() {
8282
MaterialTheme {
83-
var state = remember { mutableStateOf(SwipeableItemPosition.COLLAPSED) }
84-
LeftSwipeableItem(
83+
var state = remember { mutableStateOf(Position.COLLAPSED) }
84+
SwipeToRevealContainerRTL(
8585
position = state,
8686
actions = {
8787
IconButton(
8888
onClick = {
89-
state.value = SwipeableItemPosition.COLLAPSED
89+
state.value = Position.COLLAPSED
9090
},
9191
modifier = Modifier.background(Color.Red)
9292
) {
@@ -104,24 +104,24 @@ private fun LeftSwipeableItemPreview() {
104104

105105

106106
/**
107-
* Right [SwipeableItem] with actions on the left side
107+
* Right [SwipeToRevealContainer] with actions on the left side
108108
* @param isRevealed is actions fully expanded
109109
* @param actions row-scoped menu hidden under the content left side and appears on left-to-right swipe
110110
* @param onFullyExpanded is called when actions are fully expanded
111111
* @param onFullyCollapsed is called when actions are fully collapsed
112112
* @param content item main content
113113
* */
114114
@Composable
115-
fun RightSwipeableItem(
116-
position: MutableState<SwipeableItemPosition>,
115+
fun SwipeToRevealContainerLTR(
116+
position: MutableState<Position>,
117117
actions: @Composable RowScope.() -> Unit,
118118
modifier: Modifier = Modifier,
119119
onFullyExpanded: () -> Unit = {},
120120
onFullyCollapsed: () -> Unit = {},
121121
animationSpec: AnimationSpec<Float> = spring(),
122122
content: @Composable () -> Unit
123123
) {
124-
SwipeableItem(
124+
SwipeToRevealContainer(
125125
position = position,
126126
leftActions = actions,
127127
rightActions = {},
@@ -135,15 +135,15 @@ fun RightSwipeableItem(
135135

136136
@Preview
137137
@Composable
138-
private fun RightSwipeableItemPreview() {
138+
private fun LTRPreview() {
139139
MaterialTheme {
140-
var state = remember { mutableStateOf(SwipeableItemPosition.COLLAPSED) }
141-
RightSwipeableItem(
140+
var state = remember { mutableStateOf(Position.COLLAPSED) }
141+
SwipeToRevealContainerLTR(
142142
position = state,
143143
actions = {
144144
IconButton(
145145
onClick = {
146-
state.value = SwipeableItemPosition.COLLAPSED
146+
state.value = Position.COLLAPSED
147147
},
148148
modifier = Modifier.background(Color.Red)
149149
) {
@@ -161,7 +161,7 @@ private fun RightSwipeableItemPreview() {
161161

162162

163163
/**
164-
* Left and right [SwipeableItem] with actions on the both sides
164+
* Left and right [SwipeToRevealContainer] with actions on the both sides
165165
* @param isLeftRevealed is left actions fully expanded
166166
* @param isRightRevealed is right actions fully expanded
167167
* @param leftActions row-scoped menu hidden under the content left side and appears on left-to-right swipe
@@ -171,8 +171,8 @@ private fun RightSwipeableItemPreview() {
171171
* @param content item main content
172172
* */
173173
@Composable
174-
fun SwipeableItem(
175-
position: MutableState<SwipeableItemPosition>,
174+
fun SwipeToRevealContainer(
175+
position: MutableState<Position>,
176176
leftActions: @Composable RowScope.() -> Unit,
177177
rightActions: @Composable RowScope.() -> Unit,
178178
modifier: Modifier = Modifier,
@@ -201,21 +201,21 @@ fun SwipeableItem(
201201
position.value,
202202
) {
203203
when (position.value) {
204-
SwipeableItemPosition.MOVING -> {} //not in use for now
205-
SwipeableItemPosition.COLLAPSED -> if (contentOffset.value != 0f) {
204+
Position.MOVING -> {} //not in use for now
205+
Position.COLLAPSED -> if (contentOffset.value != 0f) {
206206
Timber.d("launched effect called to collapse")
207207
contentOffset.animateTo(0f)
208208
onFullyCollapsed()
209209
}
210-
SwipeableItemPosition.LEFT -> if (contentOffset.value > -rightMenuWidth) {
210+
Position.LEFT -> if (contentOffset.value > -rightMenuWidth) {
211211
Timber.d("launched effect called to expand left")
212212
contentOffset.animateTo(
213213
-rightMenuWidth,
214214
animationSpec
215215
)
216216
onFullyExpanded()
217217
}
218-
SwipeableItemPosition.RIGHT -> if (contentOffset.value < leftMenuWidth) {
218+
Position.RIGHT -> if (contentOffset.value < leftMenuWidth) {
219219
Timber.d("launched effect called to expand right")
220220
contentOffset.animateTo(
221221
leftMenuWidth,
@@ -266,7 +266,7 @@ fun SwipeableItem(
266266
.coerceIn(-rightMenuWidth, leftMenuWidth)
267267
.let { newOffset ->
268268
Timber.d("Moving: $newOffset")
269-
position.value = SwipeableItemPosition.MOVING
269+
position.value = Position.MOVING
270270
contentOffset.snapTo(newOffset)
271271
}
272272
}
@@ -277,7 +277,7 @@ fun SwipeableItem(
277277
if (contentOffset.value > leftMenuWidth / 2f) {
278278
scope.launch {
279279
Timber.d("Moved right for more than a half - expanding...")
280-
position.value = SwipeableItemPosition.RIGHT
280+
position.value = Position.RIGHT
281281
onFullyExpanded()
282282
}
283283
}
@@ -286,15 +286,15 @@ fun SwipeableItem(
286286
else if (contentOffset.value < -rightMenuWidth / 2f) {
287287
scope.launch {
288288
Timber.d("Moved left for more than a half - expanding...")
289-
position.value = SwipeableItemPosition.LEFT
289+
position.value = Position.LEFT
290290
onFullyExpanded()
291291
}
292292
}
293293
//if shifted only a little bit, shift back to center
294294
else {
295295
scope.launch {
296296
Timber.d("Moved for less than a half - collapsing back...")
297-
position.value = SwipeableItemPosition.COLLAPSED
297+
position.value = Position.COLLAPSED
298298
onFullyCollapsed()
299299
}
300300
}
@@ -309,24 +309,24 @@ fun SwipeableItem(
309309

310310
@Preview
311311
@Composable
312-
private fun SwipeableItemPreview() {
312+
private fun TwoSidePreview() {
313313
MaterialTheme {
314314
val context = LocalContext.current
315-
var state = remember { mutableStateOf(SwipeableItemPosition.COLLAPSED) }
316-
SwipeableItem(
315+
var state = remember { mutableStateOf(Position.COLLAPSED) }
316+
SwipeToRevealContainer(
317317
position = state,
318318
leftActions = {
319319
IconButton(
320320
onClick = {
321-
state.value = SwipeableItemPosition.COLLAPSED
321+
state.value = Position.COLLAPSED
322322
},
323323
modifier = Modifier.background(Color.Red)
324324
) {
325325
Icon(Icons.Default.Delete, null)
326326
}
327327
IconButton(
328328
onClick = {
329-
state.value = SwipeableItemPosition.COLLAPSED
329+
state.value = Position.COLLAPSED
330330
},
331331
modifier = Modifier.background(Color.Cyan)
332332
) {
@@ -336,7 +336,7 @@ private fun SwipeableItemPreview() {
336336
rightActions = {
337337
IconButton(
338338
onClick = {
339-
state.value = SwipeableItemPosition.COLLAPSED
339+
state.value = Position.COLLAPSED
340340
},
341341
modifier = Modifier.background(Color.Green)
342342
) {

swipeableitem/src/main/java/nikmax/swipeableitem/SwipeableItemPosition.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)