mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
d682753244
Summary: JS changes to support D32138347 (https://github.com/facebook/react-native/commit/a96bdb7154b0d8c7f43977d8a583e8d2cbdcb795). This was previously reverted due to missing iOS Paper support. Changelog: [Android][Fixed] Enable hitSlop to be set using a single number. Original commit changeset: 91cfcc86582c Original Phabricator Diff: D32559015 (https://github.com/facebook/react-native/commit/589b129581903a737a64e14eab3f2e29620831d5) Reviewed By: yungsters Differential Revision: D33453327 fbshipit-source-id: d289a0a8b8208bc9c68e6ca537632b745e8196ed
86 lines
2.2 KiB
JavaScript
86 lines
2.2 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-local
|
|
* @format
|
|
*/
|
|
|
|
import normalizeColor from '../StyleSheet/normalizeColor';
|
|
import type {ColorValue} from '../StyleSheet/StyleSheet';
|
|
import {normalizeRect, type RectOrSize} from '../StyleSheet/Rect';
|
|
|
|
import View from '../Components/View/View';
|
|
import * as React from 'react';
|
|
|
|
type Props = $ReadOnly<{|
|
|
color: ColorValue,
|
|
hitSlop: ?RectOrSize,
|
|
|}>;
|
|
|
|
/**
|
|
* Displays a debug overlay to visualize press targets when enabled via the
|
|
* React Native Inspector. Calls to this module should be guarded by `__DEV__`,
|
|
* for example:
|
|
*
|
|
* return (
|
|
* <View>
|
|
* {children}
|
|
* {__DEV__ ? (
|
|
* <PressabilityDebugView color="..." hitSlop={props.hitSlop} />
|
|
* ) : null}
|
|
* </View>
|
|
* );
|
|
*
|
|
*/
|
|
export function PressabilityDebugView(props: Props): React.Node {
|
|
if (__DEV__) {
|
|
if (isEnabled()) {
|
|
const normalizedColor = normalizeColor(props.color);
|
|
if (typeof normalizedColor !== 'number') {
|
|
return null;
|
|
}
|
|
const baseColor =
|
|
'#' + (normalizedColor ?? 0).toString(16).padStart(8, '0');
|
|
const hitSlop = normalizeRect(props.hitSlop);
|
|
return (
|
|
<View
|
|
pointerEvents="none"
|
|
style={
|
|
// eslint-disable-next-line react-native/no-inline-styles
|
|
{
|
|
backgroundColor: baseColor.slice(0, -2) + '0F', // 15%
|
|
borderColor: baseColor.slice(0, -2) + '55', // 85%
|
|
borderStyle: 'dashed',
|
|
borderWidth: 1,
|
|
bottom: -(hitSlop?.bottom ?? 0),
|
|
left: -(hitSlop?.left ?? 0),
|
|
position: 'absolute',
|
|
right: -(hitSlop?.right ?? 0),
|
|
top: -(hitSlop?.top ?? 0),
|
|
}
|
|
}
|
|
/>
|
|
);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
let isDebugEnabled = false;
|
|
|
|
export function isEnabled(): boolean {
|
|
if (__DEV__) {
|
|
return isDebugEnabled;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
export function setEnabled(value: boolean): void {
|
|
if (__DEV__) {
|
|
isDebugEnabled = value;
|
|
}
|
|
}
|