From e5b220aef574a269eabf868b556fafb2c7523602 Mon Sep 17 00:00:00 2001 From: thislight Date: Fri, 27 Sep 2024 18:04:09 +0800 Subject: [PATCH] TootBottomSheet: fix the skipped animation --- src/material/BottomSheet.module.css | 6 ++++ src/material/BottomSheet.tsx | 38 +++++++++++----------- src/timelines/ChooseTootLang.tsx | 2 +- src/timelines/ReplyEditor.tsx | 49 ++++++++++++++++++++++------- 4 files changed, 64 insertions(+), 31 deletions(-) diff --git a/src/material/BottomSheet.module.css b/src/material/BottomSheet.module.css index 6c31a44..adddddb 100644 --- a/src/material/BottomSheet.module.css +++ b/src/material/BottomSheet.module.css @@ -44,10 +44,16 @@ &.animated { position: absolute; transform: none; + overflow: hidden; + will-change: width, height, top, left; &::backdrop { opacity: 0; } + + & * { + overflow: hidden; + } } &.bottom { diff --git a/src/material/BottomSheet.tsx b/src/material/BottomSheet.tsx index cb3adc4..3191426 100644 --- a/src/material/BottomSheet.tsx +++ b/src/material/BottomSheet.tsx @@ -55,7 +55,7 @@ const BottomSheet: ParentComponent = (props) => { createEffect(() => { if (props.open) { if (!element.open && !pending()) { - animatedOpen(); + requestAnimationFrame(animatedOpen); setCache(ochildren()); } } else { @@ -66,15 +66,16 @@ const BottomSheet: ParentComponent = (props) => { } }); + const onClose = () => { + element.close(); + setHero(); + }; + const animatedClose = () => { const endRect = hero(); if (endRect) { const startRect = element.getBoundingClientRect(); const animation = animateHero(startRect, endRect, element, true); - const onClose = () => { - element.close(); - setHero(); - }; animation.addEventListener("finish", onClose); animation.addEventListener("cancel", onClose); } else { @@ -126,19 +127,19 @@ const BottomSheet: ParentComponent = (props) => { } }); - onMount(() => { - makeEventListener(element, "click", (event) => { - const rect = element.getBoundingClientRect(); - const isInDialog = - rect.top <= event.clientY && - event.clientY <= rect.top + rect.height && - rect.left <= event.clientX && - event.clientX <= rect.left + rect.width; - if (!isInDialog) { - props.onClose?.("backdrop"); - } - }); - }); + const onDialogClick = ( + event: MouseEvent & { currentTarget: HTMLDialogElement }, + ) => { + const rect = event.currentTarget.getBoundingClientRect(); + const isInDialog = + rect.top <= event.clientY && + event.clientY <= rect.top + rect.height && + rect.left <= event.clientX && + event.clientX <= rect.left + rect.width; + if (!isInDialog) { + props.onClose?.("backdrop"); + } + }; return ( = (props) => { [styles.bottomSheet]: true, [styles.bottom]: props.bottomUp, }} + onClick={onDialogClick} ref={element!} > {ochildren() ?? cache()} diff --git a/src/timelines/ChooseTootLang.tsx b/src/timelines/ChooseTootLang.tsx index 8405bb1..9d5cbb7 100644 --- a/src/timelines/ChooseTootLang.tsx +++ b/src/timelines/ChooseTootLang.tsx @@ -22,7 +22,7 @@ import { Title } from "../material/typography"; type ChooseTootLangProps = { code: string; - onCodeChange: (ncode?: string) => void; + onCodeChange: (ncode: string) => void; onClose?: JSX.EventHandlerUnion; }; diff --git a/src/timelines/ReplyEditor.tsx b/src/timelines/ReplyEditor.tsx index 51259b9..0d9995a 100644 --- a/src/timelines/ReplyEditor.tsx +++ b/src/timelines/ReplyEditor.tsx @@ -1,8 +1,12 @@ import { batch, + createEffect, + createRenderEffect, createSignal, createUniqueId, + lazy, onMount, + Show, type Component, type Setter, } from "solid-js"; @@ -156,6 +160,25 @@ const TootVisibilityPickerDialog: Component<{ ); }; +const TootLanguagePickerDialog: Component<{ + open?: boolean; + onClose: () => void; + code: string; + onCodeChange: (nval: string) => void; +}> = (props) => { + return ( + + + + + + ); +}; + const ReplyEditor: Component<{ profile: Account; replyToDisplayName: string; @@ -163,15 +186,19 @@ const ReplyEditor: Component<{ onTypingChange: (value: boolean) => void; }> = (props) => { let inputRef: HTMLTextAreaElement; - const buttonId = createUniqueId(); - const menuId = createUniqueId(); const typing = () => props.isTyping; const setTyping = (v: boolean) => props.onTypingChange(v); const [visibility, setVisibility] = createSignal("public"); const [permPicker, setPermPicker] = createSignal(false); - const [language, setLanguage] = createSignal(useLanguage()().split("-")[0]); + const [language, setLanguage] = createSignal("en"); const [langPickerOpen, setLangPickerOpen] = createSignal(false); + const appLanguage = useLanguage(); + + createEffect(() => { + const lang = appLanguage().split("-")[0]; + setLanguage(lang); + }); onMount(() => { makeEventListener(inputRef, "focus", () => setTyping(true)); @@ -223,6 +250,8 @@ const ReplyEditor: Component<{ display: "flex", "justify-content": "flex-end", "margin-top": "8px", + gap: "16px", + "flex-flow": "row wrap" }} > -