From 4bf471bd99f739b10223a78c5c2696c7f6eb27f6 Mon Sep 17 00:00:00 2001 From: Kyle Geib Date: Mon, 14 Mar 2022 08:49:14 -0500 Subject: [PATCH] ISSUE-069 - FL wipe working. Big refactor of how the PositionFlag components work. I flipped the way the wipe effect works. Originally there was the complicated problem of revealing a flag instantly and then wiping it away, requiring some delicate work with mounting and unmounting components. Instead it now works by always having a colored PositionFlag component in place and temporarily disappearing the normal PositionFlag (that is on top of it) using a transition-free opacity switch that lets the WipeTransition work reliably. This makes for fewer states and conditional renders. Added textColor and bgColor props to the PositionFlag component for flexibility. --- .../Common/PositionFlag/PositionFlag.tsx | 10 +- .../Common/PositionFlag/styles.ts | 2 + .../TimingTower/TimingTowerRow.tsx | 91 ++++++++++--------- .../TimingBoard/TimingTower/styles.ts | 13 +-- src/shared/theme.ts | 1 + 5 files changed, 58 insertions(+), 59 deletions(-) diff --git a/src/components/BroadcastGraphics/Common/PositionFlag/PositionFlag.tsx b/src/components/BroadcastGraphics/Common/PositionFlag/PositionFlag.tsx index 660d0ac..e35c1ad 100644 --- a/src/components/BroadcastGraphics/Common/PositionFlag/PositionFlag.tsx +++ b/src/components/BroadcastGraphics/Common/PositionFlag/PositionFlag.tsx @@ -7,17 +7,19 @@ type PositionFlagProps = { size: Px, number: number, numberSizeFraction?: Fraction, - color?: string; + bgColor?: string, + numberColor?: string, }; export function PositionFlag({ size, number, numberSizeFraction = 0.64, - color = theme.colors.posWhite, + bgColor = theme.colors.posWhite, + numberColor = theme.colors.black, }: PositionFlagProps) { return ( - - + + {number} diff --git a/src/components/BroadcastGraphics/Common/PositionFlag/styles.ts b/src/components/BroadcastGraphics/Common/PositionFlag/styles.ts index 979d8bb..22967a5 100644 --- a/src/components/BroadcastGraphics/Common/PositionFlag/styles.ts +++ b/src/components/BroadcastGraphics/Common/PositionFlag/styles.ts @@ -21,10 +21,12 @@ PositionFlagBox.displayName = "PositionFlagBox"; type PositionNumberProps = { size: Px, + color: string, }; export const PositionNumber = styled.span` font-family: ${p => p.theme.fonts.f1Regular}; font-size: ${({ size }) => size}px; + color: ${({ color }) => color}; margin-top: 2px; `; PositionNumber.displayName = "PositionNumber"; diff --git a/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx b/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx index 238aaf1..d8c7772 100644 --- a/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx +++ b/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx @@ -62,31 +62,38 @@ export function TimingTowerRow({ const { design: { timingTower: ttTheme } } = theme; const [pastPos, setPastPos] = useState(car.position); - const [posChange, setPosChange] = useState(0); - const [pastFLHolder, setPastFLHolder] = useState(false); + const [currentFL, setCurrentFL] = useState(false); const [pastDisplayMode, setPastDisplayMode] = useState(displayMode); const [hugRight, setHugRight] = useState(true); // Using timeouts and boolean states I can manipulate visiblity of the position - // change effects. showPosWipe is true for only 1ms before being switched back off. - const [showPosOutline, setShowPosOutline] = useState(false); + // change effects. When a const [showOutline, setShowOutline] = useState(false); - const [showPosWipe, setShowPosWipe] = useState(false); - useTimeoutWhen(() => setShowPosOutline(false), ( - ttTheme.wipeDelayMs + ttTheme.wipeDurationMs - ) * DDM, showPosOutline); useTimeoutWhen(() => setShowOutline(false), ttTheme.rowTravelDurationMs * DDM, showOutline); - useTimeoutWhen(() => setShowPosWipe(false), 1, showPosWipe); + const [showChangeFlag, setShowChangeFlag] = useState(false); + useTimeoutWhen(() => setShowChangeFlag(false), ttTheme.wipeDelayMs * DDM, showChangeFlag); + const [changeColors, setChangeColors] = useState<[string, string]>(["white", "black"]); useEffect(() => { if (car.position !== pastPos) { + // Position change. + setShowChangeFlag(true); + setChangeColors([ + car.position < pastPos ? theme.colors.posGainedGreen : theme.colors.posLostRed, + theme.colors.black, + ]); setPastPos(car.position); - setPosChange(pastPos - car.position); - setShowPosOutline(true); setShowOutline(true); - setShowPosWipe(true); + } else if (car.notices.includes(CarNotice.FastestLap) && !currentFL) { + // Fastest Lap gained. + setShowChangeFlag(true); + setCurrentFL(true); + setChangeColors([theme.colors.posFastestLap, theme.colors.textWhite]); + } else if (currentFL && !car.notices.includes(CarNotice.FastestLap)) { + // Fastest Lap lost. + setCurrentFL(false); } - }, [car.position]); + }, [car.position, car.notices]); useEffect(() => { if (pastDisplayMode !== displayMode) { @@ -105,7 +112,7 @@ export function TimingTowerRow({ }, [displayMode]); const { outlineClipPathProgress } = useSpring({ - outlineClipPathProgress: showPosOutline ? 1 : 0, + outlineClipPathProgress: showOutline ? 1 : 0, config: { duration: 333 * DDM }, delay: 0 * DDM, }); @@ -201,36 +208,34 @@ export function TimingTowerRow({ > {car.status !== CarStatus.Retired && ( + /** + * The "Change" PositionFlag (the colored one) is always present but + * usually hidden under a second visible "Normal" PositionFlag. When + * a change is made the normal PositionFlag is hidden instantly and + * after a delay is revealed. With the reveal a WipeTransition also + * takes place. Before, the "Change" PositionFlag would wipe away. + * Now, instead, it is hidden under a revealed "Normal" PositionFlag. + */ - - {(showPosOutline) && ( - - 0 - ? theme.colors.posGainedGreen - : theme.colors.posLostRed} - /> - - - )} + + + + )} @@ -285,12 +290,8 @@ export function TimingTowerRow({ open={showOutline} startThickness={1.5} endThickness={1.5} - startColor={posChange > 0 - ? theme.colors.posGainedGreen - : theme.colors.posLostRed} - endColor={posChange > 0 - ? theme.colors.posGainedGreen - : theme.colors.posLostRed} + startColor={changeColors[0]} + endColor={changeColors[0]} transitionProps={[{ property: "opacity", duration: 333 * DDM, diff --git a/src/components/BroadcastGraphics/TimingBoard/TimingTower/styles.ts b/src/components/BroadcastGraphics/TimingBoard/TimingTower/styles.ts index a3c749d..715e4da 100644 --- a/src/components/BroadcastGraphics/TimingBoard/TimingTower/styles.ts +++ b/src/components/BroadcastGraphics/TimingBoard/TimingTower/styles.ts @@ -6,6 +6,7 @@ import { Px, DirectionalTransitionProps, TransitionProps, + OpenProps, } from "../../../../types/style"; import { Milliseconds } from "../../../../types/util"; import { commonDirectionalTransition, commonTransition } from "../../../../utils/styling"; @@ -134,20 +135,12 @@ export const RowLeftHalfPosFlagContainer = styled.div` +export const RowLeftHalfPosFlagChangeContainer = styled.div` position: absolute; top: 0; left: 0; - height: ${({ size }) => size}px; - width: ${({ size }) => size}px; - opacity: ${({ visible }) => visible ? 1 : 0}; - transition: opacity ${({ transitionTime }) => transitionTime}ms; + opacity: ${({ open }) => open ? 1 : 0}; `; RowLeftHalfPosFlagChangeContainer.displayName = "RowLeftHalfPosFlagChangeContainer"; diff --git a/src/shared/theme.ts b/src/shared/theme.ts index 492cd38..ca32eb4 100644 --- a/src/shared/theme.ts +++ b/src/shared/theme.ts @@ -21,6 +21,7 @@ export const theme = { posLostRed: "#e40030", posGainedGreen: "#10ff35", posFastestLap: "#ae43ca", + black: "#000", grey: "#aaa", lightGrey: "#ddd", faintGrey: "#eee",