-
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 #35838 from dukenv0307/fix/34307
Handle emoji tooltip
- Loading branch information
Showing
13 changed files
with
120 additions
and
13 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 |
---|---|---|
|
@@ -101,7 +101,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#a8ed0f8e1be3a1e09016e07a74cfd13c85bbc167", | ||
"expensify-common": "git+ssh://[email protected]/Expensify/expensify-common.git#45d3b61bb38b4f9a19ddf573ce1e212369b242db", | ||
"expo": "^50.0.3", | ||
"expo-av": "~13.10.4", | ||
"expo-image": "1.10.1", | ||
|
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,40 @@ | ||
import React, {useCallback} from 'react'; | ||
import {View} from 'react-native'; | ||
import Text from '@components/Text'; | ||
import Tooltip from '@components/Tooltip'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as EmojiUtils from '@libs/EmojiUtils'; | ||
import type EmojiWithTooltipProps from './types'; | ||
|
||
function EmojiWithTooltip({emojiCode, style = {}}: EmojiWithTooltipProps) { | ||
const styles = useThemeStyles(); | ||
const emoji = EmojiUtils.findEmojiByCode(emojiCode); | ||
const emojiName = EmojiUtils.getEmojiName(emoji); | ||
|
||
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
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