Reduce <Text> nesting (#6615)
* Move isOnlyEmoji out of RichText To fix Fast Refresh. * Make renderChildrenWithEmoji work with any children * Always go through UITextView for consistency It already contains the `selectable` and `iOS` checks inside. * Move `emoji` check into `renderChildrenWithEmoji` * Remove unnecessary intermediate UITextView nodes * Make childHasEmoji check recursive It didn't handle nested arrays etc correctly before. * Remove the "children must be string" limitation Should not be necessary now that we correctly handle nested arrays etc. * Fix unnecessary regex reallocation This doesn't have a global flag so it's okay to reuse. * Remove unnecessary <Text> wrapper in RichText
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React from 'react'
|
||||
import {StyleSheet, Text as RNText, TextProps} from 'react-native'
|
||||
import {StyleSheet, TextProps} from 'react-native'
|
||||
import {UITextView} from 'react-native-uitextview'
|
||||
|
||||
import {lh, s} from '#/lib/styles'
|
||||
@@ -9,7 +9,6 @@ import {isIOS, isWeb} from '#/platform/detection'
|
||||
import {applyFonts, useAlf} from '#/alf'
|
||||
import {
|
||||
childHasEmoji,
|
||||
childIsString,
|
||||
renderChildrenWithEmoji,
|
||||
StringChild,
|
||||
} from '#/alf/typography'
|
||||
@@ -56,10 +55,6 @@ function Text_DEPRECATED({
|
||||
`Text: emoji detected but emoji not enabled: "${children}"\n\nPlease add <Text emoji />'`,
|
||||
)
|
||||
}
|
||||
|
||||
if (emoji && !childIsString(children)) {
|
||||
logger.error('Text: when <Text emoji />, children can only be strings.')
|
||||
}
|
||||
}
|
||||
|
||||
const textProps = React.useMemo(() => {
|
||||
@@ -107,19 +102,9 @@ function Text_DEPRECATED({
|
||||
type,
|
||||
])
|
||||
|
||||
if (selectable && isIOS) {
|
||||
return (
|
||||
<UITextView {...textProps}>
|
||||
{isIOS && emoji
|
||||
? renderChildrenWithEmoji(children, textProps)
|
||||
: children}
|
||||
</UITextView>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<RNText {...textProps}>
|
||||
{isIOS && emoji ? renderChildrenWithEmoji(children, textProps) : children}
|
||||
</RNText>
|
||||
<UITextView {...textProps}>
|
||||
{renderChildrenWithEmoji(children, textProps, emoji ?? false)}
|
||||
</UITextView>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user