mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: format
This commit is contained in:
@@ -3,14 +3,14 @@
|
||||
* @argument time Time of the current frame in milliseconds
|
||||
*/
|
||||
export interface FrameRequestCallback {
|
||||
(time: number): void;
|
||||
(time: number): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests an animation frame and returns the timer ID
|
||||
* @param cb Callback to be called on frame
|
||||
*/
|
||||
export function requestAnimationFrame(cb: FrameRequestCallback): number
|
||||
export function requestAnimationFrame(cb: FrameRequestCallback): number;
|
||||
|
||||
/**
|
||||
* Cancels a previously scheduled animation frame request
|
||||
|
||||
@@ -2,7 +2,7 @@ import { FPSCallback } from "../fps-meter/fps-native";
|
||||
import { getTimeInFrameBase } from "./animation-native";
|
||||
|
||||
export interface FrameRequestCallback {
|
||||
(time: number): void;
|
||||
(time: number): void;
|
||||
}
|
||||
|
||||
let animationId = 0;
|
||||
@@ -13,50 +13,52 @@ let fpsCallback: FPSCallback;
|
||||
let lastFrameTime = 0;
|
||||
|
||||
function getNewId() {
|
||||
return animationId++;
|
||||
return animationId++;
|
||||
}
|
||||
|
||||
function ensureNative() {
|
||||
if (fpsCallback) {
|
||||
return;
|
||||
}
|
||||
fpsCallback = new FPSCallback(doFrame);
|
||||
if (fpsCallback) {
|
||||
return;
|
||||
}
|
||||
fpsCallback = new FPSCallback(doFrame);
|
||||
}
|
||||
|
||||
function doFrame(currentTimeMillis: number) {
|
||||
lastFrameTime = currentTimeMillis;
|
||||
shouldStop = true;
|
||||
const thisFrameCbs = nextFrameAnimationCallbacks;
|
||||
nextFrameAnimationCallbacks = {};
|
||||
inAnimationFrame = true;
|
||||
for (const animationId in thisFrameCbs) {
|
||||
if (thisFrameCbs[animationId]) {
|
||||
thisFrameCbs[animationId](lastFrameTime);
|
||||
}
|
||||
}
|
||||
inAnimationFrame = false;
|
||||
if (shouldStop) {
|
||||
fpsCallback.stop(); // TODO: check performance without stopping to allow consistent frame times
|
||||
}
|
||||
lastFrameTime = currentTimeMillis;
|
||||
shouldStop = true;
|
||||
const thisFrameCbs = nextFrameAnimationCallbacks;
|
||||
nextFrameAnimationCallbacks = {};
|
||||
inAnimationFrame = true;
|
||||
for (const animationId in thisFrameCbs) {
|
||||
if (thisFrameCbs[animationId]) {
|
||||
thisFrameCbs[animationId](lastFrameTime);
|
||||
}
|
||||
}
|
||||
inAnimationFrame = false;
|
||||
if (shouldStop) {
|
||||
fpsCallback.stop(); // TODO: check performance without stopping to allow consistent frame times
|
||||
}
|
||||
}
|
||||
|
||||
export function requestAnimationFrame(cb: FrameRequestCallback): number {
|
||||
if (!inAnimationFrame) {
|
||||
inAnimationFrame = true;
|
||||
zonedCallback(cb)(getTimeInFrameBase()); // TODO: store and use lastFrameTime
|
||||
inAnimationFrame = false;
|
||||
if (!inAnimationFrame) {
|
||||
inAnimationFrame = true;
|
||||
zonedCallback(cb)(getTimeInFrameBase()); // TODO: store and use lastFrameTime
|
||||
inAnimationFrame = false;
|
||||
|
||||
return getNewId();
|
||||
}
|
||||
ensureNative();
|
||||
const animId = getNewId();
|
||||
nextFrameAnimationCallbacks[animId] = zonedCallback(cb) as FrameRequestCallback;
|
||||
shouldStop = false;
|
||||
fpsCallback.start();
|
||||
return getNewId();
|
||||
}
|
||||
ensureNative();
|
||||
const animId = getNewId();
|
||||
nextFrameAnimationCallbacks[animId] = zonedCallback(
|
||||
cb
|
||||
) as FrameRequestCallback;
|
||||
shouldStop = false;
|
||||
fpsCallback.start();
|
||||
|
||||
return animId;
|
||||
return animId;
|
||||
}
|
||||
|
||||
export function cancelAnimationFrame(id: number) {
|
||||
delete nextFrameAnimationCallbacks[id];
|
||||
delete nextFrameAnimationCallbacks[id];
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
export function getTimeInFrameBase(): number {
|
||||
return java.lang.System.nanoTime() / 1000000;
|
||||
return java.lang.System.nanoTime() / 1000000;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
* Gets the time in millisseconds in the same base as frames
|
||||
*/
|
||||
export function getTimeInFrameBase(): number;
|
||||
export function getTimeInFrameBase(): number;
|
||||
|
||||
Reference in New Issue
Block a user