-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
reset tooltip position on scroll #56209
Merged
MonilBhavsar
merged 17 commits into
Expensify:main
from
mohit6789:54924-scrolling-tooltip-issue
Mar 7, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a6b5f75
reset tooltip position on scroll
mohit6789 e04e6da
Refactor
mohit6789 b5957f6
Fix conflict issues
mohit6789 8aa3e13
Fix conflict issues
mohit6789 66a337f
Fix merge conflict
mohit6789 9591074
Fix eslint issues
mohit6789 d694671
Fix eslint issues
mohit6789 ae23518
Fix eslint issues
mohit6789 8dd063b
Merge remote-tracking branch 'origin/main' into 54924-scrolling-toolt…
mohit6789 61008a6
Review comment fix
mohit6789 97ba896
Fix eslint
mohit6789 039ff0e
Fix eslint
mohit6789 008d4f3
Review comment fix
mohit6789 0aa4535
Review comment fix
mohit6789 14cfc5a
Fix review comment
mohit6789 51ce273
Fix review comment
mohit6789 d384480
Fix review comment
mohit6789 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {useCallback, useEffect, useRef} from 'react'; | ||
import {DeviceEventEmitter} from 'react-native'; | ||
import CONST from '@src/CONST'; | ||
|
||
/** | ||
* This hook tracks scroll events and emits a "scrolling" event when scrolling starts and ends. | ||
*/ | ||
const useScrollEventEmitter = () => { | ||
const isScrollingRef = useRef<boolean>(false); | ||
const timeoutRef = useRef<NodeJS.Timeout | null>(null); | ||
|
||
const triggerScrollEvent = useCallback(() => { | ||
const emitScrolling = (isScrolling: boolean) => { | ||
DeviceEventEmitter.emit(CONST.EVENTS.SCROLLING, { | ||
isScrolling, | ||
}); | ||
}; | ||
|
||
// Start emitting the scrolling event when the scroll begins | ||
if (!isScrollingRef.current) { | ||
emitScrolling(true); | ||
isScrollingRef.current = true; | ||
} | ||
|
||
// End the scroll and emit after a brief timeout to detect the end of scrolling | ||
if (timeoutRef.current) { | ||
clearTimeout(timeoutRef.current); | ||
} | ||
|
||
timeoutRef.current = setTimeout(() => { | ||
emitScrolling(false); | ||
isScrollingRef.current = false; | ||
}, 250); | ||
}, []); | ||
|
||
// Cleanup timeout on unmount | ||
useEffect(() => { | ||
return () => { | ||
if (!timeoutRef.current) { | ||
return; | ||
} | ||
clearTimeout(timeoutRef.current); | ||
}; | ||
}, []); | ||
|
||
return triggerScrollEvent; | ||
}; | ||
|
||
export default useScrollEventEmitter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, we only display 1 educational tooltip at a time. Is it easier if we can reuse the existing scrolling event here
App/src/components/InvertedFlatList/index.tsx
Lines 33 to 48 in 0856182
And we also introduce additional prop to EducationalTooltip (i.e shouldHideOnScroll). Then we check if it's displayed and shouldHideOnScroll, we will hide/display tooltip. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need show/hide tooltip in scrolling for SearchPage as well so I have created new hook. And in future we need to add more we can reuse same hook. So as per me current implementation can be reused in other places as well. Let me know if you have any other opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this approach:
SelectionList
.LHNOptionsList
, we probably forgot to remove this scroll event emitter as well.The new hook is a good idea, I like it. It helps reuse. But if we can also have a way to avoid above concerns, that should be great. Any thoughts? Something like put this new hook into
SelectionList
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hoangzinh I did not understand what you are trying to say. Can you please provide code snippet about your thoughts?
What I understand is, we need to call triggerScrollEvent() whenever scrolling happened, and also this is not limited to SelectionList right? We can have different types of wrapper which can scroll, so I am not sure if we can make changes in one places and it will be applied to all the places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
LHNOptionsList
we usedFlashList
component while inSearch
we useSelectionListWithModal
which internally useSelectionList
so I think it is better idea to use the new hook and trigger the event whenever necessary.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I see the problem. Basically, what I meant is putting useScrollEventEmitter in SelectionList, so other components using SelectionList, we don't need to initialize
useScrollEventEmitter
anymore. Anyways, I'm good with current, but 2 things:Can you add a comment above this line, to explain why do we need this line? It will help to remove/improve later.
App/src/components/LHNOptionsList/LHNOptionsList.tsx
Line 70 in ae23518
I'm still thinking that we don't need to inject tooltipName into
useScrollEventEmitter
and simply calluseScrollEventEmitter()
. Reason: In some components, we have 2-3 kinds of EducationalTooltip. For example, inOptionRowLHN
, it has 2 kinds of tooltipApp/src/components/LHNOptionsList/OptionRowLHN.tsx
Line 73 in fc643d5
If we go with current approach, do we need to setup 2 useScrollEventEmitter?
My thoughts here is we can introduce an additional prop
shouldHideOnScroll
in BaseEducationalTooltip, then only setup 1useScrollEventEmitter()
inOptionRowLHN
and passshouldHideOnScroll={true}
hereApp/src/components/LHNOptionsList/OptionRowLHN.tsx
Lines 189 to 201 in fc643d5
wdyt? @mohit6789
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me try to implement it, and see if this will work or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes pushed