[CORL-391] Fix jankiness when opening reply box of last comment in Stream (#2447)

* feat: add useResizeObserver hook

* fix: stream jumps when clicking on the last reply button when scrolled to the bottom

* chore: use resize observer in auth popup and simplify resize handling

* fix: snapshots and remove resize observer from stream

* fix: focus unmounted rte
This commit is contained in:
Vinh
2019-08-07 15:26:30 -04:00
committed by Kim Gardner
parent b41ddbc22f
commit 3f307002e2
37 changed files with 771 additions and 836 deletions
+1
View File
@@ -3,3 +3,4 @@ export { default as usePrevious } from "./usePrevious";
export { default as useEffectWhenChanged } from "./useEffectWhenChanged";
export { default as useUUID } from "./useUUID";
export { default as useToken } from "./useToken";
export { default as useResizeObserver } from "./useResizeObserver";
@@ -0,0 +1,28 @@
import { useEffect, useRef } from "react";
import ResizeObserver from "resize-observer-polyfill";
export default function useResizeObserver(
cb: (entry: ResizeObserverEntry) => void
) {
const ref = useRef<any>(null);
useEffect(() => {
const element = ref.current;
if (element) {
const resizeObserver = new ResizeObserver(entries => {
if (!Array.isArray(entries)) {
return;
}
if (entries.length === 0) {
return;
}
// We are only observing one element.
const entry = entries[0];
cb(entry);
});
resizeObserver.observe(element);
return () => resizeObserver.unobserve(element);
}
return;
}, [ref.current]);
return ref;
}