Skip to content

Commit

Permalink
move input styles to separate variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Feb 7, 2024
1 parent e613dcd commit 3541370
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(

// Empty placeholder would collapse the div, so we need to use zero-width space to prevent it
const heightSafePlaceholder = useMemo(() => getPlaceholderValue(placeholder), [placeholder]);

const parseText = useCallback(
(target: HTMLDivElement, text: string | null, customMarkdownStyles: MarkdownStyle, cursorPosition: number | null = null, shouldAddToHistory = true) => {
if (text === null) {
Expand Down Expand Up @@ -197,6 +198,19 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
return newMarkdownStyle;
}, [markdownStyle]);

const inputStyles = useMemo(
() =>
StyleSheet.flatten([
styles.defaultInputStyles,
flattenedStyle && {
caretColor: (flattenedStyle as TextStyle).color || 'black',
},
disabled && styles.disabledInputStyles,
createReactDOMStyle(preprocessStyle(flattenedStyle)),
]) as CSSProperties,
[flattenedStyle, disabled],
);

const undo = useCallback(
(target: HTMLDivElement) => {
if (!history.current) return '';
Expand Down Expand Up @@ -461,16 +475,7 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
<div
ref={setRef}
contentEditable={!disabled}
style={
StyleSheet.flatten([
styles.defaultInputStyles,
flattenedStyle && {
caretColor: (flattenedStyle as TextStyle).color || 'black',
},
disabled && styles.disabledInputStyles,
createReactDOMStyle(preprocessStyle(flattenedStyle)),
]) as CSSProperties
}
style={inputStyles}
role={accessibilityRole || 'textbox'}
aria-label={accessibilityLabel}
aria-labelledby={`${accessibilityLabelledBy}`}
Expand Down

0 comments on commit 3541370

Please sign in to comment.