ISSUE-058 - Basic mode switching implemented.

Still need to fade-in/fade-out the interval numbers.
Also need to look into wipe-in fade animations for full names. Will see what I can do...
This commit is contained in:
Kyle Geib committed 2022-03-03 18:56:07 -05:00
1 parent 90c8b78a20
commit 1cccc7d094
7 files changed
+209 -95

No files matched your search

@@ -48,7 +48,7 @@ export function TimingTower({ debugDurationMultiplier: DDM }: TimingTowerProps)
trackLength={trackLength}
debugDurationMultiplier={DDM}
/>));
}, [lastUpdate, splitsMode]);
}, [lastUpdate, splitsMode, displayMode]);
return (
<RowsContainer
@@ -34,12 +34,14 @@ import {
TimeDiff,
RowLeftHalfPosFlagChangeContainer,
AnimatedRowLeftHalfOutline,
DriverNameContainer,
} from "./styles";
import useMeasure from "react-use-measure";
const WIPE_DELAY: Milliseconds = 3500;
const WIPE_DURATION: Milliseconds = 400;
const TRAVEL_DURATION: Milliseconds = 750;
const FULL_WIDTH_DURATION: Milliseconds = 750;
interface TimingTowerRowProps {
car: Car;
@@ -63,13 +65,15 @@ export function TimingTowerRow({
}: TimingTowerRowProps) {
const [pastPos, setPastPos] = useState(car.position);
const [posChange, setPosChange] = useState(0);
const [pastDisplayMode, setPastDisplayMode] = useState(displayMode);
const [hugRight, setHugRight] = useState(true);
// Using timeouts and boolean states I can manipulate visiblity of the position
// change effects. wipeVisible is true for only 1ms before being switched back off.
const [showPosChange, setshowPosChange] = useState(false);
const [showPosChange, setShowPosChange] = useState(false);
const [showOutline, setShowOutline] = useState(false);
const [wipeVisible, setWipeVisible] = useState(false);
useTimeoutWhen(() => setshowPosChange(false), (WIPE_DELAY + WIPE_DURATION) * DDM, showPosChange);
useTimeoutWhen(() => setShowPosChange(false), (WIPE_DELAY + WIPE_DURATION) * DDM, showPosChange);
useTimeoutWhen(() => setShowOutline(false), TRAVEL_DURATION * DDM, showOutline);
useTimeoutWhen(() => setWipeVisible(false), 1, wipeVisible);
@@ -77,12 +81,28 @@ export function TimingTowerRow({
if (car.position !== pastPos) {
setPastPos(car.position);
setPosChange(pastPos - car.position);
setshowPosChange(true);
setShowPosChange(true);
setShowOutline(true);
setWipeVisible(true);
}
}, [car.position]);
useEffect(() => {
if (pastDisplayMode !== displayMode) {
if ((pastDisplayMode === BGTimingTowerDisplayMode.LeftAndRight
&& displayMode === BGTimingTowerDisplayMode.FullLeft) || (
pastDisplayMode === BGTimingTowerDisplayMode.FullLeft
&& displayMode === BGTimingTowerDisplayMode.LeftAndRight
)
) {
setHugRight(true);
} else {
setHugRight(false);
}
setPastDisplayMode(displayMode);
}
}, [displayMode]);
const { outlineClipPathProgress } = useSpring({
outlineClipPathProgress: showPosChange ? 1 : 0,
config: { duration: 333 * DDM },
@@ -146,7 +166,12 @@ export function TimingTowerRow({
BGTimingTowerDisplayMode.FullLeft,
) ? 5 : undefined
}
transitionTime={TRAVEL_DURATION * DDM}
cornerTransitionTime={TRAVEL_DURATION * DDM}
transitionProps={[{
property: "width",
duration: FULL_WIDTH_DURATION * DDM,
}]}
wide={displayMode === BGTimingTowerDisplayMode.FullLeft}
ref={leftHalfRef}
>
<RowLeftHalfLayout>
@@ -182,12 +207,21 @@ export function TimingTowerRow({
)}
</RowLeftHalfPosFlagChangeContainer>
</RowLeftHalfPosFlagContainer>
)}
<DriverName>
{car.driver.initials}
</DriverName>
<DriverNameContainer
transitionProps={[{
property: "opacity",
duration: 1000,
}]}
>
<DriverName visible={displayMode !== BGTimingTowerDisplayMode.FullLeft}>
{car.driver.initials}
</DriverName>
<DriverName visible={displayMode === BGTimingTowerDisplayMode.FullLeft}>
{car.driver.lastName}
</DriverName>
</DriverNameContainer>
</RowLeftHalfLayout>
<RowLeftHalfGemContainer>
<TeamGem team={car.driver.team.id} height={30} />
@@ -231,7 +265,13 @@ export function TimingTowerRow({
BGTimingTowerSplitsMode.Interval,
) ? 5 : undefined
}
transitionTime={TRAVEL_DURATION * DDM}
cornerTransitionTime={TRAVEL_DURATION * DDM}
collapsed={displayMode !== BGTimingTowerDisplayMode.LeftAndRight}
transitionProps={[{
property: "width",
duration: FULL_WIDTH_DURATION * DDM,
}]}
hugRight={hugRight}
>
<RowRightHalfLayout>
<TimeDiff xScale={xScale} yScale={yScale}>
@@ -11,7 +11,7 @@ import fastestLapIcon from "../../../../public/images/icons/fastest-lap.svg";
type OpenProps = {
open: boolean,
};
type TransitionProps = OpenProps & {
type TransitionProps = {
transitionProps: TransitionArgs[],
};
@@ -61,30 +61,38 @@ AnimatedRowContainer.displayName = "AnimatedRowContainer";
type RoundedProp = {
roundedCornerTop?: Px,
roundedCornerBottom?: Px,
transitionTime: Milliseconds,
cornerTransitionTime: Milliseconds,
};
const Rounded = styled.div<RoundedProp>`
${({ roundedCornerTop }) =>
roundedCornerTop && css`border-top-right-radius: ${roundedCornerTop}px;`}
${({ roundedCornerBottom }) =>
roundedCornerBottom && css`border-bottom-right-radius: ${roundedCornerBottom}px;`}
transition: border-top-right-radius ${({ transitionTime }) => transitionTime}ms,
border-bottom-right-radius ${({ transitionTime }) => transitionTime}ms;
transition: border-top-right-radius ${({ cornerTransitionTime }) => cornerTransitionTime}ms,
border-bottom-right-radius ${({ cornerTransitionTime }) => cornerTransitionTime}ms;
`;
export const RowLeftHalf = styled(Rounded)`
type RowLeftHalfProps = TransitionProps & {
wide: boolean,
};
export const RowLeftHalf = styled(Rounded)<RowLeftHalfProps>`
position: absolute;
left: 0;
top: 0;
z-index: 1;
overflow-x: clip;
width: ${p => p.theme.design.timingTower.rowLeftHalfWidthPx}px; // Future will be animated.
width: ${({ theme: { design: { timingTower } }, wide }) =>
(wide ? timingTower.rowRightHalfWidthPx : 0) + timingTower.rowLeftHalfWidthPx}px;
height: ${p => p.theme.design.timingTower.rowHeightPx}px;
background-color: #000000e5
background-color: #000000e5;
${({ transitionProps }) => commonTransition(transitionProps)}
`;
RowLeftHalf.displayName = "RowLeftHalf";
type AnimatedRowLeftHalfOutlineProps = TransitionProps & {
type AnimatedRowLeftHalfOutlineProps = OpenProps & TransitionProps & {
startThickness: Px,
endThickness: Px,
startColor: string,
@@ -115,7 +123,7 @@ export const RowLeftHalfLayout = styled.div`
display: flex;
padding-left: 3px;
align-items: center;
/* align-items: center; */
justify-content: flex-start;
`;
RowLeftHalfLayout.displayName = "RowLeftHalfLayout";
@@ -155,17 +163,27 @@ export const RowLeftHalfGemContainer = styled.div`
`;
RowLeftHalfGemContainer.displayName = "RowLeftHalfGemContainer";
export const RowRightHalf = styled(Rounded)`
type RowRightHalfProps = TransitionProps & {
collapsed: boolean,
hugRight: boolean,
};
export const RowRightHalf = styled(Rounded)<RowRightHalfProps>`
position: absolute;
right: 0;
${({ hugRight }) => hugRight
? css`right: 0;` : css`
left: ${p => p.theme.design.timingTower.rowLeftHalfWidthPx}px;
`}
top: 0;
width: ${p => p.theme.design.timingTower.rowRightHalfWidthPx}px; // Future will be animated.
width: ${({ theme: { design: { timingTower } }, collapsed }) =>
collapsed ? 0 : timingTower.rowRightHalfWidthPx}px;
height: ${p => p.theme.design.timingTower.rowHeightPx}px;
overflow-x: hidden;
overflow-x: clip;
background-color: #0000007e
background-color: #0000007e;
${({ transitionProps }) => commonTransition(transitionProps)}
`;
RowRightHalf.displayName = "RowRightHalf";
@@ -181,14 +199,33 @@ export const RowRightHalfLayout = styled.div`
`;
RowRightHalfLayout.displayName = "RowRightHalfLayout";
export const DriverName = styled.span`
type DriverNameProps = {
visible: boolean,
};
export const DriverName = styled.span<DriverNameProps>`
position: absolute;
top: 0;
left: 0;
opacity: ${({ visible }) => visible ? 1 : 0};
color: white;
font-family: ${p => p.theme.fonts.f1Bold};
font-size: 20px;
margin-left: 14px;
text-transform: uppercase;
`;
DriverName.displayName = "DriverName";
export const DriverNameContainer = styled.div<TransitionProps>`
position: relative;
margin-left: 14px;
> span {
${({ transitionProps }) => commonTransition(transitionProps)}
}
`;
DriverNameContainer.displayName = "DriverNameContainer";
type TimeDiffProps = {
xScale: Fraction,
yScale: Fraction,