All files / packages/components/src view.web.tsx

75% Statements 3/4
75% Branches 3/4
50% Functions 1/2
75% Lines 3/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46                                                      332x             166131x 166131x                    
import type React from "react";
import { View as RawView } from "react-native";
import type { LayoutRectangle, ViewStyle } from "react-native";
 
import { cn } from "~components/utils";
 
import type { ViewHandle } from "./view.base";
import { useScrollView } from "./view.base";
 
export type ViewReactNode =
	| React.JSX.Element
	| (ViewReactNode | undefined)[]
	| null;
 
export type Props = Pick<
	React.ComponentProps<typeof RawView>,
	"role" | "pointerEvents"
> & {
	ref?: React.Ref<ViewHandle | null>;
	className?: string;
	children?: ViewReactNode;
	testID?: string;
	onPress?: () => void;
	onLayout?: (rect: LayoutRectangle) => void;
	style?: ViewStyle;
};
 
export const View: React.FC<Props> = ({
	onPress,
	className,
	onLayout,
	ref,
	...props
}) => {
	const innerRef = useScrollView(ref);
	return (
		<RawView
			ref={innerRef}
			{...props}
			onClick={onPress}
			onLayout={onLayout ? (e) => onLayout(e.nativeEvent.layout) : undefined}
			className={cn(onPress ? "cursor-pointer" : undefined, className)}
		/>
	);
};