mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-24 20:26:24 +00:00
Rename files
This commit is contained in:
61
ts/components/StoryProgressSegment.dom.tsx
Normal file
61
ts/components/StoryProgressSegment.dom.tsx
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright 2024 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
import React, { memo, useEffect, useRef } from 'react';
|
||||
import { animated, useSpring } from '@react-spring/web';
|
||||
|
||||
export type StoryProgressSegmentProps = Readonly<{
|
||||
currentIndex: number;
|
||||
duration: number | null;
|
||||
index: number;
|
||||
playing: boolean;
|
||||
onFinish: () => void;
|
||||
}>;
|
||||
|
||||
function isValidDuration(duration: number | null): boolean {
|
||||
return duration != null && Number.isFinite(duration) && duration > 0;
|
||||
}
|
||||
|
||||
export const StoryProgressSegment = memo(function StoryProgressSegment({
|
||||
currentIndex,
|
||||
duration,
|
||||
index,
|
||||
playing,
|
||||
onFinish,
|
||||
}: StoryProgressSegmentProps): JSX.Element {
|
||||
const onFinishRef = useRef(onFinish);
|
||||
useEffect(() => {
|
||||
onFinishRef.current = onFinish;
|
||||
}, [onFinish]);
|
||||
|
||||
const [progressBarStyle] = useSpring(() => {
|
||||
return {
|
||||
immediate: index !== currentIndex,
|
||||
// Pause while we are waiting for a valid duration
|
||||
pause: !playing || !isValidDuration(duration),
|
||||
from: { x: index < currentIndex ? 1 : 0 },
|
||||
to: { x: index <= currentIndex ? 1 : 0 },
|
||||
config: { duration: duration ?? Infinity },
|
||||
onRest: result => {
|
||||
if (index === currentIndex && result.finished) {
|
||||
onFinishRef.current();
|
||||
}
|
||||
},
|
||||
};
|
||||
}, [index, playing, currentIndex, duration]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className="StoryProgressSegment"
|
||||
aria-current={index === currentIndex ? 'step' : false}
|
||||
>
|
||||
<animated.div
|
||||
className="StoryProgressSegment__bar"
|
||||
style={{
|
||||
transform: progressBarStyle.x.to(
|
||||
value => `translateX(${value * 100 - 100}%)`
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user