mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
033ad83b29
Summary: Changelog: [Internal][SVC][JS] Refactor the JS base SVC StaticViewConfig to be easier to understand This diff is a refactor that doesn't change any logic. # Context NativeViewConfigs are generated from RCTViewManager in iOS and ViewManager in Android. StaticViewConfigs are partially generated from JS, and partially handwritten in JS. We've noticed in at least 2 instances that engineers who add new props to NativeViewConfigs sometimes don't put props in the correct place for StaticViewConfigs, and thus they accidentally break the landblocking jest e2e test that validates the StaticViewConfigs matches the NativeViewConfigs. The human error is mostly because PlatformBaseViewConfig.js was too nested to be easily understood. This diff refactors PlatformBaseViewConfig.js and adds clarifying comments. Reviewed By: RSNara Differential Revision: D35623775 fbshipit-source-id: 498a3daa812fa314821a2e7cb7d6f809900dbe3a
55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow strict
|
|
* @format
|
|
*/
|
|
|
|
import Platform from '../Utilities/Platform';
|
|
|
|
const ignoredViewConfigProps = new WeakSet<{...}>();
|
|
|
|
/**
|
|
* Decorates ViewConfig values that are dynamically injected by the library,
|
|
* react-native-gesture-handler. (T45765076)
|
|
*/
|
|
export function DynamicallyInjectedByGestureHandler<T: {...}>(object: T): T {
|
|
ignoredViewConfigProps.add(object);
|
|
return object;
|
|
}
|
|
|
|
/**
|
|
* On iOS, ViewManager event declarations generate {eventName}: true entries
|
|
* in ViewConfig valueAttributes. These entries aren't generated for Android.
|
|
* This annotation allows Static ViewConfigs to insert these entries into
|
|
* iOS but not Android.
|
|
*
|
|
* In the future, we want to remove this platform-inconsistency. We want
|
|
* to set RN$ViewConfigEventValidAttributesDisabled = true server-side,
|
|
* so that iOS does not generate validAttributes from event props in iOS RCTViewManager,
|
|
* since Android does not generate validAttributes from events props in Android ViewManager.
|
|
*
|
|
* TODO(T110872225): Remove this logic, after achieving platform-consistency
|
|
*/
|
|
export function ConditionallyIgnoredEventHandlers<T: {[name: string]: true}>(
|
|
value: T,
|
|
): T | void {
|
|
if (
|
|
Platform.OS === 'ios' &&
|
|
!(global.RN$ViewConfigEventValidAttributesDisabled === true)
|
|
) {
|
|
return value;
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
export function isIgnored(value: mixed): boolean {
|
|
if (typeof value === 'object' && value != null) {
|
|
return ignoredViewConfigProps.has(value);
|
|
}
|
|
return false;
|
|
}
|