-
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.
Merge pull request #40617 from wildan-m/wildan/fix-14676-prevent-form…
…at-emoji Prevent format emoji On Submitted text
- Loading branch information
Showing
9 changed files
with
115 additions
and
20 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,75 @@ | ||
import React from 'react'; | ||
import {StyleSheet} from 'react-native'; | ||
import type {StyleProp, TextStyle} from 'react-native'; | ||
import type {TDefaultRendererProps} from 'react-native-render-html'; | ||
import EmojiWithTooltip from '@components/EmojiWithTooltip'; | ||
import Text from '@components/Text'; | ||
import getCurrentData from './getCurrentData'; | ||
import type InlineCodeBlockProps from './types'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import type {ThemeStyles} from '@styles/index'; | ||
import type {TTextOrTPhrasing} from './types'; | ||
import type InlineCodeBlockProps from './types'; | ||
|
||
/** | ||
* This function is used to render elements based on the provided defaultRendererProps and styles. | ||
* It iterates over the children of the tnode object in defaultRendererProps, and for each child, | ||
* it checks if the child's tagName is 'emoji'. If it is, it creates an EmojiWithTooltip component | ||
* with the appropriate styles and adds it to the elements array. If it's not, it adds the child's | ||
* 'data' property to the elements array. The function then returns the elements array. | ||
* | ||
* @param defaultRendererProps - The default renderer props. | ||
* @param textStyles - The text styles. | ||
* @param styles - The theme styles. | ||
* @returns The array of elements to be rendered. | ||
*/ | ||
function renderElements(defaultRendererProps: TDefaultRendererProps<TTextOrTPhrasing>, textStyles: StyleProp<TextStyle>, styles: ThemeStyles) { | ||
const elements: Array<string | React.JSX.Element> = []; | ||
|
||
if ('data' in defaultRendererProps.tnode) { | ||
elements.push(defaultRendererProps.tnode.data); | ||
return elements; | ||
} | ||
|
||
if (!defaultRendererProps.tnode.children) { | ||
return elements; | ||
} | ||
|
||
defaultRendererProps.tnode.children.forEach((child) => { | ||
if (!('data' in child)) { | ||
return; | ||
} | ||
|
||
if (child.tagName === 'emoji') { | ||
elements.push( | ||
<EmojiWithTooltip | ||
style={[textStyles, styles.cursorDefault, styles.emojiDefaultStyles]} | ||
key={child.data} | ||
emojiCode={child.data} | ||
/>, | ||
); | ||
} else { | ||
elements.push(child.data); | ||
} | ||
}); | ||
|
||
return elements; | ||
} | ||
|
||
function InlineCodeBlock<TComponent extends TTextOrTPhrasing>({TDefaultRenderer, textStyle, defaultRendererProps, boxModelStyle}: InlineCodeBlockProps<TComponent>) { | ||
const styles = useThemeStyles(); | ||
const flattenTextStyle = StyleSheet.flatten(textStyle); | ||
const {textDecorationLine, ...textStyles} = flattenTextStyle; | ||
|
||
const data = getCurrentData(defaultRendererProps); | ||
const elements = renderElements(defaultRendererProps, textStyles, styles); | ||
|
||
return ( | ||
<TDefaultRenderer | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...defaultRendererProps} | ||
> | ||
<Text style={[boxModelStyle, textStyles]}>{data}</Text> | ||
<Text style={[boxModelStyle, textStyles]}>{elements}</Text> | ||
</TDefaultRenderer> | ||
); | ||
} | ||
|
||
InlineCodeBlock.displayName = 'InlineCodeBlock'; | ||
|
||
export default InlineCodeBlock; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type EmojiDefaultStyles from './types'; | ||
|
||
const emojiDefaultStyles: EmojiDefaultStyles = { | ||
fontStyle: 'normal', | ||
fontWeight: 'normal', | ||
textDecorationLine: 'none', | ||
}; | ||
|
||
export default emojiDefaultStyles; |
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,11 @@ | ||
// eslint-disable-next-line no-restricted-imports | ||
import display from '@styles/utils/display'; | ||
import type EmojiDefaultStyles from './types'; | ||
|
||
const emojiDefaultStyles: EmojiDefaultStyles = { | ||
fontStyle: 'normal', | ||
fontWeight: 'normal', | ||
...display.dInlineFlex, | ||
}; | ||
|
||
export default emojiDefaultStyles; |
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,5 @@ | ||
import type {TextStyle} from 'react-native'; | ||
|
||
type EmojiDefaultStyles = TextStyle; | ||
|
||
export default EmojiDefaultStyles; |