@@ -74,10 +74,11 @@ import {
7474} from 'react-reconciler/src/ReactWorkTags' ;
7575import { listenToAllSupportedEvents } from '../events/DOMPluginEventSystem' ;
7676
77- import { DefaultEventPriority } from 'react-reconciler/src/ReactEventPriorities' ;
77+ import { UnknownEventPriority } from 'react-reconciler/src/ReactEventPriorities' ;
7878
7979// TODO: Remove this deep import when we delete the legacy root API
8080import { ConcurrentMode , NoMode } from 'react-reconciler/src/ReactTypeOfMode' ;
81+ import * as Scheduler from 'scheduler' ;
8182
8283import {
8384 prepareToRenderResources ,
@@ -373,7 +374,7 @@ export function createTextInstance(
373374export function getCurrentEventPriority ( ) : EventPriority {
374375 const currentEvent = window . event ;
375376 if ( currentEvent === undefined ) {
376- return DefaultEventPriority ;
377+ return UnknownEventPriority ;
377378 }
378379 return getEventPriority ( currentEvent . type ) ;
379380}
@@ -393,6 +394,11 @@ const localRequestAnimationFrame =
393394 typeof requestAnimationFrame === 'function'
394395 ? requestAnimationFrame
395396 : scheduleTimeout ;
397+ const localCancelAnimationFrame =
398+ typeof window !== 'undefined' &&
399+ typeof window . cancelAnimationFrame === 'function'
400+ ? window . cancelAnimationFrame
401+ : cancelTimeout ;
396402// -------------------
397403// Microtasks
398404// -------------------
@@ -408,6 +414,39 @@ export const scheduleMicrotask: any =
408414 . catch ( handleErrorInNextTick )
409415 : scheduleTimeout ; // TODO: Determine the best fallback here.
410416
417+ // -------------------
418+ // requestAnimationFrame
419+ // -------------------
420+ type FrameAlignedTask = {
421+ frameNode : any ,
422+ callbackNode : any ,
423+ } ;
424+
425+ // TODO: Fix these types
426+ export const supportsFrameAlignedTask = true ;
427+ export function scheduleFrameAlignedTask ( task : any ) : FrameAlignedTask {
428+ // Schedule both tasks, we'll race them and use the first to fire.
429+ const raf : any = localRequestAnimationFrame ;
430+
431+ return {
432+ frameNode : raf ( task ) ,
433+ callbackNode : Scheduler . unstable_scheduleCallback (
434+ Scheduler . unstable_NormalPriority ,
435+ task ,
436+ ) ,
437+ } ;
438+ }
439+ export function cancelFrameAlignedTask ( task : any ) {
440+ const caf : any = localCancelAnimationFrame ;
441+ if ( task . frameNode != null ) {
442+ caf ( task . frameNode ) ;
443+ }
444+
445+ if ( task . callbackNode != null ) {
446+ Scheduler . unstable_cancelCallback ( task . callbackNode ) ;
447+ }
448+ }
449+
411450function handleErrorInNextTick ( error ) {
412451 setTimeout ( ( ) => {
413452 throw error ;
0 commit comments