mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
484f62a71f
Summary: ## This diff - Add a hybird scene tracker that support both native navigation and js navigation - It also has a filter that bypass loading routes and unrelated routes like log box - The tracker can provide exactly what surface user is looking at Changelog: [Internal] Differential Revision: D19667699 fbshipit-source-id: 600efd05e68bf2702c6c2b1d794e720059f75f81
42 lines
877 B
JavaScript
42 lines
877 B
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow strict
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
export 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;
|