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:
1 parent
c07d364584
commit
14e4c0569d
4 files changed
+55
-31
No files matched your search
+21
-14
@@ -1,53 +1,60 @@
|
|||||||
import { useState } from "react";
|
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 useMeasure from "react-use-measure";
|
||||||
|
|
||||||
import { VenetianBlindsFilter } from "./styles";
|
import { VenetianBlindsFilter } from "./styles";
|
||||||
import { wipe45DegClip } from "../../../../utils/styling";
|
import { wipeCustomDegClip } from "../../../../utils/styling";
|
||||||
|
import { Corner } from "../../../../types/style";
|
||||||
|
|
||||||
type VenetianBlindsTransitionProps = {
|
type VenetianBlindsTransitionProps = {
|
||||||
color: string,
|
blindsColor: string,
|
||||||
|
degrees: number,
|
||||||
|
duration: number,
|
||||||
|
wipeStartingCorner: Corner,
|
||||||
};
|
};
|
||||||
export const VenetianBlindsTransition = (
|
export const VenetianBlindsTransition = (
|
||||||
{ color, children }: React.PropsWithChildren<VenetianBlindsTransitionProps>,
|
{
|
||||||
|
blindsColor,
|
||||||
|
degrees,
|
||||||
|
duration,
|
||||||
|
wipeStartingCorner,
|
||||||
|
children,
|
||||||
|
}: React.PropsWithChildren<VenetianBlindsTransitionProps>,
|
||||||
) => {
|
) => {
|
||||||
const [childRef, {
|
const [childRef, {
|
||||||
height: childHeight,
|
height: childHeight,
|
||||||
width: childWidth,
|
width: childWidth,
|
||||||
}] = useMeasure();
|
}] = useMeasure();
|
||||||
const deg = -45;
|
|
||||||
|
|
||||||
const [state, toggle] = useState(true);
|
const [state, toggle] = useState(true);
|
||||||
|
|
||||||
const { x } = useSpring({
|
const { x } = useSpring({
|
||||||
from: { x: 0 },
|
from: { x: 0 },
|
||||||
x: state ? 1 : 0,
|
x: state ? 1 : 0,
|
||||||
config: { duration: 300 },
|
config: { duration },
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div onClick={() => {
|
<div onClick={() => toggle(!state)}>
|
||||||
console.log(!state);
|
|
||||||
toggle(!state);
|
|
||||||
}}>
|
|
||||||
<animated.div
|
<animated.div
|
||||||
style={{
|
style={{
|
||||||
clipPath: x.to(x => {
|
clipPath: x.to(x => {
|
||||||
const [a1, a2, b1, b2, c1, c2] = wipe45DegClip(
|
const [a1, a2, b1, b2, c1, c2] = wipeCustomDegClip(
|
||||||
childWidth,
|
childWidth,
|
||||||
childHeight,
|
childHeight,
|
||||||
x,
|
x,
|
||||||
"bottomRight",
|
wipeStartingCorner,
|
||||||
|
degrees,
|
||||||
);
|
);
|
||||||
return `polygon(${a1}px ${a2}px, ${b1}px ${b2}px, ${c1}px ${c2}px)`;
|
return `polygon(${a1}px ${a2}px, ${b1}px ${b2}px, ${c1}px ${c2}px)`;
|
||||||
}),
|
}),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<VenetianBlindsFilter
|
<VenetianBlindsFilter
|
||||||
deg={deg}
|
deg={-45}
|
||||||
transparentWidth={3}
|
transparentWidth={3}
|
||||||
opaqueWidth={5}
|
opaqueWidth={5}
|
||||||
opaqueColor={color}
|
opaqueColor={blindsColor}
|
||||||
ref={childRef}
|
ref={childRef}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
+13
-3
@@ -9,20 +9,30 @@ import { BasicBlock } from "../styles";
|
|||||||
export function VenetianBlindsWorkspace() {
|
export function VenetianBlindsWorkspace() {
|
||||||
const { prototypeState } = useSelector(workspaceSelector);
|
const { prototypeState } = useSelector(workspaceSelector);
|
||||||
|
|
||||||
const bgColor = prototypeState?.venetianTransition?.showBG
|
const bgColor = prototypeState?.venetianTransition?.showBG ?? true
|
||||||
? "black" : "transparent";
|
? "black" : "transparent";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BasicBlock width={450} height={450} color={bgColor} >
|
<BasicBlock width={450} height={450} color={bgColor} >
|
||||||
{prototypeState?.venetianTransition?.mode === "driverPortrait" ? (
|
{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
|
<DriverPortrait
|
||||||
driverId="hamilton"
|
driverId="hamilton"
|
||||||
height={150}
|
height={150}
|
||||||
/>
|
/>
|
||||||
</VenetianBlindsTransition>
|
</VenetianBlindsTransition>
|
||||||
) : (
|
) : (
|
||||||
<VenetianBlindsTransition color="#f60d0db5">
|
<VenetianBlindsTransition
|
||||||
|
blindsColor="#f60d0db5"
|
||||||
|
degrees={45}
|
||||||
|
duration={350}
|
||||||
|
wipeStartingCorner="bottomRight"
|
||||||
|
>
|
||||||
<PositionFlag size={122} number={1} />
|
<PositionFlag size={122} number={1} />
|
||||||
</VenetianBlindsTransition>
|
</VenetianBlindsTransition>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Vendored
+5
@@ -22,3 +22,8 @@ export interface Placement {
|
|||||||
bottom?: string;
|
bottom?: string;
|
||||||
left?: string;
|
left?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Useful to initialize movements from.
|
||||||
|
*/
|
||||||
|
export type Corner = "topLeft" | "topRight" | "bottomRight" | "bottomLeft";
|
||||||
+16
-14
@@ -1,6 +1,7 @@
|
|||||||
import { css }from "styled-components";
|
import { css }from "styled-components";
|
||||||
|
import { clamp } from "lodash";
|
||||||
|
|
||||||
import { Fraction, Placement, Px } from "../types/style";
|
import { Corner, Fraction, Placement, Px } from "../types/style";
|
||||||
|
|
||||||
export function placementStyleRules(pos: Placement) {
|
export function placementStyleRules(pos: Placement) {
|
||||||
return css`
|
return css`
|
||||||
@@ -15,46 +16,47 @@ export function placementStyleRules(pos: Placement) {
|
|||||||
/**
|
/**
|
||||||
* Provides the x, y coordinates of a three point polygon for use in a clip-path
|
* Provides the x, y coordinates of a three point polygon for use in a clip-path
|
||||||
* mask. By taking a fraction to indicate the progress through the animation it
|
* mask. By taking a fraction to indicate the progress through the animation it
|
||||||
* will return the six coordinates that will generate a 45 degree wipe effect.
|
* will return the six coordinates that will generate a wipe effect.
|
||||||
* @param width element width in pixels
|
* @param width element width in pixels
|
||||||
* @param height element height in pixels
|
* @param height element height in pixels
|
||||||
* @param progress fraction from 0 to 1
|
* @param progress fraction from 0 to 1
|
||||||
* @param startingCorner Which corner the wipe originates from
|
* @param startingCorner Which corner the wipe originates from
|
||||||
|
* @param degrees The angle in degrees of the wipe
|
||||||
* @returns Array of six numbers representing pixel values of the clip-path
|
* @returns Array of six numbers representing pixel values of the clip-path
|
||||||
*/
|
*/
|
||||||
export function wipe45DegClip(
|
export function wipeCustomDegClip(
|
||||||
width: Px,
|
width: Px,
|
||||||
height: Px,
|
height: Px,
|
||||||
progress: Fraction,
|
progress: Fraction,
|
||||||
startingCorner: "topLeft" | "topRight" | "bottomRight" | "bottomLeft",
|
startingCorner: Corner,
|
||||||
|
degrees: number,
|
||||||
): [Px, Px, Px, Px, Px, Px] {
|
): [Px, Px, Px, Px, Px, Px] {
|
||||||
// Long edge multiplied by 2.
|
const tangent = Math.tan(clamp(degrees, 0.01, 90) * Math.PI / 180);
|
||||||
const l = Math.max(width, height) * 2;
|
|
||||||
|
|
||||||
switch (startingCorner) {
|
switch (startingCorner) {
|
||||||
case "topLeft":
|
case "topLeft":
|
||||||
return [
|
return [
|
||||||
0, 0,
|
0, 0,
|
||||||
l * progress, 0,
|
(width + height / tangent) * progress, 0,
|
||||||
0, l * progress,
|
0, (height + width * tangent) * progress ,
|
||||||
];
|
];
|
||||||
case "topRight":
|
case "topRight":
|
||||||
return [
|
return [
|
||||||
width, 0,
|
width, 0,
|
||||||
width, l * progress,
|
width, (height + width * tangent) * progress,
|
||||||
width - l * progress, 0,
|
width - (width + height / tangent) * progress, 0,
|
||||||
];
|
];
|
||||||
case "bottomRight":
|
case "bottomRight":
|
||||||
return [
|
return [
|
||||||
width, height,
|
width, height,
|
||||||
width, height - l * progress,
|
width, height - (height + width * tangent) * progress,
|
||||||
width - l * progress, height,
|
width - (width + height / tangent) * progress, height,
|
||||||
];
|
];
|
||||||
case "bottomLeft":
|
case "bottomLeft":
|
||||||
return [
|
return [
|
||||||
0, height,
|
0, height,
|
||||||
0, height - l * progress,
|
0, height - (height + width * tangent) * progress,
|
||||||
l * progress, height,
|
(width + height / tangent) * progress, height,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user