Skip to content

🎥 Make videos programmatically with React

Allow last <Series.Sequence /> to have durationInSeconds as Inifinty

Ravi Jainaa652ed83ef7
diff --git a/packages/core/src/series/index.tsx b/packages/core/src/series/index.tsx
index 94cd50265d..55c3ac47f0 100644
--- a/packages/core/src/series/index.tsx
+++ b/packages/core/src/series/index.tsx
@@ -32,7 +32,8 @@ const Series: FC<{
} = ({children}) => {
const childrenValue = useMemo(() => {
let startFrame = 0;
- return Children.map(flattenChildren(children), (child, i) => {
+ let flattenedChildren = flattenChildren(children)
+ return Children.map(flattenedChildren, (child, i) => {
const castedChild = child as unknown as
| {
props: SeriesSequenceProps;
@@ -71,10 +72,13 @@ const Series: FC<{
children: _children,
...passedProps
} = castedChild.props;
- validateDurationInFrames(
- durationInFramesProp,
- `of a <Series.Sequence /> component`
- );
+
+ if (i != flattenedChildren.length-1 || durationInFramesProp != Infinity) {
+ validateDurationInFrames(
+ durationInFramesProp,
+ `of a <Series.Sequence /> component`
+ );
+ }
const offset = castedChild.props.offset ?? 0;
if (Number.isNaN(offset)) {
throw new TypeError(
diff --git a/packages/core/src/test/series.test.tsx b/packages/core/src/test/series.test.tsx
index 77585a6bc0..edbcf08f1f 100644
--- a/packages/core/src/test/series.test.tsx
+++ b/packages/core/src/test/series.test.tsx
@@ -325,3 +325,46 @@ test('Should cascade positive offset props', () => {
);
expect(container.outerHTML).toBe('<div><div>third 0</div></div>');
});
+
+test('Allow durationInFrames as Infinity for last Series.Sequence', () => {
+ const {container} = renderForFrame(
+ 10,
+ <WrapSequenceContext>
+ <Series>
+ <Series.Sequence durationInFrames={5}>
+ <First />
+ </Series.Sequence>
+ <Series.Sequence durationInFrames={5}>
+ <Second />
+ </Series.Sequence>
+ <Series.Sequence durationInFrames={5}>
+ <Third />
+ </Series.Sequence>
+ </Series>{' '}
+ </WrapSequenceContext>
+ );
+ expect(container.outerHTML).toBe('<div><div style="position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px; width: 100%; height: 100%; display: flex;"><div>third 0</div></div> </div>');
+});
+
+test('Disallow durationInFrames as Infinity for first n-1 Series.Sequence', () => {
+ expect(() => {
+ renderForFrame(
+ 10,
+ <WrapSequenceContext>
+ <Series>
+ <Series.Sequence durationInFrames={5}>
+ <First />
+ </Series.Sequence>
+ <Series.Sequence durationInFrames={Infinity}>
+ <Second />
+ </Series.Sequence>
+ <Series.Sequence durationInFrames={5}>
+ <Third />
+ </Series.Sequence>
+ </Series>{' '}
+ </WrapSequenceContext>
+ );
+ }).toThrow(
+ /The "durationInFrames" prop of a <Series.Sequence \/> component must be an integer, but got Infinity\./
+ );
+});
diff --git a/packages/docs/docs/series.md b/packages/docs/docs/series.md
index 2314f6b874..5f572de21e 100644
--- a/packages/docs/docs/series.md
+++ b/packages/docs/docs/series.md
@@ -56,6 +56,8 @@ This component is a high order component, and accepts, besides it's children, th
For how many frames the sequence should be displayed. Children are unmounted if they are not within the time range of display.
+Only the last `<Serires.Sequence />` instance is allowed to have the durationInFrames as `Infinity`, rest should have a positive integer.
+
### `offset`
_optional_