[Perf] Sparkles: Pause when in background
This commit is contained in:
parent
d04c811f8f
commit
0aa6681b1e
@ -1,8 +1,10 @@
|
|||||||
import { memo } from '../../lib/teact/teact';
|
import { memo, useEffect, useRef } from '../../lib/teact/teact';
|
||||||
|
|
||||||
import buildClassName from '../../util/buildClassName';
|
import buildClassName from '../../util/buildClassName';
|
||||||
import buildStyle from '../../util/buildStyle';
|
import buildStyle from '../../util/buildStyle';
|
||||||
|
|
||||||
|
import { getIsInBackground } from '../../hooks/window/useBackgroundMode.ts';
|
||||||
|
|
||||||
import styles from './Sparkles.module.scss';
|
import styles from './Sparkles.module.scss';
|
||||||
|
|
||||||
type ButtonParameters = {
|
type ButtonParameters = {
|
||||||
@ -89,9 +91,19 @@ const Sparkles = ({
|
|||||||
noAnimation,
|
noAnimation,
|
||||||
...presetSettings
|
...presetSettings
|
||||||
}: OwnProps) => {
|
}: OwnProps) => {
|
||||||
|
const ref = useRef<HTMLDivElement>();
|
||||||
|
|
||||||
|
const getIsInBackgroundLocal = getIsInBackground;
|
||||||
|
useEffect(() => {
|
||||||
|
(Array.from(ref.current!.children) as HTMLDivElement[]).forEach((sparkleEL) => {
|
||||||
|
sparkleEL.style.animationPlayState = getIsInBackgroundLocal() ? 'paused' : 'running';
|
||||||
|
});
|
||||||
|
}, [getIsInBackgroundLocal]);
|
||||||
|
|
||||||
if (presetSettings.preset === 'button') {
|
if (presetSettings.preset === 'button') {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
ref={ref}
|
||||||
className={buildClassName(styles.root, styles.button, className, noAnimation && styles.noAnimation)}
|
className={buildClassName(styles.root, styles.button, className, noAnimation && styles.noAnimation)}
|
||||||
style={style}
|
style={style}
|
||||||
>
|
>
|
||||||
@ -121,7 +133,7 @@ const Sparkles = ({
|
|||||||
|
|
||||||
if (presetSettings.preset === 'progress') {
|
if (presetSettings.preset === 'progress') {
|
||||||
return (
|
return (
|
||||||
<div className={buildClassName(styles.root, styles.progress, className)} style={style}>
|
<div ref={ref} className={buildClassName(styles.root, styles.progress, className)} style={style}>
|
||||||
{PROGRESS_POSITIONS.map((position) => {
|
{PROGRESS_POSITIONS.map((position) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user