-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32930 from suneox/fix/19642-report-screen-unexpec…
…ted-scroll Fix/19642 report screen unexpected scroll
- Loading branch information
Showing
4 changed files
with
55 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Native doesn't have the DOM, so we just return null. | ||
* | ||
*/ | ||
const useIsScrollBarVisible = () => null; | ||
|
||
export default useIsScrollBarVisible; |
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,28 @@ | ||
import {useCallback, useEffect, useState} from 'react'; | ||
|
||
const useIsScrollBarVisible = (ref: React.RefObject<HTMLDivElement | HTMLTextAreaElement>, value: string) => { | ||
const [isScrollBarVisible, setIsScrollBarVisible] = useState(false); | ||
|
||
const handleResize = useCallback(() => { | ||
if (!ref.current) { | ||
return; | ||
} | ||
const {scrollHeight, clientHeight} = ref.current; | ||
setIsScrollBarVisible(scrollHeight > clientHeight); | ||
}, [ref]); | ||
|
||
useEffect(() => { | ||
if (!ref.current || !('ResizeObserver' in (window || {}))) { | ||
return; | ||
} | ||
|
||
const resizeObserver = new ResizeObserver(handleResize); | ||
resizeObserver.observe(ref.current); | ||
return () => { | ||
resizeObserver.disconnect(); | ||
}; | ||
}, [handleResize, ref, value]); | ||
return isScrollBarVisible; | ||
}; | ||
|
||
export default useIsScrollBarVisible; |
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