ISSUE-045 - Venetian Blinds - Figured out some trig to get this to work. The angle of the wipe is now customizable and no longer limited to 45°.

This commit is contained in:
Kyle Geib committed 2022-02-07 16:02:15 -05:00
1 parent c07d364584
commit 14e4c0569d
4 files changed
+56 -32

No files matched your search

@@ -1,53 +1,60 @@
import { useState } from "react";
import { useSpring, animated } from "@react-spring/web";
import { useSpring, animated, config } from "@react-spring/web";
import useMeasure from "react-use-measure";
import { VenetianBlindsFilter } from "./styles";
import { wipe45DegClip } from "../../../../utils/styling";
import { wipeCustomDegClip } from "../../../../utils/styling";
import { Corner } from "../../../../types/style";
type VenetianBlindsTransitionProps = {
color: string,
blindsColor: string,
degrees: number,
duration: number,
wipeStartingCorner: Corner,
};
export const VenetianBlindsTransition = (
{ color, children }: React.PropsWithChildren<VenetianBlindsTransitionProps>,
{
blindsColor,
degrees,
duration,
wipeStartingCorner,
children,
}: React.PropsWithChildren<VenetianBlindsTransitionProps>,
) => {
const [childRef, {
height: childHeight,
width: childWidth,
}] = useMeasure();
const deg = -45;
const [state, toggle] = useState(true);
const { x } = useSpring({
from: { x: 0 },
x: state ? 1 : 0,
config: { duration: 300 },
config: { duration },
});
return (
<div onClick={() => {
console.log(!state);
toggle(!state);
}}>
<div onClick={() => toggle(!state)}>
<animated.div
style={{
clipPath: x.to(x => {
const [a1, a2, b1, b2, c1, c2] = wipe45DegClip(
const [a1, a2, b1, b2, c1, c2] = wipeCustomDegClip(
childWidth,
childHeight,
x,
"bottomRight",
wipeStartingCorner,
degrees,
);
return `polygon(${a1}px ${a2}px, ${b1}px ${b2}px, ${c1}px ${c2}px)`;
}),
}}
>
<VenetianBlindsFilter
deg={deg}
deg={-45}
transparentWidth={3}
opaqueWidth={5}
opaqueColor={color}
opaqueColor={blindsColor}
ref={childRef}
>
{children}
@@ -9,20 +9,30 @@ import { BasicBlock } from "../styles";
export function VenetianBlindsWorkspace() {
const { prototypeState } = useSelector(workspaceSelector);
const bgColor = prototypeState?.venetianTransition?.showBG
const bgColor = prototypeState?.venetianTransition?.showBG ?? true
? "black" : "transparent";
return (
<BasicBlock width={450} height={450} color={bgColor} >
{prototypeState?.venetianTransition?.mode === "driverPortrait" ? (
<VenetianBlindsTransition color={theme.colors.teams.mercedes + "b5"}>
<VenetianBlindsTransition
blindsColor={theme.colors.teams.mercedes + "b5"}
degrees={35}
duration={500}
wipeStartingCorner="topLeft"
>
<DriverPortrait
driverId="hamilton"
height={150}
/>
</VenetianBlindsTransition>
) : (
<VenetianBlindsTransition color="#f60d0db5">
<VenetianBlindsTransition
blindsColor="#f60d0db5"
degrees={45}
duration={350}
wipeStartingCorner="bottomRight"
>
<PositionFlag size={122} number={1} />
</VenetianBlindsTransition>
)}