@@ -77,7 +77,7 @@ data class TodoItem(
7777// [START android_compose_components_swipeitem]
7878@Composable
7979fun SwipeItem (
80- value : TodoItem ,
80+ todoItem : TodoItem ,
8181 startToEndAction : (TodoItem ) -> Unit ,
8282 endToStartAction : (TodoItem ) -> Unit ,
8383 modifier : Modifier = Modifier ,
@@ -87,12 +87,12 @@ fun SwipeItem(
8787 confirmValueChange = {
8888 when (it) {
8989 SwipeToDismissBoxValue .StartToEnd -> {
90- startToEndAction(value )
90+ startToEndAction(todoItem )
9191 // Do not dismiss this item.
9292 false
9393 }
9494 SwipeToDismissBoxValue .EndToStart -> {
95- endToStartAction(value )
95+ endToStartAction(todoItem )
9696 true
9797 }
9898 SwipeToDismissBoxValue .Settled -> {
@@ -104,8 +104,7 @@ fun SwipeItem(
104104
105105 SwipeToDismissBox (
106106 state = swipeToDismissBoxState,
107- modifier = modifier
108- .fillMaxSize(),
107+ modifier = modifier.fillMaxSize(),
109108 backgroundContent = {
110109 Row (
111110 modifier = Modifier
@@ -128,23 +127,20 @@ fun SwipeItem(
128127 ) {
129128 when (swipeToDismissBoxState.dismissDirection) {
130129 SwipeToDismissBoxValue .StartToEnd -> {
131- if (value.isItemDone) {
132- Icon (
133- imageVector = Icons .Default .CheckBox ,
134- contentDescription = " Item done" ,
135- tint = Color .White ,
136- modifier = Modifier
137- .padding(12 .dp)
138- )
130+ val icon = if (todoItem.isItemDone) {
131+ Icons .Default .CheckBox
139132 } else {
140- Icon (
141- imageVector = Icons .Default .CheckBoxOutlineBlank ,
142- contentDescription = " Item not done" ,
143- tint = Color .White ,
144- modifier = Modifier
145- .padding(12 .dp)
146- )
133+ Icons .Default .CheckBoxOutlineBlank
147134 }
135+
136+ val contentDescription = if (todoItem.isItemDone) " Done" else " Not done"
137+
138+ Icon (
139+ icon,
140+ contentDescription,
141+ Modifier .padding(12 .dp),
142+ tint = Color .White
143+ )
148144 }
149145
150146 SwipeToDismissBoxValue .EndToStart -> {
@@ -153,8 +149,7 @@ fun SwipeItem(
153149 imageVector = Icons .Default .Delete ,
154150 contentDescription = " Remove item" ,
155151 tint = Color .White ,
156- modifier = Modifier
157- .padding(12 .dp)
152+ modifier = Modifier .padding(12 .dp)
158153 )
159154 }
160155
@@ -163,7 +158,7 @@ fun SwipeItem(
163158 }
164159 }
165160 ) {
166- content(value )
161+ content(todoItem )
167162 }
168163}
169164// [END android_compose_components_swipeitem]
@@ -187,7 +182,7 @@ private fun SwipeItemExample() {
187182 key = { it.itemDescription }
188183 ) { todoItem ->
189184 SwipeItem (
190- value = todoItem,
185+ todoItem = todoItem,
191186 startToEndAction = {
192187 todoItem.isItemDone = ! todoItem.isItemDone
193188 },
@@ -208,23 +203,24 @@ private fun SwipeItemExample() {
208203// [START android_compose_components_swipecarditem]
209204@Composable
210205fun SwipeCardItem (
211- value : TodoItem ,
206+ todoItem : TodoItem ,
212207 startToEndAction : (TodoItem ) -> Unit ,
213208 endToStartAction : (TodoItem ) -> Unit ,
214209 modifier : Modifier = Modifier ,
215210 content : @Composable (TodoItem ) -> Unit
216211) {
212+ // [START_EXCLUDE]
217213 val swipeToDismissState = rememberSwipeToDismissBoxState(
218214 positionalThreshold = { totalDistance -> totalDistance * 0.25f },
219215 confirmValueChange = {
220216 when (it) {
221217 SwipeToDismissBoxValue .StartToEnd -> {
222- startToEndAction(value )
218+ startToEndAction(todoItem )
223219 // Do not dismiss this item.
224220 false
225221 }
226222 SwipeToDismissBoxValue .EndToStart -> {
227- endToStartAction(value )
223+ endToStartAction(todoItem )
228224 true
229225 }
230226 SwipeToDismissBoxValue .Settled -> {
@@ -234,6 +230,7 @@ fun SwipeCardItem(
234230 }
235231 )
236232
233+ // [END_EXCLUDE]
237234 SwipeToDismissBox (
238235 modifier = Modifier ,
239236 state = swipeToDismissState,
@@ -250,6 +247,7 @@ fun SwipeCardItem(
250247 },
251248 label = " swipeable card item background color"
252249 )
250+ // [START_EXCLUDE]
253251 Row (
254252 modifier = Modifier
255253 .background(color)
@@ -259,23 +257,15 @@ fun SwipeCardItem(
259257 ) {
260258 when (swipeToDismissState.dismissDirection) {
261259 SwipeToDismissBoxValue .StartToEnd -> {
262- if (value.isItemDone) {
263- Icon (
264- imageVector = Icons .Default .CheckBox ,
265- contentDescription = " Item done" ,
266- tint = Color .White ,
267- modifier = Modifier
268- .padding(12 .dp)
269- )
260+ val icon = if (todoItem.isItemDone) {
261+ Icons .Default .CheckBox
270262 } else {
271- Icon (
272- imageVector = Icons .Default .CheckBoxOutlineBlank ,
273- contentDescription = " Item not done" ,
274- tint = Color .White ,
275- modifier = Modifier
276- .padding(12 .dp)
277- )
263+ Icons .Default .CheckBoxOutlineBlank
278264 }
265+
266+ val contentDescription = if (todoItem.isItemDone) " Done" else " Not done"
267+
268+ Icon (icon, contentDescription, Modifier .padding(12 .dp), tint = Color .White )
279269 }
280270
281271 SwipeToDismissBoxValue .EndToStart -> {
@@ -284,8 +274,7 @@ fun SwipeCardItem(
284274 imageVector = Icons .Default .Delete ,
285275 contentDescription = " Remove item" ,
286276 tint = Color .White ,
287- modifier = Modifier
288- .padding(12 .dp)
277+ modifier = Modifier .padding(12 .dp)
289278 )
290279 }
291280
@@ -294,8 +283,9 @@ fun SwipeCardItem(
294283 }
295284 }
296285 ) {
297- content(value )
286+ content(todoItem )
298287 }
288+ // [END_EXCLUDE]
299289}
300290// [END android_compose_components_swipecarditem]
301291
@@ -318,7 +308,7 @@ private fun SwipeCardItemExample() {
318308 key = { it.itemDescription }
319309 ) { todoItem ->
320310 SwipeCardItem (
321- value = todoItem,
311+ todoItem = todoItem,
322312 startToEndAction = {
323313 todoItem.isItemDone = ! todoItem.isItemDone
324314 },
0 commit comments