| 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 |
| 8 | */ |
| 9 | |
| 10 | import type {ReactNodeList, Wakeable} from 'shared/ReactTypes'; |
| 11 | import type {Lanes} from './ReactFiberLane'; |
| 12 | import type {SpawnedCachePool} from './ReactFiberCacheComponent'; |
| 13 | import type {Transition} from 'react/src/ReactStartTransition'; |
| 14 | import type {TracingMarkerInstance} from './ReactFiberTracingMarkerComponent'; |
| 15 | import type {RetryQueue} from './ReactFiberSuspenseComponent'; |
| 16 | |
| 17 | type OffscreenMode = 'hidden' | 'unstable-defer-without-hiding' | 'visible'; |
| 18 | |
| 19 | export type LegacyHiddenProps = { |
| 20 | mode?: OffscreenMode | null | void, |
| 21 | children?: ReactNodeList, |
| 22 | }; |
| 23 | |
| 24 | export type OffscreenProps = { |
| 25 | // TODO: Pick an API before exposing the Offscreen type. I've chosen an enum |
| 26 | // for now, since we might have multiple variants. For example, hiding the |
| 27 | // content without changing the layout. |
| 28 | // |
| 29 | // Default mode is visible. Kind of a weird default for a component |
| 30 | // called "Offscreen." Possible alt: <Visibility />? |
| 31 | mode?: OffscreenMode | null | void, |
| 32 | children?: ReactNodeList, |
| 33 | }; |
| 34 | |
| 35 | // We use the existence of the state object as an indicator that the component |
| 36 | // is hidden. |
| 37 | export type OffscreenState = { |
| 38 | // TODO: This doesn't do anything, yet. It's always NoLanes. But eventually it |
| 39 | // will represent the pending work that must be included in the render in |
| 40 | // order to unhide the component. |
| 41 | baseLanes: Lanes, |
| 42 | cachePool: SpawnedCachePool | null, |
| 43 | }; |
| 44 | |
| 45 | export type OffscreenQueue = { |
| 46 | transitions: Array<Transition> | null, |
| 47 | markerInstances: Array<TracingMarkerInstance> | null, |
| 48 | retryQueue: RetryQueue | null, |
| 49 | }; |
| 50 | |
| 51 | type OffscreenVisibility = number; |
| 52 | |
| 53 | export const OffscreenVisible = /* */ 0b001; |
| 54 | export const OffscreenPassiveEffectsConnected = /* */ 0b010; |
| 55 | |
| 56 | export type OffscreenInstance = { |
| 57 | _visibility: OffscreenVisibility, |
| 58 | _pendingMarkers: Set<TracingMarkerInstance> | null, |
| 59 | _transitions: Set<Transition> | null, |
| 60 | _retryCache: WeakSet<Wakeable> | Set<Wakeable> | null, |
| 61 | }; |