Skip to content

Commit

Permalink
Add functions to host config
Browse files Browse the repository at this point in the history
add getCurrentEventStartTime and scheduleTransitionCallbacks to host configs
  • Loading branch information
lunaruan committed Jan 12, 2022
1 parent a014d90 commit 8bc65be
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/react-art/src/ReactARTHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,11 @@ export function preparePortalMount(portalInstance: any): void {
export function detachDeletedInstance(node: Instance): void {
// noop
}

export function getCurrentEventStartTime() {
// noop
}

export function scheduleTransitionCallbacks(callback, pendingTransitions) {
// noop
}
29 changes: 29 additions & 0 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ import {HostComponent, HostText} from 'react-reconciler/src/ReactWorkTags';
import {listenToAllSupportedEvents} from '../events/DOMPluginEventSystem';

import {DefaultEventPriority} from 'react-reconciler/src/ReactEventPriorities';
import {
now,
scheduleCallback,
IdlePriority,
} from 'react-reconciler/src/Scheduler';

export type Type = string;
export type Props = {
Expand Down Expand Up @@ -1241,3 +1246,27 @@ export function setupIntersectionObserver(
},
};
}

export function getCurrentEventStartTime(): number {
const event = window.event;
if (event === undefined) {
return now();
}
return event.timeStamp;
}

// TODO(luna) Fix this because rAF doesn't actually do
// what you want here
export function scheduleTransitionCallbacks(
callback: (Array<{}>, endTime: number) => void,
// TODO(luna) Figure out type of this
pendingTransitions: Array<{}>,
): void {
window.requestAnimationFrame(() => {
const endTime = now();

scheduleCallback(IdlePriority, () => {
callback(pendingTransitions, endTime);
});
});
}
8 changes: 8 additions & 0 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,11 @@ export function preparePortalMount(portalInstance: Instance): void {
export function detachDeletedInstance(node: Instance): void {
// noop
}

export function getCurrentEventStartTime() {
// noop
}

export function scheduleTransitionCallbacks(callback, pendingTransitions) {
// noop
}
8 changes: 8 additions & 0 deletions packages/react-native-renderer/src/ReactNativeHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,3 +513,11 @@ export function preparePortalMount(portalInstance: Instance): void {
export function detachDeletedInstance(node: Instance): void {
// noop
}

export function getCurrentEventStartTime() {
// noop
}

export function scheduleTransitionCallbacks(callback, pendingTransitions) {
// noop
}
6 changes: 6 additions & 0 deletions packages/react-noop-renderer/src/createReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,12 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
},

detachDeletedInstance() {},

getCurrentEventStartTime() {
return Scheduler.unstable_now();
},

scheduleTransitionCallbacks(callback, pendingTransitions) {},
};

const hostConfig = useMutation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,11 @@ export const didNotFindHydratableTextInstance =
export const didNotFindHydratableSuspenseInstance =
$$$hostConfig.didNotFindHydratableSuspenseInstance;
export const errorHydratingContainer = $$$hostConfig.errorHydratingContainer;

// -------------------
// Transition Tracing
// (optional)
// -------------------
export const getCurrentEventStartTime = $$$hostConfig.getCurrentEventStartTime;
export const scheduleTransitionCallbacks =
$$$hostConfig.scheduleTransitionCallbacks;
8 changes: 8 additions & 0 deletions packages/react-test-renderer/src/ReactTestHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,11 @@ export function getInstanceFromScope(scopeInstance: Object): null | Object {
export function detachDeletedInstance(node: Instance): void {
// noop
}

export function getCurrentEventStartTime() {
// noop
}

export function scheduleTransitionCallbacks(callback, pendingTransitions) {
// noop
}

0 comments on commit 8bc65be

Please sign in to comment.