BottomSheet: fix jumpy animation
This commit is contained in:
parent
368bca9fa1
commit
7cc9753d30
1 changed files with 10 additions and 2 deletions
|
@ -1,11 +1,15 @@
|
||||||
import {
|
import {
|
||||||
|
children,
|
||||||
createEffect,
|
createEffect,
|
||||||
createRenderEffect,
|
createRenderEffect,
|
||||||
|
createSignal,
|
||||||
onCleanup,
|
onCleanup,
|
||||||
onMount,
|
onMount,
|
||||||
startTransition,
|
startTransition,
|
||||||
useTransition,
|
useTransition,
|
||||||
|
type ChildrenReturn,
|
||||||
type ParentComponent,
|
type ParentComponent,
|
||||||
|
type ResolvedChildren,
|
||||||
} from "solid-js";
|
} from "solid-js";
|
||||||
import styles from "./BottomSheet.module.css";
|
import styles from "./BottomSheet.module.css";
|
||||||
import { useHeroSignal } from "../platform/anim";
|
import { useHeroSignal } from "../platform/anim";
|
||||||
|
@ -40,17 +44,21 @@ const BottomSheet: ParentComponent<BottomSheetProps> = (props) => {
|
||||||
let element: HTMLDialogElement;
|
let element: HTMLDialogElement;
|
||||||
let animation: Animation | undefined;
|
let animation: Animation | undefined;
|
||||||
const hero = useHeroSignal(HERO);
|
const hero = useHeroSignal(HERO);
|
||||||
|
const [cache, setCache] = createSignal<ResolvedChildren | undefined>();
|
||||||
|
const ochildren = children(() => props.children);
|
||||||
|
|
||||||
const [pending] = useTransition()
|
const [pending] = useTransition();
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (props.open) {
|
if (props.open) {
|
||||||
if (!element.open && !pending()) {
|
if (!element.open && !pending()) {
|
||||||
animatedOpen();
|
animatedOpen();
|
||||||
|
setCache(ochildren());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (element.open) {
|
if (element.open) {
|
||||||
animatedClose();
|
animatedClose();
|
||||||
|
setCache(undefined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -115,7 +123,7 @@ const BottomSheet: ParentComponent<BottomSheetProps> = (props) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<dialog class={styles.bottomSheet} ref={element!}>
|
<dialog class={styles.bottomSheet} ref={element!}>
|
||||||
{props.children}
|
{ochildren() ?? cache()}
|
||||||
</dialog>
|
</dialog>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue