Skip to content

Commit 3a6b92e

Browse files
authored
feat(react): Implement progress bar when video-filters are being loaded (#2063)
### 💡 Overview - Introduces isLoading flag which indicates if the video filters are being loaded. - Reduce blur levels for video filters 🎫 Ticket: https://linear.app/stream/issue/REACT-715/progress-bar-when-video-filters-are-loading 📑 Docs: GetStream/docs-content#875
1 parent aa702d2 commit 3a6b92e

File tree

5 files changed

+61
-9
lines changed

5 files changed

+61
-9
lines changed

packages/react-sdk/src/components/BackgroundFilters/BackgroundFilters.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export const BackgroundFiltersProvider = (
119119
useState(bgBlurLevelFromProps);
120120

121121
const [showLowFpsWarning, setShowLowFpsWarning] = useState<boolean>(false);
122+
const [isLoading, setIsLoading] = useState<boolean>(false);
122123

123124
const fpsWarningThresholdLower =
124125
performanceThresholds?.fpsWarningThresholdLower ??
@@ -290,6 +291,7 @@ export const BackgroundFiltersProvider = (
290291
isSupported,
291292
performance,
292293
isReady,
294+
isLoading,
293295
backgroundImage,
294296
backgroundBlurLevel,
295297
backgroundFilter,
@@ -311,6 +313,7 @@ export const BackgroundFiltersProvider = (
311313
tfLite={tfLite}
312314
engine={engine}
313315
onStats={handleStats}
316+
setIsLoading={setIsLoading}
314317
/>
315318
)}
316319
</ContextProvider.Provider>
@@ -322,9 +325,10 @@ const BackgroundFilters = (props: {
322325
tfLite?: TFLite;
323326
engine: FilterEngine;
324327
onStats: (stats: PerformanceStats) => void;
328+
setIsLoading: (loading: boolean) => void;
325329
}) => {
326330
const call = useCall();
327-
const { engine, api, tfLite, onStats } = props;
331+
const { engine, api, tfLite, onStats, setIsLoading } = props;
328332
const { children, start } = useRenderer(api, tfLite, call, engine);
329333
const { onError, backgroundFilter } = api;
330334
const handleErrorRef = useRef<((error: any) => void) | undefined>(undefined);
@@ -338,17 +342,22 @@ const BackgroundFilters = (props: {
338342
useEffect(() => {
339343
if (!call || !backgroundFilter) return;
340344

341-
const { unregister } = call.camera.registerFilter((ms) => {
345+
setIsLoading(true);
346+
const { unregister, registered } = call.camera.registerFilter((ms) => {
342347
return start(
343348
ms,
344349
(error) => handleErrorRef.current?.(error),
345350
(stats: PerformanceStats) => handleStatsRef.current?.(stats),
346351
);
347352
});
353+
registered.finally(() => {
354+
setIsLoading(false);
355+
});
356+
348357
return () => {
349358
unregister().catch((err) => console.warn(`Can't unregister filter`, err));
350359
};
351-
}, [call, start, backgroundFilter]);
360+
}, [call, start, backgroundFilter, setIsLoading]);
352361

353362
return children;
354363
};

packages/react-sdk/src/components/BackgroundFilters/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ export type BackgroundFiltersAPI = {
130130
*/
131131
isReady: boolean;
132132

133+
/**
134+
* Indicates whether the background filter is currently being registered.
135+
*/
136+
isLoading: boolean;
137+
133138
/**
134139
* Performance information for background filters.
135140
*/

packages/video-filters-web/src/types.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ export const BACKGROUND_BLUR_MAP: Record<
4848
{ bgBlur: number; bgBlurRadius: number }
4949
> = {
5050
low: {
51-
bgBlur: 15,
52-
bgBlurRadius: 5,
51+
bgBlur: 5,
52+
bgBlurRadius: 3,
5353
},
5454
medium: {
55-
bgBlur: 20,
56-
bgBlurRadius: 7,
55+
bgBlur: 15,
56+
bgBlurRadius: 4,
5757
},
5858
high: {
59-
bgBlur: 25,
60-
bgBlurRadius: 10,
59+
bgBlur: 30,
60+
bgBlurRadius: 5,
6161
},
6262
};

sample-apps/react/react-dogfood/components/Settings/VideoEffects.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88

99
export const VideoEffectsSettings = () => {
1010
const {
11+
isLoading,
1112
isSupported,
1213
backgroundImages,
1314
backgroundBlurLevel,
@@ -31,6 +32,11 @@ export const VideoEffectsSettings = () => {
3132
<div className="rd__video-effects">
3233
<div className="rd__video-effects__preview-container">
3334
<VideoPreview />
35+
{isLoading && (
36+
<div className="rd__video-effects__progress-bar">
37+
<div className="rd__video-effects__progress-bar__fill" />
38+
</div>
39+
)}
3440
</div>
3541
<div className="rd__video-effects__container">
3642
<div className="rd__video-effects__card">

sample-apps/react/react-dogfood/style/SettingsTabModal.scss

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,33 @@
126126
flex-direction: column;
127127
min-height: 320px;
128128
max-width: 480px;
129+
position: relative;
129130

130131
.str-video__video-preview-container {
131132
width: 100%;
132133
}
134+
135+
.rd__video-effects__progress-bar {
136+
width: 100%;
137+
height: 4px;
138+
background-color: var(--str-video__base-color6);
139+
border-radius: 0 0 var(--str-video__border-radius-xs);
140+
overflow: hidden;
141+
position: absolute;
142+
bottom: -10px;
143+
left: 50%;
144+
transform: translateX(-50%);
145+
146+
&__fill {
147+
height: 100%;
148+
width: 20%;
149+
background-color: var(--str-video__brand-color1);
150+
border-radius: var(--str-video__border-radius-xs);
151+
position: absolute;
152+
animation: rd__video-effects__progress-bar__animation 1.5s
153+
ease-in-out infinite;
154+
}
155+
}
133156
}
134157

135158
.rd__video-effects__image {
@@ -246,3 +269,12 @@
246269
}
247270
}
248271
}
272+
273+
@keyframes rd__video-effects__progress-bar__animation {
274+
0% {
275+
transform: translateX(-100%);
276+
}
277+
100% {
278+
transform: translateX(500%);
279+
}
280+
}

0 commit comments

Comments
 (0)