|
|
@ -6,7 +6,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
// * Jolly Cobra's useHeavyAnimationCheck.ts, patched
|
|
|
|
// * Jolly Cobra's useHeavyAnimationCheck.ts, patched
|
|
|
|
|
|
|
|
|
|
|
|
//import { useEffect } from '../lib/teact/teact';
|
|
|
|
|
|
|
|
import { AnyToVoidFunction } from '../types'; |
|
|
|
import { AnyToVoidFunction } from '../types'; |
|
|
|
import ListenerSetter from '../helpers/listenerSetter'; |
|
|
|
import ListenerSetter from '../helpers/listenerSetter'; |
|
|
|
import { CancellablePromise, deferredPromise } from '../helpers/cancellablePromise'; |
|
|
|
import { CancellablePromise, deferredPromise } from '../helpers/cancellablePromise'; |
|
|
@ -18,12 +17,14 @@ const ANIMATION_START_EVENT = 'event-heavy-animation-start'; |
|
|
|
const ANIMATION_END_EVENT = 'event-heavy-animation-end'; |
|
|
|
const ANIMATION_END_EVENT = 'event-heavy-animation-end'; |
|
|
|
|
|
|
|
|
|
|
|
let isAnimating = false; |
|
|
|
let isAnimating = false; |
|
|
|
let heavyAnimationPromise: CancellablePromise<void> = Promise.resolve(); |
|
|
|
let heavyAnimationPromise: CancellablePromise<void> = deferredPromise<void>(); |
|
|
|
let promisesInQueue = 0; |
|
|
|
let promisesInQueue = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
heavyAnimationPromise.resolve(); |
|
|
|
|
|
|
|
|
|
|
|
const log = console.log.bind(console.log, '[HEAVY-ANIMATION]:'); |
|
|
|
const log = console.log.bind(console.log, '[HEAVY-ANIMATION]:'); |
|
|
|
|
|
|
|
|
|
|
|
export const dispatchHeavyAnimationEvent = (promise: Promise<any>, timeout?: number) => { |
|
|
|
export function dispatchHeavyAnimationEvent(promise: Promise<any>, timeout?: number) { |
|
|
|
if(!isAnimating) { |
|
|
|
if(!isAnimating) { |
|
|
|
heavyAnimationPromise = deferredPromise<void>(); |
|
|
|
heavyAnimationPromise = deferredPromise<void>(); |
|
|
|
rootScope.broadcast(ANIMATION_START_EVENT); |
|
|
|
rootScope.broadcast(ANIMATION_START_EVENT); |
|
|
@ -40,29 +41,48 @@ export const dispatchHeavyAnimationEvent = (promise: Promise<any>, timeout?: num |
|
|
|
].filter(Boolean); |
|
|
|
].filter(Boolean); |
|
|
|
|
|
|
|
|
|
|
|
const perf = performance.now(); |
|
|
|
const perf = performance.now(); |
|
|
|
|
|
|
|
const _heavyAnimationPromise = heavyAnimationPromise; |
|
|
|
Promise.race(promises).then(() => { |
|
|
|
Promise.race(promises).then(() => { |
|
|
|
|
|
|
|
if(heavyAnimationPromise !== _heavyAnimationPromise || heavyAnimationPromise.isFulfilled) { // interrupted
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
--promisesInQueue; |
|
|
|
--promisesInQueue; |
|
|
|
DEBUG && log('promise end, length:', promisesInQueue, performance.now() - perf); |
|
|
|
DEBUG && log('promise end, length:', promisesInQueue, performance.now() - perf); |
|
|
|
if(!promisesInQueue) { |
|
|
|
if(promisesInQueue <= 0) { |
|
|
|
|
|
|
|
onHeavyAnimationEnd(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return heavyAnimationPromise; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function onHeavyAnimationEnd() { |
|
|
|
|
|
|
|
if(heavyAnimationPromise.isFulfilled) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
isAnimating = false; |
|
|
|
isAnimating = false; |
|
|
|
promisesInQueue = 0; |
|
|
|
promisesInQueue = 0; |
|
|
|
rootScope.broadcast(ANIMATION_END_EVENT); |
|
|
|
rootScope.broadcast(ANIMATION_END_EVENT); |
|
|
|
heavyAnimationPromise.resolve(); |
|
|
|
heavyAnimationPromise.resolve(); |
|
|
|
|
|
|
|
|
|
|
|
DEBUG && log('end'); |
|
|
|
DEBUG && log('end'); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return heavyAnimationPromise; |
|
|
|
export function interruptHeavyAnimation() { |
|
|
|
}; |
|
|
|
onHeavyAnimationEnd(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const getHeavyAnimationPromise = () => heavyAnimationPromise; |
|
|
|
export function getHeavyAnimationPromise() { |
|
|
|
|
|
|
|
return heavyAnimationPromise; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export default ( |
|
|
|
export default function( |
|
|
|
handleAnimationStart: AnyToVoidFunction, |
|
|
|
handleAnimationStart: AnyToVoidFunction, |
|
|
|
handleAnimationEnd: AnyToVoidFunction, |
|
|
|
handleAnimationEnd: AnyToVoidFunction, |
|
|
|
listenerSetter?: ListenerSetter |
|
|
|
listenerSetter?: ListenerSetter |
|
|
|
) => { |
|
|
|
) { |
|
|
|
//useEffect(() => {
|
|
|
|
//useEffect(() => {
|
|
|
|
if(isAnimating) { |
|
|
|
if(isAnimating) { |
|
|
|
handleAnimationStart(); |
|
|
|
handleAnimationStart(); |
|
|
@ -78,4 +98,4 @@ export default ( |
|
|
|
remove(ANIMATION_START_EVENT, handleAnimationStart); |
|
|
|
remove(ANIMATION_START_EVENT, handleAnimationStart); |
|
|
|
}; |
|
|
|
}; |
|
|
|
//}, [handleAnimationEnd, handleAnimationStart]);
|
|
|
|
//}, [handleAnimationEnd, handleAnimationStart]);
|
|
|
|
}; |
|
|
|
} |
|
|
|