Skip to content

Commit 91a8eb6

Browse files
yungstersfacebook-github-bot
authored andcommitted
Fling: Prepare to Eliminate "Experimental" Suffix (#55086)
Summary: Makes the necessary changes to prepare for an eventual rename of the `VirtualViewExperimental` component back to `VirtualView` (by checking whether `VirtualView` exists but `VirtualViewExperimental` does not). Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D90284497
1 parent 0941bd6 commit 91a8eb6

File tree

3 files changed

+119
-1
lines changed

3 files changed

+119
-1
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5240,6 +5240,17 @@ public abstract interface class com/facebook/react/viewmanagers/VirtualViewExper
52405240
public abstract fun setRenderState (Landroid/view/View;I)V
52415241
}
52425242

5243+
public class com/facebook/react/viewmanagers/VirtualViewManagerDelegate : com/facebook/react/uimanager/BaseViewManagerDelegate {
5244+
public fun <init> (Lcom/facebook/react/uimanager/BaseViewManager;)V
5245+
public fun setProperty (Landroid/view/View;Ljava/lang/String;Ljava/lang/Object;)V
5246+
}
5247+
5248+
public abstract interface class com/facebook/react/viewmanagers/VirtualViewManagerInterface : com/facebook/react/uimanager/ViewManagerWithGeneratedInterface {
5249+
public abstract fun setInitialHidden (Landroid/view/View;Z)V
5250+
public abstract fun setRemoveClippedSubviews (Landroid/view/View;Z)V
5251+
public abstract fun setRenderState (Landroid/view/View;I)V
5252+
}
5253+
52435254
public final class com/facebook/react/views/drawer/ReactDrawerLayout : androidx/drawerlayout/widget/DrawerLayout {
52445255
public fun <init> (Lcom/facebook/react/bridge/ReactContext;)V
52455256
public fun onInterceptTouchEvent (Landroid/view/MotionEvent;)Z

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import type {NativeSyntheticEvent} from '../../../../Libraries/Types/CoreEventTy
1313
import type {HostInstance} from '../../types/HostInstance';
1414
import type {NativeModeChangeEvent} from './VirtualViewExperimentalNativeComponent';
1515

16+
import UIManager from '../../../../Libraries/ReactNative/UIManager';
1617
import StyleSheet from '../../../../Libraries/StyleSheet/StyleSheet';
1718
import * as ReactNativeFeatureFlags from '../../featureflags/ReactNativeFeatureFlags';
1819
import {useVirtualViewLogging} from './logger/VirtualViewLogger';
19-
import VirtualViewNativeComponent from './VirtualViewExperimentalNativeComponent';
20+
import VirtualViewExperimentalNativeComponent from './VirtualViewExperimentalNativeComponent';
21+
import VirtualViewProperNativeComponent from './VirtualViewNativeComponent';
2022
import nullthrows from 'nullthrows';
2123
import * as React from 'react';
2224
// $FlowFixMe[missing-export]
@@ -50,6 +52,15 @@ export type ModeChangeEvent = Readonly<{
5052
target: HostInstance,
5153
}>;
5254

55+
// If `VirtualView` exists and `VirtualViewExperimental` does not, that means
56+
// the new version was renamed to `VirtualView`. Eventually, this can be deleted
57+
// with a single remaining import of `VirtualViewNativeComponent`.
58+
const VirtualViewNativeComponent: typeof VirtualViewExperimentalNativeComponent =
59+
UIManager.hasViewManagerConfig('VirtualView') &&
60+
!UIManager.hasViewManagerConfig('VirtualViewExperimental')
61+
? VirtualViewProperNativeComponent
62+
: VirtualViewExperimentalNativeComponent;
63+
5364
type VirtualViewComponent = component(
5465
children?: React.Node,
5566
hiddenStyle?: (targetRect: Rect) => ViewStyleProp,
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
*/
10+
11+
import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes';
12+
import type {
13+
DirectEventHandler,
14+
Double,
15+
Int32,
16+
} from '../../../../Libraries/Types/CodegenTypes';
17+
import type {HostComponent} from '../../types/HostComponent';
18+
19+
import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent';
20+
21+
export type NativeModeChangeEvent = Readonly<{
22+
/**
23+
* Virtualization mode of the target view.
24+
*
25+
* - `0`: Target view is visible.
26+
* - `1`: Target view is hidden, but can be prerendered.
27+
* - `2`: Target view is hidden.
28+
*
29+
* WORKAROUND: As of this writing, codegen doesn't support enums, so we need
30+
* to convert `number` into an enum in `VirtualView`.
31+
*/
32+
mode: Int32,
33+
34+
/**
35+
* Rect of the target view, relative to the nearest ancestor scroll container.
36+
*/
37+
targetRect: Readonly<{
38+
x: Double,
39+
y: Double,
40+
width: Double,
41+
height: Double,
42+
}>,
43+
44+
/**
45+
* Rect of the threshold that determines the mode of the target view, relative
46+
* to the nearest ancestor scroll container.
47+
*
48+
* - `Visible`: Rect in which the target view is visible.
49+
* - `Prerender`: Rect in which the target view is prerendered.
50+
* - `Hidden`: Unused, without any guarantees.
51+
*
52+
* This can be used to determine whether and how much new content to render.
53+
*/
54+
thresholdRect: Readonly<{
55+
x: Double,
56+
y: Double,
57+
width: Double,
58+
height: Double,
59+
}>,
60+
}>;
61+
62+
type VirtualViewNativeProps = Readonly<{
63+
...ViewProps,
64+
65+
/**
66+
* Whether the initial mode should be `Hidden`.
67+
*/
68+
initialHidden?: boolean,
69+
70+
/**
71+
* This was needed to get VirtualViewManagerDelegate to set this property.
72+
* TODO: Investigate why spread ViewProps doesn't call setter
73+
*/
74+
removeClippedSubviews?: boolean,
75+
76+
/**
77+
* Render state of children.
78+
*
79+
* - `0`: Reserved to represent unknown future values.
80+
* - `1`: Children are rendered.
81+
* - `2`: Children are not rendered.
82+
*
83+
* WORKAROUND: As of this writing, codegen doesn't support enums, so we need
84+
* to convert `number` into an enum in `VirtualView`.
85+
*/
86+
renderState: Int32,
87+
88+
/**
89+
* See `NativeModeChangeEvent`.
90+
*/
91+
onModeChange?: ?DirectEventHandler<NativeModeChangeEvent>,
92+
}>;
93+
94+
export default codegenNativeComponent<VirtualViewNativeProps>('VirtualView', {
95+
interfaceOnly: true,
96+
}) as HostComponent<VirtualViewNativeProps>;

0 commit comments

Comments
 (0)