-
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.
perf: use explicit composite architecture for RenderHTML component
This allows to avoid the cost of instantiating a new engine for each HTML snippet, see https://git.io/JRcZb fix #4123
- Loading branch information
Showing
9 changed files
with
100 additions
and
71 deletions.
There are no files selected for viewing
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
6 changes: 3 additions & 3 deletions
6
...ponents/RenderHTML/renderHTMLPropTypes.js → ...HTMLEngineProvider/htmlEnginePropTypes.js
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,20 @@ | ||
import React from 'react'; | ||
import BaseHTMLEngineProvider from './BaseHTMLEngineProvider'; | ||
import {defaultProps, propTypes} from './htmlEnginePropTypes'; | ||
import withWindowDimensions from '../withWindowDimensions'; | ||
import canUseTouchScreen from '../../libs/canUseTouchscreen'; | ||
|
||
const HTMLEngineProvider = ({isSmallScreenWidth, debug, children}) => ( | ||
<BaseHTMLEngineProvider | ||
debug={debug} | ||
textSelectable={!canUseTouchScreen() || !isSmallScreenWidth} | ||
> | ||
{children} | ||
</BaseHTMLEngineProvider> | ||
); | ||
|
||
HTMLEngineProvider.displayName = 'HTMLEngineProvider'; | ||
HTMLEngineProvider.propTypes = propTypes; | ||
HTMLEngineProvider.defaultProps = defaultProps; | ||
|
||
export default withWindowDimensions(HTMLEngineProvider); |
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,15 @@ | ||
import React from 'react'; | ||
import BaseHTMLEngineProvider from './BaseHTMLEngineProvider'; | ||
import {propTypes, defaultProps} from './htmlEnginePropTypes'; | ||
|
||
const HTMLEngineProvider = ({debug, children}) => ( | ||
<BaseHTMLEngineProvider debug={debug}> | ||
{children} | ||
</BaseHTMLEngineProvider> | ||
); | ||
|
||
HTMLEngineProvider.displayName = 'HTMLEngineProvider'; | ||
HTMLEngineProvider.propTypes = propTypes; | ||
HTMLEngineProvider.defaultProps = defaultProps; | ||
|
||
export default HTMLEngineProvider; |
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,27 @@ | ||
import React from 'react'; | ||
import {useWindowDimensions} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import {RenderHTMLSource} from 'react-native-render-html'; | ||
|
||
// We are using the explicit composite architecture for performance gains. | ||
// Configuration for RenderHTML is handled in a top-level component providing | ||
// context to RenderHTMLSource components. See https://git.io/JRcZb | ||
// The provider is available at src/components/HTMLEngineProvider/ | ||
const RenderHTML = ({html}) => { | ||
const {width} = useWindowDimensions(); | ||
return ( | ||
<RenderHTMLSource | ||
contentWidth={width * 0.8} | ||
source={{html}} | ||
/> | ||
); | ||
}; | ||
|
||
RenderHTML.displayName = 'RenderHTML'; | ||
RenderHTML.propTypes = { | ||
/** HTML string to render */ | ||
html: PropTypes.string.isRequired, | ||
}; | ||
RenderHTML.defaultProps = {}; | ||
|
||
export default RenderHTML; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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