Skip to content

Commit

Permalink
[TS migration] Code improvements and variable cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ruben-rebelo committed Jan 10, 2024
1 parent c8813dc commit baa1577
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/components/HTMLEngineProvider/BaseHTMLEngineProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import convertToLTR from '@libs/convertToLTR';
import FontUtils from '@styles/utils/FontUtils';
import * as HTMLEngineUtils from './htmlEngineUtils';
import htmlRenderers from './HTMLRenderers';
import type {HTMLEngineProviderProps} from './types';
import type ChildrenProps from '@src/types/utils/ChildrenProps';

type BaseHTMLEngineProviderProps = HTMLEngineProviderProps & {
type BaseHTMLEngineProviderProps = ChildrenProps & {
/** Whether text elements should be selectable */
textSelectable?: boolean;

Expand Down
7 changes: 4 additions & 3 deletions src/components/HTMLEngineProvider/htmlEngineUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {TNode} from 'react-native-render-html';
import type {Predicate} from './types';

type Predicate = (node: TNode) => boolean;

const MAX_IMG_DIMENSIONS = 512;

Expand Down Expand Up @@ -47,15 +48,15 @@ function isChildOfNode(tnode: TNode, predicate: Predicate): boolean {
* Finding node with name 'comment' flags that we are rendering a comment.
*/
function isChildOfComment(tnode: TNode): boolean {
return isChildOfNode(tnode, (node) => node.domNode?.name !== undefined && isCommentTag(node.domNode?.name));
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.
*/
function isChildOfH1(tnode: TNode): boolean {
return isChildOfNode(tnode, (node) => node.domNode?.name !== null && node.domNode?.name.toLowerCase() === 'h1');
return isChildOfNode(tnode, (node) => node.domNode?.name !== undefined && node.domNode.name.toLowerCase() === 'h1');
}

export {computeEmbeddedMaxWidth, isChildOfComment, isCommentTag, isChildOfH1};
4 changes: 2 additions & 2 deletions src/components/HTMLEngineProvider/index.native.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
import BaseHTMLEngineProvider from './BaseHTMLEngineProvider';
import type {HTMLEngineProviderProps} from './types';

function HTMLEngineProvider({children}: HTMLEngineProviderProps) {
function HTMLEngineProvider({children}: ChildrenProps) {
return <BaseHTMLEngineProvider enableExperimentalBRCollapsing>{children}</BaseHTMLEngineProvider>;
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/HTMLEngineProvider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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';
import type {HTMLEngineProviderProps} from './types';

function HTMLEngineProvider({children = null}: HTMLEngineProviderProps) {
function HTMLEngineProvider({children}: ChildrenProps) {
const {isSmallScreenWidth} = useWindowDimensions();

return <BaseHTMLEngineProvider textSelectable={!DeviceCapabilities.canUseTouchScreen() || !isSmallScreenWidth}>{children}</BaseHTMLEngineProvider>;
Expand Down
8 changes: 0 additions & 8 deletions src/components/HTMLEngineProvider/types.ts

This file was deleted.

0 comments on commit baa1577

Please sign in to comment.