11import React from 'react' ;
2- import { GestureResponderEvent , Linking , Text } from 'react-native' ;
2+ import { GestureResponderEvent , Linking , Text , View } from 'react-native' ;
33import anchorme from 'anchorme' ;
44import truncate from 'lodash/truncate' ;
55// @ts -expect-error
@@ -11,6 +11,7 @@ import {
1111 ParseFunction ,
1212 parseInline ,
1313 ReactNodeOutput ,
14+ SingleASTNode ,
1415} from 'simple-markdown' ;
1516
1617import type { MessageType } from '../../../MessageList/hooks/useMessageList' ;
@@ -41,6 +42,9 @@ const defaultMarkdownStyles: MarkdownStyle = {
4142 listItemText : {
4243 flex : 0 ,
4344 } ,
45+ listRow : {
46+ flexDirection : 'row' ,
47+ } ,
4448 mentions : {
4549 fontWeight : '700' ,
4650 } ,
@@ -242,8 +246,37 @@ export const renderText = <
242246 ) ;
243247 } ;
244248
249+ const listLevels = {
250+ 'top' : 'top' ,
251+ 'sub' : 'sub' ,
252+ }
253+
254+ const customListAtLevel = ( level : keyof typeof listLevels ) : ReactNodeOutput => ( node , output , { ...state } ) => {
255+ var numberIndex = node . start ;
256+ var items = node . items . map ( ( item : Array < SingleASTNode > , i : number ) => {
257+ const withinList = item . length > 1 && item [ 1 ] . type === 'list' ;
258+ var content = output ( item , { ...state , withinList } ) ;
259+
260+ const isTopLevelText = [ 'text' , 'paragraph' , 'strong' ] . includes ( item [ 0 ] . type ) && withinList == false
261+
262+ numberIndex ++ ;
263+
264+ return (
265+ < View key = { i } style = { styles . listRow } >
266+ < Text style = { styles . listItemNumber } > { node . ordered ? `${ numberIndex } . ` : `\u2022` } </ Text >
267+ < Text style = { [ styles . listItemText , isTopLevelText && { marginBottom : 0 } ] } > { content } </ Text >
268+ </ View >
269+ ) ;
270+ } ) ;
271+
272+ const isSublist = level === 'sub' ;
273+ return ( < View key = { state . key } style = { [ isSublist ? styles . list : styles . sublist ] } > { items } </ View > ) ;
274+ }
275+
245276 const customRules = {
246277 link : { react } ,
278+ list : { react : customListAtLevel ( 'top' ) } ,
279+ sublist : { react : customListAtLevel ( 'sub' ) } ,
247280 // we have no react rendering support for reflinks
248281 reflink : { match : ( ) => null } ,
249282 ...( mentionedUsers
0 commit comments