1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow strict
    
  8.  */
    
  9. 
    
  10. import * as Scheduler from './Scheduler';
    
  11. import type {Callback, Task} from './Scheduler';
    
  12. import type {PriorityLevel} from '../SchedulerPriorities';
    
  13. import typeof * as SchedulerExportsType from './Scheduler';
    
  14. import typeof * as SchedulerNativeExportsType from './SchedulerNative';
    
  15. 
    
  16. // This type is supposed to reflect the actual methods and arguments currently supported by the C++ implementation:
    
  17. // https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeSchedulerBinding.cpp
    
  18. type NativeSchedulerType = {
    
  19.   unstable_ImmediatePriority: PriorityLevel,
    
  20.   unstable_UserBlockingPriority: PriorityLevel,
    
  21.   unstable_NormalPriority: PriorityLevel,
    
  22.   unstable_IdlePriority: PriorityLevel,
    
  23.   unstable_LowPriority: PriorityLevel,
    
  24.   unstable_scheduleCallback: (
    
  25.     priorityLevel: PriorityLevel,
    
  26.     callback: Callback,
    
  27.   ) => Task,
    
  28.   unstable_cancelCallback: (task: Task) => void,
    
  29.   unstable_getCurrentPriorityLevel: () => PriorityLevel,
    
  30.   unstable_shouldYield: () => boolean,
    
  31.   unstable_requestPaint: () => void,
    
  32.   unstable_now: () => DOMHighResTimeStamp,
    
  33. };
    
  34. 
    
  35. declare var nativeRuntimeScheduler: void | NativeSchedulerType;
    
  36. 
    
  37. export const unstable_UserBlockingPriority: PriorityLevel =
    
  38.   typeof nativeRuntimeScheduler !== 'undefined'
    
  39.     ? nativeRuntimeScheduler.unstable_UserBlockingPriority
    
  40.     : Scheduler.unstable_UserBlockingPriority;
    
  41. 
    
  42. export const unstable_NormalPriority: PriorityLevel =
    
  43.   typeof nativeRuntimeScheduler !== 'undefined'
    
  44.     ? nativeRuntimeScheduler.unstable_NormalPriority
    
  45.     : Scheduler.unstable_NormalPriority;
    
  46. 
    
  47. export const unstable_IdlePriority: PriorityLevel =
    
  48.   typeof nativeRuntimeScheduler !== 'undefined'
    
  49.     ? nativeRuntimeScheduler.unstable_IdlePriority
    
  50.     : Scheduler.unstable_IdlePriority;
    
  51. 
    
  52. export const unstable_LowPriority: PriorityLevel =
    
  53.   typeof nativeRuntimeScheduler !== 'undefined'
    
  54.     ? nativeRuntimeScheduler.unstable_LowPriority
    
  55.     : Scheduler.unstable_LowPriority;
    
  56. 
    
  57. export const unstable_ImmediatePriority: PriorityLevel =
    
  58.   typeof nativeRuntimeScheduler !== 'undefined'
    
  59.     ? nativeRuntimeScheduler.unstable_ImmediatePriority
    
  60.     : Scheduler.unstable_ImmediatePriority;
    
  61. 
    
  62. export const unstable_scheduleCallback: (
    
  63.   priorityLevel: PriorityLevel,
    
  64.   callback: Callback,
    
  65. ) => Task =
    
  66.   typeof nativeRuntimeScheduler !== 'undefined'
    
  67.     ? nativeRuntimeScheduler.unstable_scheduleCallback
    
  68.     : Scheduler.unstable_scheduleCallback;
    
  69. 
    
  70. export const unstable_cancelCallback: (task: Task) => void =
    
  71.   typeof nativeRuntimeScheduler !== 'undefined'
    
  72.     ? nativeRuntimeScheduler.unstable_cancelCallback
    
  73.     : Scheduler.unstable_cancelCallback;
    
  74. 
    
  75. export const unstable_getCurrentPriorityLevel: () => PriorityLevel =
    
  76.   typeof nativeRuntimeScheduler !== 'undefined'
    
  77.     ? nativeRuntimeScheduler.unstable_getCurrentPriorityLevel
    
  78.     : Scheduler.unstable_getCurrentPriorityLevel;
    
  79. 
    
  80. export const unstable_shouldYield: () => boolean =
    
  81.   typeof nativeRuntimeScheduler !== 'undefined'
    
  82.     ? nativeRuntimeScheduler.unstable_shouldYield
    
  83.     : Scheduler.unstable_shouldYield;
    
  84. 
    
  85. export const unstable_requestPaint: () => void =
    
  86.   typeof nativeRuntimeScheduler !== 'undefined'
    
  87.     ? nativeRuntimeScheduler.unstable_requestPaint
    
  88.     : Scheduler.unstable_requestPaint;
    
  89. 
    
  90. export const unstable_now: () => number | DOMHighResTimeStamp =
    
  91.   typeof nativeRuntimeScheduler !== 'undefined'
    
  92.     ? nativeRuntimeScheduler.unstable_now
    
  93.     : Scheduler.unstable_now;
    
  94. 
    
  95. // These were never implemented on the native scheduler because React never calls them.
    
  96. // For consistency, let's disable them altogether and make them throw.
    
  97. export const unstable_next: any = throwNotImplemented;
    
  98. export const unstable_runWithPriority: any = throwNotImplemented;
    
  99. export const unstable_wrapCallback: any = throwNotImplemented;
    
  100. export const unstable_continueExecution: any = throwNotImplemented;
    
  101. export const unstable_pauseExecution: any = throwNotImplemented;
    
  102. export const unstable_getFirstCallbackNode: any = throwNotImplemented;
    
  103. export const unstable_forceFrameRate: any = throwNotImplemented;
    
  104. export const unstable_Profiling: any = null;
    
  105. 
    
  106. function throwNotImplemented() {
    
  107.   throw Error('Not implemented.');
    
  108. }
    
  109. 
    
  110. // Flow magic to verify the exports of this file match the original version.
    
  111. export type {Callback, Task};
    
  112. ((((null: any): SchedulerExportsType): SchedulerNativeExportsType): SchedulerExportsType);