-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[TS migration] Migrate HTMLEngineProvider component #33643
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
d487449
4ba8eb2
71ee3aa
aebd554
5b9473f
c8813dc
baa1577
f75c0fa
7c3cfd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| import lodashGet from 'lodash/get'; | ||
| import type {TNode} from 'react-native-render-html'; | ||
|
|
||
| type Predicate = (node: TNode) => boolean; | ||
|
|
||
| const MAX_IMG_DIMENSIONS = 512; | ||
|
|
||
|
|
@@ -7,12 +9,12 @@ const MAX_IMG_DIMENSIONS = 512; | |
| * is used by the HTML component in the default renderer for img tags to scale | ||
| * down images that would otherwise overflow horizontally. | ||
| * | ||
| * @param {string} tagName - The name of the tag for which max width should be constrained. | ||
| * @param {number} contentWidth - The content width provided to the HTML | ||
| * @param contentWidth - The content width provided to the HTML | ||
| * component. | ||
| * @returns {number} The minimum between contentWidth and MAX_IMG_DIMENSIONS | ||
| * @param tagName - The name of the tag for which max width should be constrained. | ||
| * @returns The minimum between contentWidth and MAX_IMG_DIMENSIONS | ||
| */ | ||
| function computeEmbeddedMaxWidth(tagName, contentWidth) { | ||
| function computeEmbeddedMaxWidth(contentWidth: number, tagName: string): number { | ||
|
Comment on lines
-15
to
+17
Member
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. This is interesting were we doing something wrong the whole time? Isn't this param swapping a breaking change?
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. This is something that was actually wrong the whole time, if you take a look at function computeEmbeddedMaxWidth from react-native-render-html the parameters order is the one that we have provided now. |
||
| if (tagName === 'img') { | ||
| return Math.min(MAX_IMG_DIMENSIONS, contentWidth); | ||
| } | ||
|
|
@@ -22,21 +24,15 @@ function computeEmbeddedMaxWidth(tagName, contentWidth) { | |
| /** | ||
| * Check if tagName is equal to any of our custom tags wrapping chat comments. | ||
| * | ||
| * @param {string} tagName | ||
| * @returns {Boolean} | ||
| */ | ||
| function isCommentTag(tagName) { | ||
| function isCommentTag(tagName: string): boolean { | ||
| return tagName === 'email-comment' || tagName === 'comment'; | ||
| } | ||
|
|
||
| /** | ||
| * Check if there is an ancestor node for which the predicate returns true. | ||
| * | ||
| * @param {TNode} tnode | ||
| * @param {Function} predicate | ||
| * @returns {Boolean} | ||
| */ | ||
| function isChildOfNode(tnode, predicate) { | ||
| function isChildOfNode(tnode: TNode, predicate: Predicate): boolean { | ||
| let currentNode = tnode.parent; | ||
| while (currentNode) { | ||
| if (predicate(currentNode)) { | ||
|
|
@@ -50,21 +46,17 @@ function isChildOfNode(tnode, predicate) { | |
| /** | ||
| * Check if there is an ancestor node with name 'comment'. | ||
| * Finding node with name 'comment' flags that we are rendering a comment. | ||
| * @param {TNode} tnode | ||
| * @returns {Boolean} | ||
| */ | ||
| function isChildOfComment(tnode) { | ||
| return isChildOfNode(tnode, (node) => isCommentTag(lodashGet(node, 'domNode.name', ''))); | ||
| function isChildOfComment(tnode: TNode): boolean { | ||
| return isChildOfNode(tnode, (node) => node.domNode?.name !== undefined && isCommentTag(node.domNode.name)); | ||
| } | ||
|
|
||
| /** | ||
| * Check if there is an ancestor node with the name 'h1'. | ||
| * Finding a node with the name 'h1' flags that we are rendering inside an h1 element. | ||
| * @param {TNode} tnode | ||
| * @returns {Boolean} | ||
| */ | ||
| function isChildOfH1(tnode) { | ||
| return isChildOfNode(tnode, (node) => lodashGet(node, 'domNode.name', '').toLowerCase() === 'h1'); | ||
| function isChildOfH1(tnode: TNode): boolean { | ||
| return isChildOfNode(tnode, (node) => node.domNode?.name !== undefined && node.domNode.name.toLowerCase() === 'h1'); | ||
| } | ||
|
|
||
| export {computeEmbeddedMaxWidth, isChildOfComment, isCommentTag, isChildOfH1}; | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import React from 'react'; | ||
| import type ChildrenProps from '@src/types/utils/ChildrenProps'; | ||
| import BaseHTMLEngineProvider from './BaseHTMLEngineProvider'; | ||
|
|
||
| function HTMLEngineProvider({children}: ChildrenProps) { | ||
| return <BaseHTMLEngineProvider enableExperimentalBRCollapsing>{children}</BaseHTMLEngineProvider>; | ||
| } | ||
|
|
||
| HTMLEngineProvider.displayName = 'HTMLEngineProvider'; | ||
|
|
||
| export default HTMLEngineProvider; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import React from 'react'; | ||
| import useWindowDimensions from '@hooks/useWindowDimensions'; | ||
| import * as DeviceCapabilities from '@libs/DeviceCapabilities'; | ||
| import type ChildrenProps from '@src/types/utils/ChildrenProps'; | ||
| import BaseHTMLEngineProvider from './BaseHTMLEngineProvider'; | ||
|
|
||
| function HTMLEngineProvider({children}: ChildrenProps) { | ||
| const {isSmallScreenWidth} = useWindowDimensions(); | ||
|
|
||
| return <BaseHTMLEngineProvider textSelectable={!DeviceCapabilities.canUseTouchScreen() || !isSmallScreenWidth}>{children}</BaseHTMLEngineProvider>; | ||
| } | ||
|
|
||
| HTMLEngineProvider.displayName = 'HTMLEngineProvider'; | ||
|
|
||
| export default HTMLEngineProvider; |
Uh oh!
There was an error while loading. Please reload this page.