Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - Chat - Compose box stays in the middle when reduced with a several lines message #50520

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c7e3f5a
fix the bottom line of the composer on composer full size mode change
FitseTLT Oct 9, 2024
26926f0
change listener
FitseTLT Oct 9, 2024
447dc03
set prevHeight to content size height
FitseTLT Oct 9, 2024
1792e20
resolve conflict
FitseTLT Oct 15, 2024
2db9a48
Merge branch 'main' into fix-scroll-problem-on-composer-size-change
FitseTLT Oct 22, 2024
ccb9ca5
resolve conflict
FitseTLT Oct 22, 2024
dca3bcc
scroll to the cursor on composer size change for native
FitseTLT Oct 23, 2024
9a62a08
Merge branch 'main' into fix-scroll-problem-on-composer-size-change
FitseTLT Oct 23, 2024
6c80d07
Merge branch 'main' into fix-scroll-problem-on-composer-size-change
FitseTLT Oct 27, 2024
54402d1
comment out the set selection code
FitseTLT Oct 28, 2024
673c98c
Merge branch 'main' into fix-scroll-problem-on-composer-size-change
FitseTLT Oct 28, 2024
4e65339
revert
FitseTLT Oct 28, 2024
aa8156d
only scroll to cursor on changing to composer to small size
FitseTLT Oct 28, 2024
40c5968
Merge branch 'main' into fix-scroll-problem-on-composer-size-change
FitseTLT Oct 28, 2024
913563b
fix tests
FitseTLT Oct 28, 2024
ff96f95
Merge branch 'main' into fix-scroll-problem-on-composer-size-change
FitseTLT Oct 31, 2024
d8076c1
applied small delay to setSelection
FitseTLT Nov 1, 2024
295079f
reduced the delay
FitseTLT Nov 1, 2024
e873e25
Merge branch 'main' into fix-scroll-problem-on-composer-size-change
FitseTLT Nov 11, 2024
4c1045a
Merge branch 'main' into fix-scroll-problem-on-composer-size-change
FitseTLT Nov 15, 2024
e226acf
Merge branch 'main' into fix-scroll-problem-on-composer-size-change
FitseTLT Nov 21, 2024
624ab5f
Merge branch 'main' into fix-scroll-problem-on-composer-size-change
FitseTLT Nov 21, 2024
1c3d327
Merge branch 'main' into fix-scroll-problem-on-composer-size-change
FitseTLT Nov 26, 2024
d80be2a
added comment
FitseTLT Nov 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/components/Composer/implementation/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ function Composer(
inputCallbackRef(autoFocus ? textInput.current : null);
}, [autoFocus, inputCallbackRef, autoFocusInputRef]);

useEffect(() => {
if (!textInput.current || !textInput.current.setSelection || !selection || isComposerFullSize) {
return;
}

// We are setting selection twice to trigger a scroll to the cursor on toggling to smaller composer size.
const timeoutID = setTimeout(() => {
textInput.current?.setSelection((selection.start || 1) - 1, selection.start);
textInput.current?.setSelection(selection.start, selection.start);
}, 0);
FitseTLT marked this conversation as resolved.
Show resolved Hide resolved

return () => clearTimeout(timeoutID);

// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [isComposerFullSize]);
FitseTLT marked this conversation as resolved.
Show resolved Hide resolved

/**
* Set the TextInput Ref
* @param {Element} el
Expand Down
6 changes: 4 additions & 2 deletions src/components/Composer/implementation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function Composer(
const [isRendered, setIsRendered] = useState(false);
const isScrollBarVisible = useIsScrollBarVisible(textInput, value ?? '');
const [prevScroll, setPrevScroll] = useState<number | undefined>();
const [prevHeight, setPrevHeight] = useState<number | undefined>();
const isReportFlatListScrolling = useRef(false);

useEffect(() => {
Expand Down Expand Up @@ -243,11 +244,11 @@ function Composer(
}, []);

useEffect(() => {
if (!textInput.current || prevScroll === undefined) {
if (!textInput.current || prevScroll === undefined || prevHeight === undefined) {
return;
}
// eslint-disable-next-line react-compiler/react-compiler
textInput.current.scrollTop = prevScroll;
textInput.current.scrollTop = prevScroll + prevHeight - textInput.current.clientHeight;
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [isComposerFullSize]);

Expand Down Expand Up @@ -353,6 +354,7 @@ function Composer(
{...props}
onSelectionChange={addCursorPositionToSelectionChange}
onContentSizeChange={(e) => {
setPrevHeight(e.nativeEvent.contentSize.height);
updateIsFullComposerAvailable({maxLines, isComposerFullSize, isDisabled, setIsFullComposerAvailable}, e, styles);
}}
disabled={isDisabled}
Expand Down
Loading