Skip to content

🎥 Make videos programmatically with React

add trigger loading to player-example

Alexander Engdahld7e07bd16da2
diff --git a/packages/player-example/src/App.tsx b/packages/player-example/src/App.tsx
index aeb5db2da1..5b75bc5e2c 100644
--- a/packages/player-example/src/App.tsx
+++ b/packages/player-example/src/App.tsx
@@ -11,6 +11,7 @@ export default function App() {
const [clickToPlay, setClickToPlay] = useState(true);
const [logs, setLogs] = useState<string[]>(() => []);
const [spaceKeyToPlayOrPause, setspaceKeyToPlayOrPause] = useState(true);
+ const [loading, setLoading] = useState(false);
const ref = useRef<PlayerRef>(null);
@@ -53,6 +54,7 @@ export default function App() {
title: String(title),
bgColor: String(bgColor),
color: String(color),
+ loading: Boolean(loading)
}}
spaceKeyToPlayOrPause={spaceKeyToPlayOrPause}
/>
@@ -163,6 +165,9 @@ export default function App() {
<button type="button" onClick={() => setspaceKeyToPlayOrPause((l) => !l)}>
spaceKeyToPlayOrPause = {String(spaceKeyToPlayOrPause)}
</button>
+ <button type="button" onClick={() => setLoading(!loading)}>
+ Toggle loading
+ </button>
<br />
<br />
{logs
diff --git a/packages/player-example/src/CarSlideshow.tsx b/packages/player-example/src/CarSlideshow.tsx
index fe6d70dcfe..b5352d75fa 100644
--- a/packages/player-example/src/CarSlideshow.tsx
+++ b/packages/player-example/src/CarSlideshow.tsx
@@ -1,12 +1,22 @@
+import { lazy } from 'react';
import {interpolate, useCurrentFrame, useVideoConfig} from 'remotion';
type Props = {
- title: string;
+ title: string,
bgColor: string,
- color: string
+ color: string,
+ loading: Boolean
};
+
+ const TriggerLoading = lazy(() => {
+ return new Promise(() => () =>
+ import(
+ './trigger-loading'
+ ).then(() => () => null as never),
+ );
+ });
-const CarSlideshow = ({title, bgColor, color}: Props) => {
+const CarSlideshow = ({title, bgColor, color, loading}: Props) => {
const frame = useCurrentFrame();
const {width, height, durationInFrames} = useVideoConfig();
const left = interpolate(frame, [0, durationInFrames], [width, width * -1]);
@@ -35,6 +45,7 @@ const CarSlideshow = ({title, bgColor, color}: Props) => {
>
{title}
</h1>
+ {loading && <TriggerLoading/>}
</div>
);
};
diff --git a/packages/player-example/src/trigger-loading.tsx b/packages/player-example/src/trigger-loading.tsx
new file mode 100644
index 0000000000..cea1029ada
--- /dev/null
+++ b/packages/player-example/src/trigger-loading.tsx
@@ -0,0 +1,5 @@
+import React from 'react';
+
+const FakeLoader: React.FC = () => <div/>
+
+export default FakeLoader;