-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Summary Logic related with managing time when recording AnimationUpdates was moved to a separate file. Also I delete the following functions: * `public async setAnimationTimestamp` * `public async advanceAnimationByTime` * `public async advanceAnimationByFrames` ## Test plan
- Loading branch information
Showing
3 changed files
with
127 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
apps/common-app/src/examples/RuntimeTests/ReJest/TestRunner/AnimationUpdatesRecorder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import type { Operation } from '../types'; | ||
import { SyncUIRunner } from '../utils/SyncUIRunner'; | ||
import { createUpdatesContainer } from './UpdatesContainer'; | ||
|
||
export class AnimationUpdatesRecorder { | ||
private _syncUIRunner: SyncUIRunner = new SyncUIRunner(); | ||
|
||
public async recordAnimationUpdates() { | ||
const updatesContainer = createUpdatesContainer(); | ||
const recordAnimationUpdates = updatesContainer.pushAnimationUpdates; | ||
const recordLayoutAnimationUpdates = updatesContainer.pushLayoutAnimationUpdates; | ||
|
||
await this._syncUIRunner.runOnUIBlocking(() => { | ||
'worklet'; | ||
const originalUpdateProps = global._IS_FABRIC ? global._updatePropsFabric : global._updatePropsPaper; | ||
global.originalUpdateProps = originalUpdateProps; | ||
|
||
const mockedUpdateProps = (operations: Operation[]) => { | ||
recordAnimationUpdates(operations); | ||
originalUpdateProps(operations); | ||
}; | ||
|
||
if (global._IS_FABRIC) { | ||
global._updatePropsFabric = mockedUpdateProps; | ||
} else { | ||
global._updatePropsPaper = mockedUpdateProps; | ||
} | ||
|
||
const originalNotifyAboutProgress = global._notifyAboutProgress; | ||
global.originalNotifyAboutProgress = originalNotifyAboutProgress; | ||
global._notifyAboutProgress = (tag: number, value: Record<string, unknown>, isSharedTransition: boolean) => { | ||
recordLayoutAnimationUpdates(tag, value); | ||
originalNotifyAboutProgress(tag, value, isSharedTransition); | ||
}; | ||
}); | ||
return updatesContainer; | ||
} | ||
|
||
public async stopRecordingAnimationUpdates() { | ||
await this._syncUIRunner.runOnUIBlocking(() => { | ||
'worklet'; | ||
if (global.originalUpdateProps) { | ||
if (global._IS_FABRIC) { | ||
global._updatePropsFabric = global.originalUpdateProps; | ||
} else { | ||
global._updatePropsPaper = global.originalUpdateProps; | ||
} | ||
global.originalUpdateProps = undefined; | ||
} | ||
if (global.originalNotifyAboutProgress) { | ||
global._notifyAboutProgress = global.originalNotifyAboutProgress; | ||
global.originalNotifyAboutProgress = undefined; | ||
} | ||
}); | ||
} | ||
|
||
public async mockAnimationTimer() { | ||
await this._syncUIRunner.runOnUIBlocking(() => { | ||
'worklet'; | ||
global.mockedAnimationTimestamp = 0; | ||
global.originalGetAnimationTimestamp = global._getAnimationTimestamp; | ||
global._getAnimationTimestamp = () => { | ||
if (global.mockedAnimationTimestamp === undefined) { | ||
throw new Error("Animation timestamp wasn't initialized"); | ||
} | ||
return global.mockedAnimationTimestamp; | ||
}; | ||
global.framesCount = 0; | ||
|
||
const originalRequestAnimationFrame = global.requestAnimationFrame; | ||
global.originalRequestAnimationFrame = originalRequestAnimationFrame; | ||
global.requestAnimationFrame = (callback: FrameRequestCallback) => { | ||
originalRequestAnimationFrame(() => { | ||
callback(global._getAnimationTimestamp()); | ||
}); | ||
return 0; | ||
}; | ||
|
||
global.originalFlushAnimationFrame = global.__flushAnimationFrame; | ||
global.__flushAnimationFrame = (_frameTimestamp: number) => { | ||
global.mockedAnimationTimestamp! += 16; | ||
global.__frameTimestamp = global.mockedAnimationTimestamp; | ||
global.originalFlushAnimationFrame!(global.mockedAnimationTimestamp!); | ||
global.framesCount!++; | ||
}; | ||
}); | ||
} | ||
|
||
public async unmockAnimationTimer() { | ||
await this._syncUIRunner.runOnUIBlocking(() => { | ||
'worklet'; | ||
if (global.originalGetAnimationTimestamp) { | ||
global._getAnimationTimestamp = global.originalGetAnimationTimestamp; | ||
global.originalGetAnimationTimestamp = undefined; | ||
} | ||
if (global.originalRequestAnimationFrame) { | ||
(global.requestAnimationFrame as any) = global.originalRequestAnimationFrame; | ||
global.originalRequestAnimationFrame = undefined; | ||
} | ||
if (global.originalFlushAnimationFrame) { | ||
global.__flushAnimationFrame = global.originalFlushAnimationFrame; | ||
global.originalFlushAnimationFrame = undefined; | ||
} | ||
if (global.mockedAnimationTimestamp) { | ||
global.mockedAnimationTimestamp = undefined; | ||
} | ||
if (global.framesCount) { | ||
global.framesCount = undefined; | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters