BottomSheet: first attempt for animation
This commit is contained in:
parent
1c0a83dbab
commit
2d7b931ef8
13 changed files with 196 additions and 20 deletions
|
@ -1,13 +1,47 @@
|
|||
import { createContext, useContext, type Accessor } from "solid-js";
|
||||
import {
|
||||
createContext,
|
||||
createRenderEffect,
|
||||
createSignal,
|
||||
untrack,
|
||||
useContext,
|
||||
type Accessor,
|
||||
type Signal,
|
||||
} from "solid-js";
|
||||
|
||||
export type HeroSource = {
|
||||
[key: string | symbol | number]: HTMLElement | undefined;
|
||||
[key: string | symbol | number]: DOMRect | undefined;
|
||||
};
|
||||
|
||||
const HeroSourceContext = createContext<Accessor<HeroSource>>(() => ({}));
|
||||
const HeroSourceContext = createContext<Signal<HeroSource>>(undefined);
|
||||
|
||||
export const HeroSourceProvider = HeroSourceContext.Provider;
|
||||
|
||||
export function useHeroSource() {
|
||||
function useHeroSource() {
|
||||
return useContext(HeroSourceContext);
|
||||
}
|
||||
|
||||
export function useHeroSignal(
|
||||
key: string | symbol | number,
|
||||
): Accessor<DOMRect | undefined> {
|
||||
const source = useHeroSource();
|
||||
if (source) {
|
||||
const [get, set] = createSignal<DOMRect>();
|
||||
|
||||
createRenderEffect(() => {
|
||||
const value = source[0]();
|
||||
console.debug("value", value);
|
||||
if (value[key]) {
|
||||
set(value[key]);
|
||||
source[1]((x) => {
|
||||
const cpy = Object.assign({}, x);
|
||||
delete cpy[key];
|
||||
return cpy;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return get;
|
||||
} else {
|
||||
return () => undefined;
|
||||
}
|
||||
}
|
||||
|
|
12
src/platform/host.ts
Normal file
12
src/platform/host.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
export function isiOS() {
|
||||
return [
|
||||
'iPad Simulator',
|
||||
'iPhone Simulator',
|
||||
'iPod Simulator',
|
||||
'iPad',
|
||||
'iPhone',
|
||||
'iPod'
|
||||
].includes(navigator.platform)
|
||||
// iPad on iOS 13 detection
|
||||
|| (navigator.userAgent.includes("Mac") && "ontouchend" in document)
|
||||
}
|
8
src/platform/polyfills.ts
Normal file
8
src/platform/polyfills.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
//! This module has side effect.
|
||||
//! It recommended to include the module by <script> tag.
|
||||
if (!document.body.animate) {
|
||||
// @ts-ignore: this file is polyfill, no exposed decls
|
||||
import("web-animations-js").then(() => {
|
||||
console.warn("web animation polyfill is included");
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue