Add areChildrenOffscreen to host config

Renderers can determine whether a node's children are offscreen based on
the host component's props. If so, they are given OffscreenPriority.

useSyncScheduling takes precedence.
This commit is contained in:
Andrew Clark
2017-03-01 10:56:31 -08:00
committed by Andrew Clark
parent 4ef197b7d4
commit 4602e768f3
7 changed files with 26 additions and 4 deletions
+4
View File
@@ -503,6 +503,10 @@ const ARTRenderer = ReactFiberReconciler({
// Noop
},
areChildrenOffscreen(props : Props) {
return false;
},
getRootHostContext() {
return emptyObject;
},
+5
View File
@@ -69,6 +69,7 @@ type Container = Element;
type Props = {
autoFocus ?: boolean,
children ?: mixed,
hidden ?: boolean,
};
type Instance = Element;
type TextInstance = Text;
@@ -286,6 +287,10 @@ var DOMRenderer = ReactFiberReconciler({
domElement.textContent = '';
},
areChildrenOffscreen(props : Props) : boolean {
return Boolean(props.hidden);
},
createTextInstance(
text : string,
rootContainerInstance : Container,
+4
View File
@@ -343,6 +343,10 @@ const NativeRenderer = ReactFiberReconciler({
// Noop
},
areChildrenOffscreen(props : Props) : boolean {
return false;
},
scheduleAnimationCallback: global.requestAnimationFrame,
scheduleDeferredCallback: global.requestIdleCallback,
+5 -1
View File
@@ -35,7 +35,7 @@ var scheduledAnimationCallback = null;
var scheduledDeferredCallback = null;
type Container = { rootID: string, children: Array<Instance | TextInstance> };
type Props = { prop: any };
type Props = { prop: any, hidden ?: boolean };
type Instance = {| type: string, id: number, children: Array<Instance | TextInstance>, prop: any |};
type TextInstance = {| text: string, id: number |};
@@ -101,6 +101,10 @@ var NoopRenderer = ReactFiberReconciler({
resetTextContent(instance : Instance) : void {},
areChildrenOffscreen(props : Props) : boolean {
return Boolean(props.hidden);
},
createTextInstance(
text : string,
rootContainerInstance : Container,
@@ -77,7 +77,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
getPriorityContext : () => PriorityLevel,
) {
const { shouldSetTextContent, useSyncScheduling } = config;
const { shouldSetTextContent, useSyncScheduling, areChildrenOffscreen } = config;
const {
pushHostContext,
@@ -358,7 +358,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
}
} else if (nextProps === null || memoizedProps === nextProps) {
if (!useSyncScheduling &&
memoizedProps.hidden &&
areChildrenOffscreen(memoizedProps) &&
workInProgress.pendingWorkPriority !== OffscreenPriority) {
// This subtree still has work, but it should be deprioritized so we need
// to bail out and not do any work yet.
@@ -400,7 +400,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
markRef(current, workInProgress);
if (!useSyncScheduling &&
nextProps.hidden &&
areChildrenOffscreen(nextProps) &&
workInProgress.pendingWorkPriority !== OffscreenPriority) {
// If this host component is hidden, we can bail out on the children.
// We'll rerender the children later at the lower priority.
@@ -83,6 +83,7 @@ export type HostConfig<T, P, I, TI, PI, C, CX, PL> = {
shouldSetTextContent(props : P) : boolean,
resetTextContent(instance : I) : void,
areChildrenOffscreen(props : P) : boolean,
createTextInstance(
text : string,
@@ -150,6 +150,10 @@ var TestRenderer = ReactFiberReconciler({
// noop
},
areChildrenOffscreen(props : Props) : boolean {
return false;
},
createTextInstance(
text : string,
rootContainerInstance : Container,