Skip to content

Commit 6515ada

Browse files
CalixTangmeta-codesync[bot]
authored andcommitted
Add logging interface, context, callbacks to VirtualView (facebook#54392)
Summary: Pull Request resolved: facebook#54392 ## Changelog: [Internal] Adds a VirtualView-specific logging interface, related default implementation within hook. Uses returned callbacks in VirtualView to do lifecycle-related logging. ### Public API Change Changes `ModeChangeEvent` (defined in `VirtualView.js`) to include a field for the Virtual View's current `VirtualViewRenderState`. Reviewed By: lunaleaps Differential Revision: D85712933 fbshipit-source-id: 0bc7a9f0a10e1e801f235975ba179832306815d7
1 parent 91d4332 commit 6515ada

File tree

4 files changed

+77
-11
lines changed

4 files changed

+77
-11
lines changed

packages/react-native/ReactNativeApi.d.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<4e0d1f9ebc86fb237989b7099bf6f9df>>
7+
* @generated SignedSource<<a01aee11d06658fe06d702ee4c48bf8e>>
88
*
99
* This file was generated by scripts/js-api/build-types/index.js.
1010
*/
@@ -3188,6 +3188,7 @@ declare type ModalRefProps = {
31883188
declare type ModeChangeEvent = Readonly<
31893189
Omit<NativeModeChangeEvent, "mode"> & {
31903190
mode: VirtualViewMode
3191+
renderState: VirtualViewRenderState
31913192
target: HostInstance
31923193
}
31933194
>
@@ -5838,6 +5839,19 @@ declare namespace VirtualViewMode {
58385839
export function members(): IterableIterator<VirtualViewMode>
58395840
export function getName(value: VirtualViewMode): string
58405841
}
5842+
declare enum VirtualViewRenderState {
5843+
None = 2,
5844+
Rendered = 1,
5845+
Unknown = 0,
5846+
}
5847+
declare namespace VirtualViewRenderState {
5848+
function cast(value: null | number | undefined): VirtualViewRenderState
5849+
function isValid(
5850+
value: null | number | undefined,
5851+
): value is VirtualViewRenderState
5852+
function members(): IterableIterator<VirtualViewRenderState>
5853+
function getName(value: VirtualViewRenderState): string
5854+
}
58415855
declare type WebPlatform = {
58425856
OS: "web"
58435857
select: <T>(spec: PlatformSelectSpec<T>) => T
@@ -6038,7 +6052,7 @@ export {
60386052
ModalProps, // 270223fa
60396053
ModalPropsAndroid, // 515fb173
60406054
ModalPropsIOS, // 4fbcedf6
6041-
ModeChangeEvent, // b889a7ce
6055+
ModeChangeEvent, // af2c4926
60426056
MouseEvent, // 53ede3db
60436057
NativeAppEventEmitter, // b4d20c1d
60446058
NativeColorValue, // d2094c29

packages/react-native/src/private/components/virtualview/VirtualView.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {NativeModeChangeEvent} from './VirtualViewNativeComponent';
1515

1616
import StyleSheet from '../../../../Libraries/StyleSheet/StyleSheet';
1717
import * as ReactNativeFeatureFlags from '../../featureflags/ReactNativeFeatureFlags';
18+
import {useVirtualViewLogging} from './logger/VirtualViewLogger';
1819
import VirtualViewExperimentalNativeComponent from './VirtualViewExperimentalNativeComponent';
1920
import VirtualViewClassicNativeComponent from './VirtualViewNativeComponent';
2021
import nullthrows from 'nullthrows';
@@ -45,6 +46,7 @@ export type Rect = $ReadOnly<{
4546

4647
export type ModeChangeEvent = $ReadOnly<{
4748
...Omit<NativeModeChangeEvent, 'mode'>,
49+
renderState: VirtualViewRenderState,
4850
mode: VirtualViewMode,
4951
target: HostInstance,
5052
}>;
@@ -90,21 +92,26 @@ function createVirtualView(initialState: State): VirtualViewComponent {
9092
_logs.states?.push(state);
9193
}
9294
const isHidden = state !== NotHidden;
95+
const loggingCallbacksRef = useVirtualViewLogging(isHidden, nativeID);
9396

9497
const handleModeChange = (
9598
event: NativeSyntheticEvent<NativeModeChangeEvent>,
9699
) => {
97100
const mode = nullthrows(VirtualViewMode.cast(event.nativeEvent.mode));
101+
const modeChangeEvent: ModeChangeEvent = {
102+
mode,
103+
renderState: isHidden
104+
? VirtualViewRenderState.None
105+
: VirtualViewRenderState.Rendered,
106+
// $FlowFixMe[incompatible-type] - we know this is a HostInstance
107+
target: event.currentTarget as HostInstance,
108+
targetRect: event.nativeEvent.targetRect,
109+
thresholdRect: event.nativeEvent.thresholdRect,
110+
};
111+
loggingCallbacksRef.current?.logModeChange(modeChangeEvent);
112+
98113
const emitModeChange =
99-
onModeChange == null
100-
? null
101-
: onModeChange.bind(null, {
102-
mode,
103-
// $FlowFixMe[incompatible-type] - we know this is a HostInstance
104-
target: event.currentTarget as HostInstance,
105-
targetRect: event.nativeEvent.targetRect,
106-
thresholdRect: event.nativeEvent.thresholdRect,
107-
});
114+
onModeChange == null ? null : onModeChange.bind(null, modeChangeEvent);
108115

109116
match (mode) {
110117
VirtualViewMode.Visible => {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 strict-local
8+
* @format
9+
* @oncall react_native
10+
*/
11+
12+
import type {IVirtualViewLogFunctions} from './VirtualViewLoggerTypes';
13+
14+
import {useRef} from 'react';
15+
16+
export hook useVirtualViewLogging(
17+
initiallyHidden: boolean,
18+
nativeID?: string,
19+
): React.RefObject<?IVirtualViewLogFunctions> {
20+
return useRef(null);
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 strict-local
8+
* @format
9+
* @oncall react_native
10+
*/
11+
12+
import type {ModeChangeEvent} from '../../../../..';
13+
14+
export interface IVirtualViewLogFunctions {
15+
logMount: () => void;
16+
logModeChange: (event: ModeChangeEvent) => void;
17+
logUnmount: () => void;
18+
}
19+
export interface IVirtualViewLogger {
20+
getVirtualViewLoggingCallbacks(
21+
initiallyHidden: boolean,
22+
nativeID?: string,
23+
): IVirtualViewLogFunctions;
24+
}

0 commit comments

Comments
 (0)