diff --git a/src/MarkdownTextInput.web.tsx b/src/MarkdownTextInput.web.tsx index 29d11d3a..31f7a1c5 100644 --- a/src/MarkdownTextInput.web.tsx +++ b/src/MarkdownTextInput.web.tsx @@ -70,8 +70,8 @@ type Selection = { }; type Dimensions = { - height: number | null; - width: number | null; + width: number; + height: number; }; let focusTimeout: NodeJS.Timeout | null = null; @@ -171,7 +171,7 @@ const MarkdownTextInput = React.forwardRef( const contentSelection = useRef(null); const className = `react-native-live-markdown-input-${multiline ? 'multiline' : 'singleline'}`; const history = useRef(); - const dimensions = React.useRef({height: null, width: null}); + const dimensions = React.useRef(null); if (!history.current) { history.current = new InputHistory(100); @@ -311,19 +311,15 @@ const MarkdownTextInput = React.forwardRef( } const hostNode = (divRef.current.firstChild as HTMLElement) ?? divRef.current; - const newHeight = hostNode.offsetHeight; const newWidth = hostNode.offsetWidth; + const newHeight = hostNode.offsetHeight; - if (newHeight !== dimensions.current.height || newWidth !== dimensions.current.width) { - dimensions.current.height = newHeight; - dimensions.current.width = newWidth; + if (newHeight !== dimensions.current?.height || newWidth !== dimensions.current.width) { + dimensions.current = {height: newHeight, width: newWidth}; onContentSizeChange({ nativeEvent: { - contentSize: { - height: dimensions.current.height, - width: dimensions.current.width, - }, + contentSize: dimensions.current, }, } as NativeSyntheticEvent); }