@@ -10,6 +10,7 @@ import type {
1010 ViewStyle ,
1111} from 'react-native' ;
1212
13+ import { ListItemContext } from './ListItemContext' ;
1314import { ListTokens } from './tokens' ;
1415import { ListRowContext , getLeftStyles , getRightStyles } from './utils' ;
1516import type { Style } from './utils' ;
@@ -45,6 +46,14 @@ export type Props = $RemoveChildren<typeof TouchableRipple> & {
4546 * Description text for the list item or callback which returns a React element to display the description.
4647 */
4748 description ?: Description ;
49+ /**
50+ * Element to display in the leading slot. Takes precedence over `left`.
51+ */
52+ leading ?: React . ReactNode ;
53+ /**
54+ * Element to display in the trailing slot. Takes precedence over `right`.
55+ */
56+ trailing ?: React . ReactNode ;
4857 /**
4958 * Callback which returns a React element to display on the left side.
5059 */
@@ -146,6 +155,8 @@ export type Props = $RemoveChildren<typeof TouchableRipple> & {
146155const ListItem = ( {
147156 left,
148157 right,
158+ leading,
159+ trailing,
149160 title,
150161 description,
151162 selected,
@@ -247,6 +258,45 @@ const ListItem = ({
247258 [ isDescriptionMultiline ]
248259 ) ;
249260
261+ const accessoryContext = React . useMemo (
262+ ( ) => ( { color : descriptionColor } ) ,
263+ [ descriptionColor ]
264+ ) ;
265+
266+ const renderLeading = ( ) => {
267+ const accessoryStyle = getLeftStyles ( isDescriptionMultiline , description ) ;
268+
269+ if ( leading ) {
270+ return < View style = { accessoryStyle } > { leading } </ View > ;
271+ }
272+
273+ return left
274+ ? left ( {
275+ color : selected
276+ ? theme . colors [ ListTokens . selectedContentColor ]
277+ : theme . colors [ ListTokens . leadingIconColor ] ,
278+ style : accessoryStyle ,
279+ } )
280+ : null ;
281+ } ;
282+
283+ const renderTrailing = ( ) => {
284+ const accessoryStyle = getRightStyles ( isDescriptionMultiline , description ) ;
285+
286+ if ( trailing ) {
287+ return < View style = { accessoryStyle } > { trailing } </ View > ;
288+ }
289+
290+ return right
291+ ? right ( {
292+ color : selected
293+ ? theme . colors [ ListTokens . selectedContentColor ]
294+ : theme . colors [ ListTokens . trailingIconColor ] ,
295+ style : accessoryStyle ,
296+ } )
297+ : null ;
298+ } ;
299+
250300 return (
251301 < ListRowContext . Provider value = { rowContext } >
252302 < TouchableRipple
@@ -264,34 +314,22 @@ const ListItem = ({
264314 theme = { theme }
265315 testID = { testID }
266316 >
267- < View style = { [ styles . row , containerStyle ] } >
268- { left
269- ? left ( {
270- color : selected
271- ? theme . colors [ ListTokens . selectedContentColor ]
272- : theme . colors [ ListTokens . leadingIconColor ] ,
273- style : getLeftStyles ( isDescriptionMultiline , description ) ,
274- } )
275- : null }
276- < View
277- style = { [ styles . item , styles . content , contentStyle ] }
278- testID = { `${ testID } -content` }
279- >
280- { renderTitle ( ) }
317+ < ListItemContext . Provider value = { accessoryContext } >
318+ < View style = { [ styles . row , containerStyle ] } >
319+ { renderLeading ( ) }
320+ < View
321+ style = { [ styles . item , styles . content , contentStyle ] }
322+ testID = { `${ testID } -content` }
323+ >
324+ { renderTitle ( ) }
281325
282- { description
283- ? renderDescription ( descriptionColor , description )
284- : null }
326+ { description
327+ ? renderDescription ( descriptionColor , description )
328+ : null }
329+ </ View >
330+ { renderTrailing ( ) }
285331 </ View >
286- { right
287- ? right ( {
288- color : selected
289- ? theme . colors [ ListTokens . selectedContentColor ]
290- : theme . colors [ ListTokens . trailingIconColor ] ,
291- style : getRightStyles ( isDescriptionMultiline , description ) ,
292- } )
293- : null }
294- </ View >
332+ </ ListItemContext . Provider >
295333 </ TouchableRipple >
296334 </ ListRowContext . Provider >
297335 ) ;
0 commit comments