Skip to content

Commit

Permalink
Merge pull request Expensify#35837 from software-mansion-labs/@Skalak…
Browse files Browse the repository at this point in the history
…id/live-markdown-preview-web

Live Markdown Preview for web
  • Loading branch information
thienlnam authored Feb 7, 2024
2 parents f8988df + 3b933ad commit 6135313
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"dependencies": {
"@dotlottie/react-player": "^1.6.3",
"@expensify/react-native-live-markdown": "git+ssh://[email protected]/Expensify/react-native-live-markdown.git#2ed4240336e50abb4a7fa9ff6a3c180f8bc9ce5b",
"@expensify/react-native-live-markdown": "git+ssh://[email protected]/Expensify/react-native-live-markdown.git#77f85a5265043c6100f1fa65edd58901724faf08",
"@expo/metro-runtime": "~3.1.1",
"@formatjs/intl-datetimeformat": "^6.10.0",
"@formatjs/intl-getcanonicallocales": "^2.2.0",
Expand Down
11 changes: 7 additions & 4 deletions src/components/Composer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {MarkdownTextInput} from '@expensify/react-native-live-markdown';
import type {BaseSyntheticEvent, ForwardedRef} from 'react';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {flushSync} from 'react-dom';
// eslint-disable-next-line no-restricted-imports
import type {DimensionValue, NativeSyntheticEvent, Text as RNText, TextInput, TextInputKeyPressEventData, TextInputSelectionChangeEventData} from 'react-native';
import {StyleSheet, View} from 'react-native';
import type {AnimatedTextInputRef} from '@components/RNTextInput';
import RNTextInput from '@components/RNTextInput';
import Text from '@components/Text';
import useHtmlPaste from '@hooks/useHtmlPaste';
import useIsScrollBarVisible from '@hooks/useIsScrollBarVisible';
import useMarkdownStyle from '@hooks/useMarkdownStyle';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -80,6 +81,7 @@ function Composer(
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const markdownStyle = useMarkdownStyle();
const {windowWidth} = useWindowDimensions();
const textRef = useRef<HTMLElement & RNText>(null);
const textInput = useRef<AnimatedTextInputRef | null>(null);
Expand Down Expand Up @@ -168,7 +170,7 @@ function Composer(

// To make sure the composer does not capture paste events from other inputs, we check where the event originated
// If it did originate in another input, we return early to prevent the composer from handling the paste
const isTargetInput = eventTarget?.nodeName === 'INPUT' || eventTarget?.nodeName === 'TEXTAREA' || eventTarget?.contentEditable === 'true';
const isTargetInput = ['INPUT', 'TEXTAREA', 'SPAN'].includes(eventTarget?.nodeName ?? '') || eventTarget?.contentEditable === 'true';
if (isTargetInput) {
return true;
}
Expand Down Expand Up @@ -327,13 +329,14 @@ function Composer(

return (
<>
<RNTextInput
<MarkdownTextInput
autoComplete="off"
autoCorrect={!Browser.isMobileSafari()}
placeholderTextColor={theme.placeholderText}
ref={(el) => (textInput.current = el)}
ref={(el) => (textInput.current = el as AnimatedTextInputRef)}
selection={selection}
style={inputStyleMemo}
markdownStyle={markdownStyle}
value={value}
defaultValue={defaultValue}
autoFocus={autoFocus}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ function ComposerWithSuggestions({
}

// if we're typing on another input/text area, do not focus
if (['INPUT', 'TEXTAREA'].includes(e.target.nodeName)) {
if (['INPUT', 'TEXTAREA', 'DIV'].includes(e.target.nodeName)) {
return;
}

Expand Down

0 comments on commit 6135313

Please sign in to comment.