1- package nikmax.swipeableitem
1+ package nikmax.swipe_to_reveal
22
33import android.widget.Toast
44import 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 ) {
0 commit comments