Add Offscreen component type

Doesn't do anything special in this initial commit. Just acts like a
fragment.
This commit is contained in:
Luna Ruan
2020-04-23 12:53:46 -07:00
committed by Andrew Clark
parent 1df756ba2c
commit ed01fdacce
5 changed files with 58 additions and 1 deletions
@@ -54,6 +54,7 @@ import {
FundamentalComponent,
ScopeComponent,
Block,
OffscreenComponent,
} from './ReactWorkTags';
import getComponentName from 'shared/getComponentName';
@@ -87,6 +88,7 @@ import {
REACT_FUNDAMENTAL_TYPE,
REACT_SCOPE_TYPE,
REACT_BLOCK_TYPE,
REACT_OFFSCREEN_TYPE,
} from 'shared/ReactSymbols';
export type {Fiber};
@@ -511,6 +513,13 @@ export function createFiberFromTypeAndProps(
expirationTime,
key,
);
case REACT_OFFSCREEN_TYPE:
return createFiberFromOffscreen(
pendingProps,
mode,
expirationTime,
key,
);
default: {
if (typeof type === 'object' && type !== null) {
switch (type.$$typeof) {
@@ -728,6 +737,24 @@ export function createFiberFromSuspenseList(
return fiber;
}
export function createFiberFromOffscreen(
pendingProps: any,
mode: TypeOfMode,
expirationTime: ExpirationTimeOpaque,
key: null | string,
) {
const fiber = createFiber(OffscreenComponent, pendingProps, key, mode);
// TODO: The OffscreenComponent fiber shouldn't have a type. It has a tag.
// This needs to be fixed in getComponentName so that it relies on the tag
// instead.
if (__DEV__) {
fiber.type = REACT_OFFSCREEN_TYPE;
}
fiber.elementType = REACT_OFFSCREEN_TYPE;
fiber.expirationTime_opaque = expirationTime;
return fiber;
}
export function createFiberFromText(
content: string,
mode: TypeOfMode,
@@ -45,6 +45,7 @@ import {
FundamentalComponent,
ScopeComponent,
Block,
OffscreenComponent,
} from './ReactWorkTags';
import {
NoEffect,
@@ -555,6 +556,21 @@ function updateSimpleMemoComponent(
);
}
function updateOffscreenComponent(
current: Fiber | null,
workInProgress: Fiber,
renderExpirationTime: ExpirationTimeOpaque,
) {
const nextChildren = workInProgress.pendingProps;
reconcileChildren(
current,
workInProgress,
nextChildren,
renderExpirationTime,
);
return workInProgress.child;
}
function updateFragment(
current: Fiber | null,
workInProgress: Fiber,
@@ -3448,6 +3464,13 @@ function beginWork(
renderExpirationTime,
);
}
case OffscreenComponent: {
return updateOffscreenComponent(
current,
workInProgress,
renderExpirationTime,
);
}
case SimpleMemoComponent: {
return updateSimpleMemoComponent(
current,
@@ -53,6 +53,7 @@ import {
FundamentalComponent,
ScopeComponent,
Block,
OffscreenComponent,
} from './ReactWorkTags';
import {NoMode, BlockingMode} from './ReactTypeOfMode';
import {Ref, Update, NoEffect, DidCapture} from './ReactSideEffectTags';
@@ -1287,6 +1288,8 @@ function completeWork(
return null;
}
break;
case OffscreenComponent:
return null;
}
invariant(
false,
+3 -1
View File
@@ -30,7 +30,8 @@ export type WorkTag =
| 19
| 20
| 21
| 22;
| 22
| 23;
export const FunctionComponent = 0;
export const ClassComponent = 1;
@@ -55,3 +56,4 @@ export const SuspenseListComponent = 19;
export const FundamentalComponent = 20;
export const ScopeComponent = 21;
export const Block = 22;
export const OffscreenComponent = 23;
+2
View File
@@ -32,6 +32,7 @@ export let REACT_RESPONDER_TYPE = 0xead6;
export let REACT_SCOPE_TYPE = 0xead7;
export let REACT_OPAQUE_ID_TYPE = 0xeae0;
export let REACT_DEBUG_TRACING_MODE_TYPE = 0xeae1;
export let REACT_OFFSCREEN_TYPE = 0xeae2;
if (typeof Symbol === 'function' && Symbol.for) {
const symbolFor = Symbol.for;
@@ -54,6 +55,7 @@ if (typeof Symbol === 'function' && Symbol.for) {
REACT_SCOPE_TYPE = symbolFor('react.scope');
REACT_OPAQUE_ID_TYPE = symbolFor('react.opaque.id');
REACT_DEBUG_TRACING_MODE_TYPE = symbolFor('react.debug_trace_mode');
REACT_OFFSCREEN_TYPE = symbolFor('react.offscreen');
}
const MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;