Skip to content

Commit fdeb673

Browse files
committed
refactor(ui): extract SwipeActionRow with multi-action support
Rename SwipeToRevealItem to SwipeActionRow and move to ui:components as a shared composable. Support N actions via SwipeAction, where the rightmost action grows on full swipe and triggers automatically. Add stateKey parameter to prevent swipe state carryover across list item removals. Move dividers outside swipeable content so they remain static during swipe. Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 143bb94 commit fdeb673

4 files changed

Lines changed: 369 additions & 163 deletions

File tree

apps/flipcash/features/direct-send/src/main/kotlin/com/flipcash/app/directsend/internal/screens/ContactListScreen.kt

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.compose.foundation.lazy.rememberLazyListState
2323
import androidx.compose.foundation.shape.CircleShape
2424
import androidx.compose.material.icons.Icons
2525
import androidx.compose.material.icons.filled.GroupAdd
26+
import androidx.compose.material.icons.rounded.PersonRemove
2627
import androidx.compose.material3.HorizontalDivider
2728
import androidx.compose.material3.Icon
2829
import androidx.compose.material3.Text
@@ -69,7 +70,8 @@ import com.getcode.ui.components.AppBarDefaults
6970
import com.getcode.ui.components.AppBarWithTitle
7071
import com.getcode.ui.components.CircularIconButton
7172
import com.getcode.ui.components.SearchInput
72-
import com.getcode.ui.components.SwipeToRevealItem
73+
import com.getcode.ui.components.SwipeAction
74+
import com.getcode.ui.components.SwipeActionRow
7375
import com.getcode.ui.core.rememberedClickable
7476
import com.getcode.ui.core.verticalScrollStateGradient
7577
import com.getcode.ui.theme.CodeCircularProgressIndicator
@@ -248,16 +250,42 @@ private fun ContactList(
248250
items[index + 1] is ContactListItem.Header
249251

250252
if (isPickerMode) {
251-
SwipeToRevealItem(
252-
modifier = Modifier.animateItem(),
253-
onDelete = { onItemDismissed(item) },
254-
) {
255-
ContactRowItem(
256-
contact = item.contact,
257-
isOnFlipcash = item.isOnFlipcash,
258-
showDivider = !isLastInSection,
259-
onClick = { onItemClick(item) },
260-
)
253+
Column(modifier = Modifier.animateItem()) {
254+
SwipeActionRow(
255+
actions = listOf(
256+
SwipeAction(
257+
background = CodeTheme.colors.error,
258+
onTriggered = { onItemDismissed(item) },
259+
) {
260+
Icon(
261+
imageVector = Icons.Rounded.PersonRemove,
262+
contentDescription = null,
263+
tint = Color.White,
264+
modifier = Modifier.requiredSize(CodeTheme.dimens.staticGrid.x5),
265+
)
266+
}
267+
),
268+
stateKey = item.contact.e164,
269+
) {
270+
ContactRowItem(
271+
contact = item.contact,
272+
isOnFlipcash = item.isOnFlipcash,
273+
showDivider = false,
274+
onClick = { onItemClick(item) },
275+
)
276+
}
277+
if (!isLastInSection) {
278+
HorizontalDivider(
279+
color = CodeTheme.colors.divider,
280+
modifier = Modifier
281+
.fillMaxWidth()
282+
.height(1.dp)
283+
.padding(
284+
start = CodeTheme.dimens.inset + CodeTheme.dimens.staticGrid.x8 + CodeTheme.dimens.grid.x3,
285+
end = CodeTheme.dimens.inset,
286+
),
287+
)
288+
}
261289
}
262290
} else {
263291
ContactRowItem(

apps/flipcash/shared/currency-selection/ui/src/main/kotlin/com/flipcash/app/currency/internal/components/ListRowItem.kt

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import androidx.compose.foundation.layout.height
1111
import androidx.compose.foundation.layout.padding
1212
import androidx.compose.foundation.layout.requiredSize
1313
import androidx.compose.foundation.layout.wrapContentWidth
14-
import androidx.compose.material.Divider
15-
import androidx.compose.material.Text
14+
import androidx.compose.material3.HorizontalDivider
15+
import androidx.compose.material3.Text
1616
import androidx.compose.runtime.Composable
1717
import androidx.compose.ui.Alignment
1818
import androidx.compose.ui.Modifier
@@ -23,7 +23,7 @@ import androidx.compose.ui.unit.dp
2323
import com.flipcash.app.currency.internal.CurrencyListItem
2424
import com.flipcash.features.currency.R
2525
import com.getcode.theme.CodeTheme
26-
import com.getcode.ui.components.SwipeToRevealItem
26+
import com.getcode.ui.components.SwipeActionRow
2727
import com.getcode.ui.core.rememberedClickable
2828

2929
@Composable
@@ -91,28 +91,38 @@ internal fun ListRowItem(
9191
contentDescription = ""
9292
)
9393
}
94+
}
95+
}
9496

95-
Divider(
97+
if (item.isRecent) {
98+
Column(modifier = modifier) {
99+
SwipeActionRow(
100+
modifier = Modifier.weight(1f),
101+
onDelete = onRemoved,
102+
stateKey = item.currency.code,
103+
) {
104+
rowContent()
105+
}
106+
HorizontalDivider(
96107
color = CodeTheme.colors.dividerVariant,
97108
modifier = Modifier
98109
.fillMaxWidth()
99110
.height(1.dp)
100-
.align(Alignment.BottomCenter)
101111
.padding(start = CodeTheme.dimens.inset)
102112
)
103113
}
104-
}
105-
106-
if (item.isRecent) {
107-
SwipeToRevealItem(
108-
modifier = modifier,
109-
onDelete = onRemoved,
110-
) {
111-
rowContent()
112-
}
113114
} else {
114-
Box(modifier = modifier) {
115-
rowContent()
115+
Column(modifier = modifier) {
116+
Box(modifier = Modifier.weight(1f)) {
117+
rowContent()
118+
}
119+
HorizontalDivider(
120+
color = CodeTheme.colors.dividerVariant,
121+
modifier = Modifier
122+
.fillMaxWidth()
123+
.height(1.dp)
124+
.padding(start = CodeTheme.dimens.inset)
125+
)
116126
}
117127
}
118128
}

0 commit comments

Comments
 (0)