Skip to content

Commit

Permalink
fix: rename shouldResetFocus -> shouldResetFocusRef
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed Jul 19, 2024
1 parent ffea2ab commit ae1c034
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/components/Composer/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function Composer(
ref: ForwardedRef<TextInput>,
) {
const textInput = useRef<AnimatedMarkdownTextInputRef | null>(null);
const {isFocused, shouldResetFocus} = useResetComposerFocus(textInput);
const {isFocused, shouldResetFocusRef} = useResetComposerFocus(textInput);
const textContainsOnlyEmojis = useMemo(() => EmojiUtils.containsOnlyEmojis(value ?? ''), [value]);
const theme = useTheme();
const markdownStyle = useMarkdownStyle(value, !isGroupPolicyReport ? excludeReportMentionStyle : excludeNoStyles);
Expand Down Expand Up @@ -95,7 +95,7 @@ function Composer(
onBlur={(e) => {
if (!isFocused) {
// eslint-disable-next-line react-compiler/react-compiler
shouldResetFocus.current = true; // detect the input is blurred when the page is hidden
shouldResetFocusRef.current = true; // detect the input is blurred when the page is hidden
}
props?.onBlur?.(e);
}}
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/useResetComposerFocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import type {TextInput} from 'react-native';

export default function useResetComposerFocus(inputRef: MutableRefObject<TextInput | null>) {
const isFocused = useIsFocused();
const shouldResetFocus = useRef(false);
const shouldResetFocusRef = useRef(false);

useEffect(() => {
if (!isFocused || !shouldResetFocus.current) {
if (!isFocused || !shouldResetFocusRef.current) {
return;
}
inputRef.current?.focus(); // focus input again
shouldResetFocus.current = false;
shouldResetFocusRef.current = false;
}, [isFocused, inputRef]);

return {isFocused, shouldResetFocus};
return {isFocused, shouldResetFocusRef};
}

0 comments on commit ae1c034

Please sign in to comment.