TootComposer: stops propagation of touch and wheel
Some checks failed
/ depoly (push) Has been cancelled

This commit is contained in:
thislight 2024-10-31 22:33:29 +08:00
parent 187ebdba33
commit a0ca305ef2
No known key found for this signature in database
GPG key ID: FCFE5192241CCD4E
3 changed files with 46 additions and 12 deletions

View file

@ -17,7 +17,10 @@
&::backdrop { &::backdrop {
background: none; background: transparent;
transition: background-color 120ms var(--tutu-anim-curve-std);
transition-behavior: allow-discrete;
} }
box-shadow: var(--tutu-shadow-e16); box-shadow: var(--tutu-shadow-e16);
@ -53,7 +56,7 @@
} }
&.animated { &.animated {
position: absolute; position: fixed;
overflow: hidden; overflow: hidden;
will-change: width, height, top, left; will-change: width, height, top, left;
@ -66,16 +69,25 @@
top: unset; top: unset;
transform: translateX(-50%); transform: translateX(-50%);
bottom: 0; bottom: 0;
content: content; height: auto;
height: unset;
contain: content; contain: content;
contain-intrinsic-size: unset; contain-intrinsic-size: unset;
&[open]::backdrop {
background: var(--tutu-color-shadow-l1);
}
@media (max-width: 560px) { @media (max-width: 560px) {
& { & {
transform: none; transform: none;
height: unset; height: auto;
} }
} }
} }
} }
@starting-style {
.BottomSheet::backdrop {
background: transparent;
}
}

View file

@ -4,6 +4,7 @@ import {
createSignal, createSignal,
onCleanup, onCleanup,
useTransition, useTransition,
type JSX,
type ParentComponent, type ParentComponent,
type ResolvedChildren, type ResolvedChildren,
} from "solid-js"; } from "solid-js";
@ -14,6 +15,7 @@ import material from "./material.module.css";
export type BottomSheetProps = { export type BottomSheetProps = {
open?: boolean; open?: boolean;
bottomUp?: boolean; bottomUp?: boolean;
class?: JSX.HTMLAttributes<HTMLElement>["class"];
onClose?(reason: "backdrop"): void; onClose?(reason: "backdrop"): void;
}; };
@ -219,10 +221,8 @@ const BottomSheet: ParentComponent<BottomSheetProps> = (props) => {
return ( return (
<dialog <dialog
class={`BottomSheet ${material.surface}`} class={`BottomSheet ${material.surface} ${props.class || ""}`}
classList={{ classList={{
["BottomSheet"]: true,
[material.surface]: true,
["bottom"]: props.bottomUp, ["bottom"]: props.bottomUp,
}} }}
onClick={onDialogClick} onClick={onDialogClick}

View file

@ -42,11 +42,13 @@ import { useLanguage } from "../platform/i18n";
import iso639_1 from "iso-639-1"; import iso639_1 from "iso-639-1";
import ChooseTootLang from "./ChooseTootLang"; import ChooseTootLang from "./ChooseTootLang";
import type { mastodon } from "masto"; import type { mastodon } from "masto";
import cardStyles from "../material/cards.module.css";
type TootVisibility = "public" | "unlisted" | "private" | "direct"; type TootVisibility = "public" | "unlisted" | "private" | "direct";
const TootVisibilityPickerDialog: Component<{ const TootVisibilityPickerDialog: Component<{
open?: boolean; open?: boolean;
class?: string;
onClose: () => void; onClose: () => void;
visibility: TootVisibility; visibility: TootVisibility;
onVisibilityChange: (value: TootVisibility) => void; onVisibilityChange: (value: TootVisibility) => void;
@ -76,7 +78,12 @@ const TootVisibilityPickerDialog: Component<{
}; };
return ( return (
<BottomSheet open={props.open} onClose={props.onClose} bottomUp> <BottomSheet
open={props.open}
onClose={props.onClose}
bottomUp
class={props.class}
>
<Scaffold <Scaffold
bottom={ bottom={
<div <div
@ -163,12 +170,13 @@ const TootVisibilityPickerDialog: Component<{
const TootLanguagePickerDialog: Component<{ const TootLanguagePickerDialog: Component<{
open?: boolean; open?: boolean;
class?: string;
onClose: () => void; onClose: () => void;
code: string; code: string;
onCodeChange: (nval: string) => void; onCodeChange: (nval: string) => void;
}> = (props) => { }> = (props) => {
return ( return (
<BottomSheet open={props.open} onClose={props.onClose}> <BottomSheet open={props.open} onClose={props.onClose} class={props.class}>
<Show when={props.open}> <Show when={props.open}>
<ChooseTootLang <ChooseTootLang
code={props.code} code={props.code}
@ -188,6 +196,10 @@ function randomChoose<T extends any[]>(
return K[idx]; return K[idx];
} }
function cancelEvent(event: Event) {
event.stopPropagation();
}
const TootComposer: Component<{ const TootComposer: Component<{
ref?: Ref<HTMLDivElement>; ref?: Ref<HTMLDivElement>;
style?: JSX.CSSProperties; style?: JSX.CSSProperties;
@ -301,7 +313,15 @@ const TootComposer: Component<{
ref={props.ref} ref={props.ref}
class={tootComposers.composer} class={tootComposers.composer}
style={containerStyle()} style={containerStyle()}
onClick={(e) => inputRef.focus()} onClick={() => {
inputRef.focus();
}}
on:touchend={
cancelEvent
/* on: is required to register the event handler on the exact element */
}
on:touchmove={cancelEvent}
on:wheel={cancelEvent}
> >
<div class={tootComposers.replyInput}> <div class={tootComposers.replyInput}>
<Show when={props.profile}> <Show when={props.profile}>
@ -365,6 +385,7 @@ const TootComposer: Component<{
</div> </div>
<TootVisibilityPickerDialog <TootVisibilityPickerDialog
class={cardStyles.cardNoPad}
open={permPicker()} open={permPicker()}
onClose={() => setPermPicker(false)} onClose={() => setPermPicker(false)}
visibility={visibility()} visibility={visibility()}
@ -372,6 +393,7 @@ const TootComposer: Component<{
/> />
<TootLanguagePickerDialog <TootLanguagePickerDialog
class={cardStyles.cardNoPad}
open={langPickerOpen()} open={langPickerOpen()}
onClose={() => setLangPickerOpen(false)} onClose={() => setLangPickerOpen(false)}
code={language()} code={language()}