-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move renderEmojisAsTextComponents to a new file
- Loading branch information
Showing
4 changed files
with
38 additions
and
43 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/components/InlineCodeBlock/renderEmojisAsTextComponents.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import Text from '@components/Text'; | ||
import type { TTextOrTPhrasing } from './types'; | ||
import { TDefaultRendererProps } from 'react-native-render-html'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
||
|
||
export function renderEmojisAsTextComponents(defaultRendererProps: TDefaultRendererProps<TTextOrTPhrasing>) { | ||
const elements: (string | React.JSX.Element)[] = []; | ||
const styles = useThemeStyles(); | ||
|
||
let hasLargeStyle = false; | ||
if ('data' in defaultRendererProps.tnode) { | ||
elements.push(defaultRendererProps.tnode.data); | ||
} else if (defaultRendererProps.tnode.children) { | ||
defaultRendererProps.tnode.children.forEach((child) => { | ||
if ('data' in child) { | ||
if (child.tagName === 'emoji') { | ||
const largeStyle = 'islarge' in child.attributes ? styles.onlyEmojisText : {}; | ||
if (Object.keys(largeStyle).length > 0) { | ||
hasLargeStyle = true; | ||
} | ||
elements.push(<Text style={[largeStyle, styles.emojiDefault]} key={child.data}>{child.data}</Text>); | ||
} else { | ||
elements.push(child.data); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
return { elements, hasLargeStyle }; | ||
} |