UNPKG

@tamagui/react-native-web-lite

Version:
144 lines 5.15 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var View_exports = {}; __export(View_exports, { View: () => View, default: () => View_default }); module.exports = __toCommonJS(View_exports); var import_react_native_web_internals = require("@tamagui/react-native-web-internals"); var React = __toESM(require("react"), 1); var import_createElement = require("../createElement/index.cjs"); const pickProps = props => (0, import_react_native_web_internals.pick)(props, import_react_native_web_internals.forwardPropsListView); const View = React.forwardRef((props, forwardedRef) => { const { hrefAttrs, onLayout, onMoveShouldSetResponder, onMoveShouldSetResponderCapture, onResponderEnd, onResponderGrant, onResponderMove, onResponderReject, onResponderRelease, onResponderStart, onResponderTerminate, onResponderTerminationRequest, onScrollShouldSetResponder, onScrollShouldSetResponderCapture, onSelectionChangeShouldSetResponder, onSelectionChangeShouldSetResponderCapture, onStartShouldSetResponder, onStartShouldSetResponderCapture, ...rest } = props; if (process.env.NODE_ENV !== "production") { React.Children.toArray(props.children).forEach(item => { if (typeof item === "string") { console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`); } }); } const hasTextAncestor = React.useContext(import_react_native_web_internals.TextAncestorContext); const hostRef = React.useRef(null); const { direction: contextDirection } = (0, import_react_native_web_internals.useLocaleContext)(); (0, import_react_native_web_internals.useElementLayout)(hostRef, onLayout); (0, import_react_native_web_internals.useResponderEvents)(hostRef, { onMoveShouldSetResponder, onMoveShouldSetResponderCapture, onResponderEnd, onResponderGrant, onResponderMove, onResponderReject, onResponderRelease, onResponderStart, onResponderTerminate, onResponderTerminationRequest, onScrollShouldSetResponder, onScrollShouldSetResponderCapture, onSelectionChangeShouldSetResponder, onSelectionChangeShouldSetResponderCapture, onStartShouldSetResponder, onStartShouldSetResponderCapture }); let component = "div"; const langDirection = props.lang != null ? (0, import_react_native_web_internals.getLocaleDirection)(props.lang) : null; const componentDirection = props.dir || langDirection; const writingDirection = componentDirection || contextDirection; const supportedProps = pickProps(rest); supportedProps.dir = componentDirection; supportedProps.style = [styles.view, hasTextAncestor && styles.inline, props.style]; if (props.href != null) { component = "a"; if (hrefAttrs != null) { const { download, rel, target } = hrefAttrs; if (download != null) { supportedProps.download = download; } if (rel != null) { supportedProps.rel = rel; } if (typeof target === "string") { supportedProps.target = target.charAt(0) !== "_" ? "_" + target : target; } } } const platformMethodsRef = (0, import_react_native_web_internals.usePlatformMethods)(supportedProps); const setRef = (0, import_react_native_web_internals.useMergeRefs)(hostRef, platformMethodsRef, forwardedRef); supportedProps.ref = setRef; return (0, import_createElement.useCreateElement)(component, supportedProps, { writingDirection }); }); View.displayName = "View"; const styles = { view: { alignItems: "stretch", boxSizing: "border-box", display: "flex", flexBasis: "auto", flexDirection: "column", flexShrink: 0 }, inline: { display: "inline-flex" } }; var View_default = View;