-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Prevent format emoji On Submitted text #40617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
stitesExpensify
merged 32 commits into
Expensify:main
from
wildan-m:wildan/fix-14676-prevent-format-emoji
Apr 30, 2024
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9d7ead0
Prevent emoji from being formatted
wildan-m 567b1de
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m aaff72e
Add dInlineFlex
wildan-m 6cb3e5b
comment emoji style in useMarkdownStyle
wildan-m 4b496f1
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m 521bf2d
Add textDecorationLine none to hide striketrough in android
wildan-m 287cb7e
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m 06e0038
Merge branch 'wildan/fix-14676-prevent-format-emoji' of https://githu…
wildan-m dcccca4
Move renderEmojisAsTextComponents to a new file
wildan-m 4fe6841
Fix lint and prettier
wildan-m 6b0d2d6
render emojis as EmojiWithTooltip instead of Text to keep emoji tooltip
wildan-m f55d6a0
Override EmojiWithTooltip textStyles with code textStyles
wildan-m bcafecd
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m f59918e
Fix Type
wildan-m dd86bd9
create platform specific emojiDefaultStyles
wildan-m 1807fa2
change emojiDefault to emojiDefaultStyles
wildan-m 2e7c148
restore getCurrentData
wildan-m 1a05d04
revert inlinecodeblock native change
wildan-m 964a7a9
apply default style to emoji inside wrappedText
wildan-m a7b5c3e
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m a7a1f12
use existing containsOnlyEmojis
wildan-m f396366
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m e74c233
remove unnecessary code
wildan-m e0d25a2
run prettier
wildan-m e06746a
fix lint error
wildan-m be66270
fix containsEmoji function
wildan-m 2c0be52
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m 5448e1a
refactor, add comment
wildan-m 46c1230
fix lint
wildan-m 68c4e7d
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m 4e651a8
move getCurrentData to native specific file
wildan-m 2fb2a49
Add comment to getCurrentData
wildan-m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||
|
wildan-m marked this conversation as resolved.
|
||
| 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 hidden or 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 hidden or 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 hidden or 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, | ||
|
wildan-m marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| export default emojiDefaultStyles; | ||
This file contains hidden or 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; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.