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:
dan
2024-11-21 22:52:16 +00:00
committed by GitHub
parent 84724bb940
commit dc3a42edb1
5 changed files with 52 additions and 90 deletions
+1 -7
View File
@@ -1,11 +1,9 @@
import {UITextView} from 'react-native-uitextview'
import {logger} from '#/logger'
import {isIOS} from '#/platform/detection'
import {atoms, flatten, useAlf, useTheme, web} from '#/alf'
import {
childHasEmoji,
childIsString,
normalizeTextStyles,
renderChildrenWithEmoji,
TextProps,
@@ -39,10 +37,6 @@ export function Text({
`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 shared = {
@@ -55,7 +49,7 @@ export function Text({
return (
<UITextView {...shared}>
{isIOS && emoji ? renderChildrenWithEmoji(children, shared) : children}
{renderChildrenWithEmoji(children, shared, emoji ?? false)}
</UITextView>
)
}