From e1eda47c1210b50e94f9334918c0aab14273ec3a Mon Sep 17 00:00:00 2001 From: Thomas Cheung Date: Wed, 8 Jan 2025 22:36:47 +0800 Subject: [PATCH] Drop use of legacy defaultProps --- autoHeightWebView/index.js | 42 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/autoHeightWebView/index.js b/autoHeightWebView/index.js index 3d0dc75..d274804 100644 --- a/autoHeightWebView/index.js +++ b/autoHeightWebView/index.js @@ -17,13 +17,31 @@ import { const AutoHeightWebView = React.memo( forwardRef((props, ref) => { + const defaultProps = { + showsVerticalScrollIndicator: false, + showsHorizontalScrollIndicator: false, + originWhitelist: ['*'], + }; + + Platform.OS === 'android' && + Object.assign(defaultProps, { + scalesPageToFit: false, + }); + + Platform.OS === 'ios' && + Object.assign(defaultProps, { + viewportContent: 'width=device-width', + }); + + const fullProps = Object.assign(defaultProps, props); + const { style, onMessage, onSizeUpdated, scrollEnabledWithZoomedin, scrollEnabled, - } = props; + } = fullProps; const [size, setSize] = useState({ height: style && style.height ? style.height : 0, @@ -62,7 +80,7 @@ const AutoHeightWebView = React.memo( ? scrollable : scrollEnabled; - const {currentSource, script} = reduceData(props); + const {currentSource, script} = reduceData(fullProps); const {width, height} = size; useEffect(() => { @@ -74,7 +92,7 @@ const AutoHeightWebView = React.memo( }, [width, height, onSizeUpdated]); return React.createElement(WebView, { - ...props, + ...fullProps, ref, onMessage: handleMessage, style: [ @@ -114,24 +132,6 @@ AutoHeightWebView.propTypes = { source: PropTypes.object, }; -let defaultProps = { - showsVerticalScrollIndicator: false, - showsHorizontalScrollIndicator: false, - originWhitelist: ['*'], -}; - -Platform.OS === 'android' && - Object.assign(defaultProps, { - scalesPageToFit: false, - }); - -Platform.OS === 'ios' && - Object.assign(defaultProps, { - viewportContent: 'width=device-width', - }); - -AutoHeightWebView.defaultProps = defaultProps; - const styles = StyleSheet.create({ webView: { backgroundColor: 'transparent',