-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[No QA] Cleanup implementation of HTMLEngineProvider #6885
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
Changes from all commits
2c0363b
8ba2490
cb6f543
d0f3400
320a543
b7089c2
8dfa15e
503ec01
339c8be
7de067d
a0f80e5
c38d79e
f6fbacd
5d75e2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import React from 'react'; | ||
| import {Linking} from 'react-native'; | ||
| import { | ||
| TNodeChildrenRenderer, | ||
| } from 'react-native-render-html'; | ||
| import lodashGet from 'lodash/get'; | ||
| import htmlRendererPropTypes from './htmlRendererPropTypes'; | ||
| import * as HTMLEngineUtils from '../htmlEngineUtils'; | ||
| import Text from '../../Text'; | ||
| import CONST from '../../../CONST'; | ||
| import styles from '../../../styles/styles'; | ||
| import Navigation from '../../../libs/Navigation/Navigation'; | ||
| import AnchorForCommentsOnly from '../../AnchorForCommentsOnly'; | ||
|
|
||
| const AnchorRenderer = (props) => { | ||
| const htmlAttribs = props.tnode.attributes; | ||
|
|
||
| // An auth token is needed to download Expensify chat attachments | ||
| const isAttachment = Boolean(htmlAttribs['data-expensify-source']); | ||
| const fileName = lodashGet(props.tnode, 'domNode.children[0].data', ''); | ||
| const parentStyle = lodashGet(props.tnode, 'parent.styles.nativeTextRet', {}); | ||
| const attrHref = htmlAttribs.href || ''; | ||
| const internalExpensifyPath = (attrHref.startsWith(CONST.NEW_EXPENSIFY_URL) && attrHref.replace(CONST.NEW_EXPENSIFY_URL, '')) | ||
| || (attrHref.startsWith(CONST.STAGING_NEW_EXPENSIFY_URL) && attrHref.replace(CONST.STAGING_NEW_EXPENSIFY_URL, '')); | ||
|
|
||
| // If we are handling a New Expensify link then we will assume this should be opened by the app internally. This ensures that the links are opened internally via react-navigation | ||
| // instead of in a new tab or with a page refresh (which is the default behavior of an anchor tag) | ||
| if (internalExpensifyPath) { | ||
| return ( | ||
| <Text | ||
| style={styles.link} | ||
| onPress={() => Navigation.navigate(internalExpensifyPath)} | ||
| > | ||
| <TNodeChildrenRenderer tnode={props.tnode} /> | ||
| </Text> | ||
| ); | ||
| } | ||
|
|
||
| if (!HTMLEngineUtils.isInsideComment(props.tnode)) { | ||
| // This is not a comment from a chat, the AnchorForCommentsOnly uses a Pressable to create a context menu on right click. | ||
| // We don't have this behaviour in other links in NewDot | ||
| // TODO: We should use TextLink, but I'm leaving it as Text for now because TextLink breaks the alignment in Android. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coming from this issue #80349 we should use TextLink instead of Text. I couldn't reproduce any
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really old PR, totally possible the alignment issue I described doesn't happen anymore. I'd say update it to use TextLink |
||
| return ( | ||
| <Text | ||
| style={styles.link} | ||
| onPress={() => Linking.openURL(attrHref)} | ||
| > | ||
| <TNodeChildrenRenderer tnode={props.tnode} /> | ||
| </Text> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <AnchorForCommentsOnly | ||
| href={attrHref} | ||
| isAuthTokenRequired={isAttachment} | ||
|
|
||
| // Unless otherwise specified open all links in | ||
| // a new window. On Desktop this means that we will | ||
| // skip the default Save As... download prompt | ||
| // and defer to whatever browser the user has. | ||
| // eslint-disable-next-line react/jsx-props-no-multi-spaces | ||
| target={htmlAttribs.target || '_blank'} | ||
| rel={htmlAttribs.rel || 'noopener noreferrer'} | ||
| style={{...props.style, ...parentStyle}} | ||
| key={props.key} | ||
| fileName={fileName} | ||
| > | ||
| <TNodeChildrenRenderer tnode={props.tnode} /> | ||
| </AnchorForCommentsOnly> | ||
| ); | ||
| }; | ||
|
|
||
| AnchorRenderer.propTypes = htmlRendererPropTypes; | ||
| AnchorRenderer.displayName = 'AnchorRenderer'; | ||
|
|
||
| export default AnchorRenderer; | ||
Uh oh!
There was an error while loading. Please reload this page.