react-native/Libraries/Utilities/SceneTracker.js
Spencer Ahrens f72d9dd08b Add option to track when we're showing blankness during fast scrolling
Summary:
If tracking is enabled and the sampling check passes on a scroll or layout event,
we compare the scroll offset to the layout of the rendered items. If the items don't cover
the visible area of the list, we fire an `onFillRateExceeded` call with relevant stats for
logging the event through an analytics pipeline.

The measurement methodology is a little jank because everything is async, but it seems directionally
useful for getting ballpark numbers, catching regressions, and tracking improvements.

Benchmark testing shows a ~2014 MotoX starts hitting the fill rate limit at about 2500 px / sec,
which is pretty fast scrolling.

This also reworks our frame rate stuff so we can use a shared `SceneTracking` thing and track blankness
globally.

Reviewed By: bvaughn

Differential Revision: D4806867

fbshipit-source-id: 119bf177463c8c3aa51fa13d1a9d03b1a96042aa
2017-04-07 01:00:39 -07:00

42 lines
989 B
JavaScript

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule SceneTracker
* @flow
*/
'use strict';
type Scene = {name: string};
let _listeners: Array<(scene: Scene) => void> = [];
let _activeScene = {name: 'default'};
const SceneTracker = {
setActiveScene(scene: Scene) {
_activeScene = scene;
_listeners.forEach((listener) => listener(_activeScene));
},
getActiveScene(): Scene {
return _activeScene;
},
addActiveSceneChangedListener(callback: (scene: Scene) => void): {remove: () => void} {
_listeners.push(callback);
return {
remove: () => {
_listeners = _listeners.filter((listener) => callback !== listener);
},
};
},
};
module.exports = SceneTracker;