Skip to content
Merged
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions src/NoticeList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const NoticeList: FC<NoticeListProps> = (props) => {
const { classNames: ctxCls } = useContext(NotificationContext);

const dictRef = useRef<Record<string, HTMLDivElement>>({});
const latestNoticeRef = useRef<HTMLDivElement>(null);
const [latestNotice, setLatestNotice] = useState<HTMLDivElement>(null);
const [hoverKeys, setHoverKeys] = useState<string[]>([]);

const keys = configList.map((config) => ({
Expand All @@ -72,7 +72,7 @@ const NoticeList: FC<NoticeListProps> = (props) => {
// Force update latest notice
useEffect(() => {
if (stack && dictRef.current[keys[keys.length - 1]?.key]) {
latestNoticeRef.current = dictRef.current[keys[keys.length - 1]?.key];
setLatestNotice(dictRef.current[keys[keys.length - 1]?.key]);
}
}, [keys, stack]);

Expand Down Expand Up @@ -115,7 +115,7 @@ const NoticeList: FC<NoticeListProps> = (props) => {
if (index > 0) {
stackStyle.height = expanded
? dictRef.current[strKey]?.offsetHeight
: latestNoticeRef.current?.offsetHeight;
: latestNotice?.offsetHeight;

// Transform
let verticalOffset = 0;
Expand All @@ -126,8 +126,8 @@ const NoticeList: FC<NoticeListProps> = (props) => {
const transformY =
(expanded ? verticalOffset : index * offset) * (placement.startsWith('top') ? 1 : -1);
const scaleX =
!expanded && latestNoticeRef.current?.offsetWidth && dictRef.current[strKey]?.offsetWidth
? (latestNoticeRef.current?.offsetWidth - offset * 2 * (index < 3 ? index : 3)) /
!expanded && latestNotice?.offsetWidth && dictRef.current[strKey]?.offsetWidth
? (latestNotice?.offsetWidth - offset * 2 * (index < 3 ? index : 3)) /
dictRef.current[strKey]?.offsetWidth
: 1;
stackStyle.transform = `translate3d(${transformX}, ${transformY}px, 0) scaleX(${scaleX})`;
Expand Down