/** * 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 type {ColorValue} from '../StyleSheet/StyleSheet'; import View from '../Components/View/View'; import normalizeColor from '../StyleSheet/normalizeColor'; import {type RectOrSize, normalizeRect} from '../StyleSheet/Rect'; 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 ( * * {children} * {__DEV__ ? ( * * ) : null} * * ); * */ 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 ( ); } } 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; } }