-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 #37814 from dukenv0307/fix/34307
Handle emoji tooltip and fix regression
- Loading branch information
Showing
16 changed files
with
146 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,7 +102,7 @@ | |
"date-fns-tz": "^2.0.0", | ||
"dom-serializer": "^0.2.2", | ||
"domhandler": "^4.3.0", | ||
"expensify-common": "git+ssh://[email protected]/Expensify/expensify-common.git#615f4a8662cd1abea9fdeee4d04847197c5e36ae", | ||
"expensify-common": "git+ssh://[email protected]/Expensify/expensify-common.git#4e020cfa13ffabde14313c92b341285aeb919f29", | ||
"expo": "^50.0.3", | ||
"expo-av": "~13.10.4", | ||
"expo-image": "1.11.0", | ||
|
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,10 @@ | ||
import Text from '@components/Text'; | ||
import type EmojiWithTooltipProps from './types'; | ||
|
||
function EmojiWithTooltip({emojiCode, style = {}}: EmojiWithTooltipProps) { | ||
return <Text style={style}>{emojiCode}</Text>; | ||
} | ||
|
||
EmojiWithTooltip.displayName = 'EmojiWithTooltip'; | ||
|
||
export default EmojiWithTooltip; |
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,42 @@ | ||
import React, {useCallback} from 'react'; | ||
import {View} from 'react-native'; | ||
import Text from '@components/Text'; | ||
import Tooltip from '@components/Tooltip'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as EmojiUtils from '@libs/EmojiUtils'; | ||
import type EmojiWithTooltipProps from './types'; | ||
|
||
function EmojiWithTooltip({emojiCode, style = {}}: EmojiWithTooltipProps) { | ||
const {preferredLocale} = useLocalize(); | ||
const styles = useThemeStyles(); | ||
const emoji = EmojiUtils.findEmojiByCode(emojiCode); | ||
const emojiName = EmojiUtils.getEmojiName(emoji, preferredLocale); | ||
|
||
const emojiTooltipContent = useCallback( | ||
() => ( | ||
<View style={[styles.alignItemsCenter, styles.ph2]}> | ||
<View style={[styles.flexRow, styles.emojiTooltipWrapper]}> | ||
<Text | ||
key={emojiCode} | ||
style={styles.onlyEmojisText} | ||
> | ||
{emojiCode} | ||
</Text> | ||
</View> | ||
<Text style={[styles.textMicro, styles.fontColorReactionLabel]}>{`:${emojiName}:`}</Text> | ||
</View> | ||
), | ||
[emojiCode, emojiName, styles.alignItemsCenter, styles.ph2, styles.flexRow, styles.emojiTooltipWrapper, styles.fontColorReactionLabel, styles.onlyEmojisText, styles.textMicro], | ||
); | ||
|
||
return ( | ||
<Tooltip renderTooltipContent={emojiTooltipContent}> | ||
<Text style={[style, styles.cursorDefault]}>{emojiCode}</Text> | ||
</Tooltip> | ||
); | ||
} | ||
|
||
EmojiWithTooltip.displayName = 'EmojiWithTooltip'; | ||
|
||
export default EmojiWithTooltip; |
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,8 @@ | ||
import type {StyleProp, TextStyle} from 'react-native'; | ||
|
||
type EmojiWithTooltipProps = { | ||
emojiCode: string; | ||
style?: StyleProp<TextStyle>; | ||
}; | ||
|
||
export default EmojiWithTooltipProps; |
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
19 changes: 19 additions & 0 deletions
19
src/components/HTMLEngineProvider/HTMLRenderers/EmojiRenderer.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,19 @@ | ||
import React from 'react'; | ||
import type {CustomRendererProps, TPhrasing, TText} from 'react-native-render-html'; | ||
import EmojiWithTooltip from '@components/EmojiWithTooltip'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
||
function EmojiRenderer({tnode}: CustomRendererProps<TText | TPhrasing>) { | ||
const styles = useThemeStyles(); | ||
const style = 'islarge' in tnode.attributes ? styles.onlyEmojisText : {}; | ||
return ( | ||
<EmojiWithTooltip | ||
style={[style, styles.cursorDefault]} | ||
emojiCode={'data' in tnode ? tnode.data : ''} | ||
/> | ||
); | ||
} | ||
|
||
EmojiRenderer.displayName = 'EmojiRenderer'; | ||
|
||
export default EmojiRenderer; |
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,11 @@ | ||
import type {TDefaultRendererProps} from 'react-native-render-html'; | ||
import type {TTextOrTPhrasing} from './types'; | ||
|
||
// Create a temporary solution to display when there are emojis in the inline code block | ||
// We can remove this after https://github.com/Expensify/App/issues/14676 is fixed | ||
export default function getCurrentData(defaultRendererProps: TDefaultRendererProps<TTextOrTPhrasing>): string { | ||
if ('data' in defaultRendererProps.tnode) { | ||
return defaultRendererProps.tnode.data; | ||
} | ||
return defaultRendererProps.tnode.children.map((child) => ('data' in child ? child.data : '')).join(''); | ||
} |
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 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
12 changes: 12 additions & 0 deletions
12
src/pages/home/report/comment/shouldRenderAsText/index.native.ts
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,12 @@ | ||
import Str from 'expensify-common/lib/str'; | ||
|
||
/** | ||
* Whether to render the report action as text | ||
*/ | ||
export default function shouldRenderAsText(html: string, text: string): boolean { | ||
// On native, we render emoji as text to prevent the large emoji is cut off when the action is edited. | ||
// More info: https://github.com/Expensify/App/pull/35838#issuecomment-1964839350 | ||
const htmlWithoutLineBreak = Str.replaceAll(html, '<br />', '\n'); | ||
const htmlWithoutEmojiOpenTag = Str.replaceAll(htmlWithoutLineBreak, '<emoji>', ''); | ||
return Str.replaceAll(htmlWithoutEmojiOpenTag, '</emoji>', '') === text; | ||
} |
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,8 @@ | ||
import Str from 'expensify-common/lib/str'; | ||
|
||
/** | ||
* Whether to render the report action as text | ||
*/ | ||
export default function shouldRenderAsText(html: string, text: string): boolean { | ||
return Str.replaceAll(html, '<br />', '\n') === text; | ||
} |
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