ISSUE-058 - New opening/closing transition props feature added. Last name wiping added.

Now we can define separate opening and closing transition settings as well as common (both ways) transition props.
This is all pretty cool.
Timing for open/close animations and transitions are looking better and more mature.
This commit is contained in:
Kyle Geib committed 2022-03-07 11:50:05 -05:00
1 parent a38af0dec4
commit 9f4e564a74
5 files changed
+156 -74

No files matched your search

@@ -35,6 +35,7 @@ import {
RowLeftHalfPosFlagChangeContainer, RowLeftHalfPosFlagChangeContainer,
AnimatedRowLeftHalfOutline, AnimatedRowLeftHalfOutline,
DriverNameContainer, DriverNameContainer,
DriverNameWipe,
} from "./styles"; } from "./styles";
import useMeasure from "react-use-measure"; import useMeasure from "react-use-measure";
@@ -42,6 +43,7 @@ const WIPE_DELAY: Milliseconds = 3500;
const WIPE_DURATION: Milliseconds = 400; const WIPE_DURATION: Milliseconds = 400;
const TRAVEL_DURATION: Milliseconds = 750; const TRAVEL_DURATION: Milliseconds = 750;
const FULL_WIDTH_DURATION: Milliseconds = 750; const FULL_WIDTH_DURATION: Milliseconds = 750;
const FULL_WIDTH_CLOSE_DELAY: Milliseconds = 333;
interface TimingTowerRowProps { interface TimingTowerRowProps {
car: Car; car: Car;
@@ -172,7 +174,8 @@ export function TimingTowerRow({
BGTimingTowerDisplayMode.FullLeft, BGTimingTowerDisplayMode.FullLeft,
) ? 5 : 0 ) ? 5 : 0
} }
transitionProps={[{ open={displayMode === BGTimingTowerDisplayMode.FullLeft}
transitionOpeningProps={[{
property: "width", property: "width",
duration: FULL_WIDTH_DURATION * DDM, duration: FULL_WIDTH_DURATION * DDM,
}, { }, {
@@ -182,7 +185,19 @@ export function TimingTowerRow({
property: "border-bottom-right-radius", property: "border-bottom-right-radius",
duration: TRAVEL_DURATION * DDM, duration: TRAVEL_DURATION * DDM,
}]} }]}
wide={displayMode === BGTimingTowerDisplayMode.FullLeft} transitionClosingProps={[{
property: "width",
duration: FULL_WIDTH_DURATION * DDM,
delay: FULL_WIDTH_CLOSE_DELAY * DDM,
}, {
property: "border-top-right-radius",
duration: TRAVEL_DURATION * DDM,
delay: FULL_WIDTH_CLOSE_DELAY * DDM,
}, {
property: "border-bottom-right-radius",
duration: TRAVEL_DURATION * DDM,
delay: FULL_WIDTH_CLOSE_DELAY * DDM,
}]}
ref={leftHalfRef} ref={leftHalfRef}
> >
<RowLeftHalfLayout> <RowLeftHalfLayout>
@@ -220,34 +235,47 @@ export function TimingTowerRow({
</RowLeftHalfPosFlagChangeContainer> </RowLeftHalfPosFlagChangeContainer>
</RowLeftHalfPosFlagContainer> </RowLeftHalfPosFlagContainer>
)} )}
<DriverNameContainer <DriverNameContainer>
transitionProps={[{ <DriverName
open={displayMode !== BGTimingTowerDisplayMode.FullLeft}
transitionOpeningProps={[{
property: "opacity", property: "opacity",
duration: (FULL_WIDTH_DURATION - 333) * DDM, duration: 333 * DDM,
delay: 333, delay: (FULL_WIDTH_DURATION - 333) * DDM,
}]}
transitionClosingProps={[{
property: "opacity",
duration: 333 * DDM,
delay: 0 * DDM,
}]} }]}
> >
<DriverName visible={displayMode !== BGTimingTowerDisplayMode.FullLeft}>
{car.driver.initials} {car.driver.initials}
</DriverName> </DriverName>
<WipeTransition <DriverNameWipe
visible={displayMode === BGTimingTowerDisplayMode.FullLeft} open={displayMode === BGTimingTowerDisplayMode.FullLeft}
angle={89} transitionOpeningProps={[{
duration={(FULL_WIDTH_DURATION + 333) * DDM} property: "width",
startingCorner={"topLeft"} duration: FULL_WIDTH_DURATION * 2 * DDM,
manualDimensions={{ delay: 0 * DDM,
height: timingTowerTheme.rowHeightPx, }, {
width: timingTowerTheme.rowLeftHalfWidthPx property: "opacity",
+ timingTowerTheme.rowRightHalfWidthPx duration: 333 * DDM,
- timingTowerTheme.teamGemSize delay: 0 * DDM,
- timingTowerTheme.posFlagSize }]}
- timingTowerTheme.nameLeftMargin, transitionClosingProps={[{
}} property: "width",
duration: FULL_WIDTH_DURATION * DDM,
delay: 0 * DDM,
}, {
property: "opacity",
duration: 333 * DDM,
delay: (FULL_WIDTH_DURATION - 333) * DDM,
}]}
> >
<DriverName visible={true}> <DriverName open>
{car.driver.lastName} {car.driver.lastName}
</DriverName> </DriverName>
</WipeTransition> </DriverNameWipe>
</DriverNameContainer> </DriverNameContainer>
</RowLeftHalfLayout> </RowLeftHalfLayout>
<RowLeftHalfGemContainer> <RowLeftHalfGemContainer>
@@ -292,25 +320,36 @@ export function TimingTowerRow({
BGTimingTowerSplitsMode.Interval, BGTimingTowerSplitsMode.Interval,
) ? 5 : 0 ) ? 5 : 0
} }
collapsed={displayMode !== BGTimingTowerDisplayMode.LeftAndRight} open={displayMode === BGTimingTowerDisplayMode.LeftAndRight}
transitionProps={[{ transitionProps={[{
property: "width",
duration: FULL_WIDTH_DURATION * DDM,
}, {
property: "border-top-right-radius", property: "border-top-right-radius",
duration: TRAVEL_DURATION * DDM, duration: TRAVEL_DURATION * DDM,
}, { }, {
property: "border-bottom-right-radius", property: "border-bottom-right-radius",
duration: TRAVEL_DURATION * DDM, duration: TRAVEL_DURATION * DDM,
}]} }]}
transitionClosingProps={[{
property: "width",
duration: FULL_WIDTH_DURATION * DDM,
}]}
transitionOpeningProps={[{
property: "width",
duration: FULL_WIDTH_DURATION * DDM,
delay: FULL_WIDTH_CLOSE_DELAY * DDM,
}]}
hugRight={hugRight} hugRight={hugRight}
> >
<RowRightHalfLayout> <RowRightHalfLayout>
<TimeDiff <TimeDiff
xScale={xScale} xScale={xScale}
yScale={yScale} yScale={yScale}
visible={displayMode === BGTimingTowerDisplayMode.LeftAndRight} open={displayMode === BGTimingTowerDisplayMode.LeftAndRight}
transitionProps={[{ transitionOpeningProps={[{
property: "opacity",
duration: FULL_WIDTH_DURATION * DDM,
delay: FULL_WIDTH_CLOSE_DELAY * DDM,
}]}
transitionClosingProps={[{
property: "opacity", property: "opacity",
duration: FULL_WIDTH_DURATION * DDM, duration: FULL_WIDTH_DURATION * DDM,
}]} }]}
@@ -1,20 +1,17 @@
import styled, { css } from "styled-components"; import styled, { css } from "styled-components";
import { animated } from "@react-spring/web"; import { animated } from "@react-spring/web";
import { Fraction, Px, TransitionArgs } from "../../../../types/style"; import {
Fraction,
Px,
DirectionalTransitionProps,
} from "../../../../types/style";
import { Milliseconds } from "../../../../types/util"; import { Milliseconds } from "../../../../types/util";
import { commonTransition } from "../../../../utils/styling"; import { commonDirectionalTransition } from "../../../../utils/styling";
import fastestLapIcon from "../../../../public/images/icons/fastest-lap.svg"; import fastestLapIcon from "../../../../public/images/icons/fastest-lap.svg";
type OpenProps = {
open: boolean,
};
type TransitionProps = {
transitionProps: TransitionArgs[],
};
type RowsContainerProps = { type RowsContainerProps = {
carsToDisplay: number, carsToDisplay: number,
retiredCarsPresent: boolean, retiredCarsPresent: boolean,
@@ -67,27 +64,25 @@ const Rounded = styled.div<RoundedProp>`
border-bottom-right-radius: ${({ roundedCornerBottom = 0 }) => roundedCornerBottom}px; border-bottom-right-radius: ${({ roundedCornerBottom = 0 }) => roundedCornerBottom}px;
`; `;
type RowLeftHalfProps = TransitionProps & { export const RowLeftHalf = styled(Rounded)<DirectionalTransitionProps>`
wide: boolean,
};
export const RowLeftHalf = styled(Rounded)<RowLeftHalfProps>`
position: absolute; position: absolute;
left: 0; left: 0;
top: 0; top: 0;
z-index: 1; z-index: 1;
overflow-x: clip; overflow-x: clip;
width: ${({ theme: { design: { timingTower } }, wide }) => width: ${({ theme: { design: { timingTower } }, open }) =>
(wide ? timingTower.rowRightHalfWidthPx : 0) + timingTower.rowLeftHalfWidthPx}px; (open ? timingTower.rowRightHalfWidthPx : 0) + timingTower.rowLeftHalfWidthPx}px;
height: ${p => p.theme.design.timingTower.rowHeightPx}px; height: ${p => p.theme.design.timingTower.rowHeightPx}px;
background-color: #000000e5; background-color: #000000e5;
${({ transitionProps }) => commonTransition(transitionProps)} ${({ open, transitionOpeningProps, transitionClosingProps, transitionProps }) =>
commonDirectionalTransition(open, transitionOpeningProps, transitionClosingProps, transitionProps)}
`; `;
RowLeftHalf.displayName = "RowLeftHalf"; RowLeftHalf.displayName = "RowLeftHalf";
type AnimatedRowLeftHalfOutlineProps = OpenProps & TransitionProps & { type AnimatedRowLeftHalfOutlineProps = DirectionalTransitionProps & {
startThickness: Px, startThickness: Px,
endThickness: Px, endThickness: Px,
startColor: string, startColor: string,
@@ -106,7 +101,8 @@ export const AnimatedRowLeftHalfOutline = animated(styled(Rounded) <AnimatedRowL
: `${startThickness}px solid ${startColor}`}; : `${startThickness}px solid ${startColor}`};
outline-offset: ${({ startThickness }) => -startThickness}px; outline-offset: ${({ startThickness }) => -startThickness}px;
${({ transitionProps }) => commonTransition(transitionProps)} ${({ open, transitionOpeningProps, transitionClosingProps, transitionProps }) =>
commonDirectionalTransition(open, transitionOpeningProps, transitionClosingProps, transitionProps)}
`); `);
AnimatedRowLeftHalfOutline.displayName = "AnimatedRowLeftHalfOutline"; AnimatedRowLeftHalfOutline.displayName = "AnimatedRowLeftHalfOutline";
@@ -118,7 +114,6 @@ export const RowLeftHalfLayout = styled.div`
display: flex; display: flex;
padding-left: 3px; padding-left: 3px;
/* align-items: center; */
justify-content: flex-start; justify-content: flex-start;
`; `;
RowLeftHalfLayout.displayName = "RowLeftHalfLayout"; RowLeftHalfLayout.displayName = "RowLeftHalfLayout";
@@ -158,27 +153,29 @@ export const RowLeftHalfGemContainer = styled.div`
`; `;
RowLeftHalfGemContainer.displayName = "RowLeftHalfGemContainer"; RowLeftHalfGemContainer.displayName = "RowLeftHalfGemContainer";
type RowRightHalfProps = TransitionProps & { type RowRightHalfProps = DirectionalTransitionProps & {
collapsed: boolean,
hugRight: boolean, hugRight: boolean,
}; };
export const RowRightHalf = styled(Rounded)<RowRightHalfProps>` export const RowRightHalf = styled(Rounded)<RowRightHalfProps>`
position: absolute; position: absolute;
${({ hugRight }) => hugRight ${({ hugRight }) => hugRight
? css`right: 0;` : css` ? css`
right: 0;
` : css`
left: ${p => p.theme.design.timingTower.rowLeftHalfWidthPx}px; left: ${p => p.theme.design.timingTower.rowLeftHalfWidthPx}px;
`} `}
top: 0; top: 0;
width: ${({ theme: { design: { timingTower } }, collapsed }) => width: ${({ theme: { design: { timingTower } }, open }) =>
collapsed ? 0 : timingTower.rowRightHalfWidthPx}px; open ? timingTower.rowRightHalfWidthPx : 0}px;
height: ${p => p.theme.design.timingTower.rowHeightPx}px; height: ${p => p.theme.design.timingTower.rowHeightPx}px;
overflow-x: clip; overflow-x: clip;
background-color: #0000007e; background-color: #0000007e;
${({ transitionProps }) => commonTransition(transitionProps)} ${({ open, transitionOpeningProps, transitionClosingProps, transitionProps }) =>
commonDirectionalTransition(open, transitionOpeningProps, transitionClosingProps, transitionProps)}
`; `;
RowRightHalf.displayName = "RowRightHalf"; RowRightHalf.displayName = "RowRightHalf";
@@ -194,37 +191,46 @@ export const RowRightHalfLayout = styled.div`
`; `;
RowRightHalfLayout.displayName = "RowRightHalfLayout"; RowRightHalfLayout.displayName = "RowRightHalfLayout";
type DriverNameProps = { export const DriverNameContainer = styled.div`
visible: boolean, position: relative;
}; margin-left: ${p => p.theme.design.timingTower.nameLeftMargin}px;
export const DriverName = styled.span<DriverNameProps>` `;
DriverNameContainer.displayName = "DriverNameContainer";
export const DriverName = styled.span<DirectionalTransitionProps>`
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
opacity: ${({ visible }) => visible ? 1 : 0};
color: white; color: white;
font-family: ${p => p.theme.fonts.f1Bold}; font-family: ${p => p.theme.fonts.f1Bold};
font-size: 20px; font-size: 20px;
text-transform: uppercase; text-transform: uppercase;
opacity: ${({ open }) => open ? 1 : 0};
${({ open, transitionOpeningProps, transitionClosingProps, transitionProps }) =>
commonDirectionalTransition(open, transitionOpeningProps, transitionClosingProps, transitionProps)}
`; `;
DriverName.displayName = "DriverName"; DriverName.displayName = "DriverName";
export const DriverNameContainer = styled.div<TransitionProps>` export const DriverNameWipe = styled.div<DirectionalTransitionProps>`
position: relative; /* background: #deadbe; */
margin-left: ${p => p.theme.design.timingTower.nameLeftMargin}px;
> span { width: ${({ open }) => open ? 800 : 200}px;
${({ transitionProps }) => commonTransition(transitionProps)} height: ${p => p.theme.design.timingTower.rowHeightPx}px;
}
mask-image: linear-gradient(to right, black 0, black 20%, transparent 30%);
mask-repeat: no-repeat;
opacity: ${({ open }) => open ? 1 : 0};
${({ open, transitionOpeningProps, transitionClosingProps, transitionProps }) =>
commonDirectionalTransition(open, transitionOpeningProps, transitionClosingProps, transitionProps)}
`; `;
DriverNameContainer.displayName = "DriverNameContainer"; DriverNameWipe.displayName = "DriverNameWipe";
type TimeDiffProps = TransitionProps & { type TimeDiffProps = DirectionalTransitionProps & {
xScale: Fraction, xScale: Fraction,
yScale: Fraction, yScale: Fraction,
visible: boolean,
}; };
export const TimeDiff = styled.span<TimeDiffProps>` export const TimeDiff = styled.span<TimeDiffProps>`
color: white; color: white;
@@ -237,8 +243,9 @@ export const TimeDiff = styled.span<TimeDiffProps>`
transform-origin: top right; transform-origin: top right;
transform: scale(${({ xScale, yScale }) => `${xScale}, ${yScale}`}); transform: scale(${({ xScale, yScale }) => `${xScale}, ${yScale}`});
opacity: ${({ visible }) => visible ? 1 : 0}; opacity: ${({ open }) => open ? 1 : 0};
${({ transitionProps }) => commonTransition(transitionProps)} ${({ open, transitionOpeningProps, transitionClosingProps, transitionProps }) =>
commonDirectionalTransition(open, transitionOpeningProps, transitionClosingProps, transitionProps)}
`; `;
TimeDiff.displayName = "TimeDiff"; TimeDiff.displayName = "TimeDiff";
@@ -10,7 +10,6 @@ import { setTimingTowerDisplayMode, setTimingTowerSplitsMode } from "../../../..
import { eventSelector } from "../../../../features/event/eventSelector"; import { eventSelector } from "../../../../features/event/eventSelector";
import { increaseDistance, refreshRunningOrder, setCarStatus } from "../../../../features/event/eventSlice"; import { increaseDistance, refreshRunningOrder, setCarStatus } from "../../../../features/event/eventSlice";
import { BGTimingTowerDisplayMode, BGTimingTowerSplitsMode, CarStatus } from "../../../../types/state"; import { BGTimingTowerDisplayMode, BGTimingTowerSplitsMode, CarStatus } from "../../../../types/state";
import { SlotSelector } from "../../../Common/Inputs/SlotSelector";
import { GridSelection } from "../GridSelection"; import { GridSelection } from "../GridSelection";
import { ClickSpan } from "./styles"; import { ClickSpan } from "./styles";
+11
View File
@@ -40,3 +40,14 @@ export interface TransitionArgs {
timing?: string timing?: string
delay?: Milliseconds, delay?: Milliseconds,
} }
export type OpenProps = {
open: boolean,
};
export type TransitionProps = OpenProps & {
transitionProps?: TransitionArgs[],
};
export type DirectionalTransitionProps = TransitionProps & {
transitionOpeningProps?: TransitionArgs[],
transitionClosingProps?: TransitionArgs[],
}
+29 -3
View File
@@ -69,16 +69,42 @@ export function wipeCustomDegClip(
* @param propsArray * @param propsArray
* @returns * @returns
*/ */
export function commonTransition(propsArray: TransitionArgs[]) { export function commonTransition(propsArray: TransitionArgs[] = []) {
if (propsArray.length === 0){
return "";
}
return ( return (
"transition: " "transition: "
+ propsArray.map(p => ` + propsArray.map(p => `
${p?.property ?? "all"} ${p?.duration ?? 1000}ms ${p?.timing ?? ""} ${p?.delay ?? 0}ms ${p?.property ?? "all"} ${p?.duration ?? 1000}ms ${p?.timing ?? ""} ${p?.delay ?? 0}ms`,
`).join(", ") ).join(", ")
+ ";" + ";"
); );
} }
/**
* An extension and evolution of commonTransition() provides a way to define
* transition configurations that can be differentiated by which direction
* (opening or closing) that they're going and can even support additional
* "shared" properties that are common in either direction.
* @param open the (often visible) state of the element
* @param openingPropsArray what transition props to use when "open" (opening)
* @param closingPropsArray what transition props to use when "closed" (closing)
* @param sharedPropsArray what transition props to use in either direction
* @returns
*/
export function commonDirectionalTransition(
open: boolean,
openingPropsArray: TransitionArgs[] = [],
closingPropsArray: TransitionArgs[] = [],
sharedPropsArray: TransitionArgs[] = [],
) {
return open
? commonTransition(openingPropsArray.concat(sharedPropsArray))
: commonTransition(closingPropsArray.concat(sharedPropsArray));
}
/** /**
* Provides the x, y coordinates of a six point polygon for use in a clip-path * Provides the x, y coordinates of a six 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