@tamagui/react-native-web-lite
Version:
React Native for Web
90 lines (89 loc) • 3.35 kB
JavaScript
import {
forwardPropsListView,
getLocaleDirection,
pick,
TextAncestorContext,
useElementLayout,
useLocaleContext,
useMergeRefs,
usePlatformMethods,
useResponderEvents
} from "@tamagui/react-native-web-internals";
import * as React from "react";
import { useCreateElement } from "../createElement/index";
const pickProps = (props) => pick(props, forwardPropsListView), 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;
process.env.NODE_ENV !== "production" && React.Children.toArray(props.children).forEach((item) => {
typeof item == "string" && console.error(
`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`
);
});
const hasTextAncestor = React.useContext(TextAncestorContext), hostRef = React.useRef(null), { direction: contextDirection } = useLocaleContext();
useElementLayout(hostRef, onLayout), 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 ? getLocaleDirection(props.lang) : null, componentDirection = props.dir || langDirection, writingDirection = componentDirection || contextDirection, supportedProps = pickProps(rest);
if (supportedProps.dir = componentDirection, supportedProps.style = [styles.view, hasTextAncestor && styles.inline, props.style], props.href != null && (component = "a", hrefAttrs != null)) {
const { download, rel, target } = hrefAttrs;
download != null && (supportedProps.download = download), rel != null && (supportedProps.rel = rel), typeof target == "string" && (supportedProps.target = target.charAt(0) !== "_" ? "_" + target : target);
}
const platformMethodsRef = usePlatformMethods(supportedProps), setRef = useMergeRefs(hostRef, platformMethodsRef, forwardedRef);
return supportedProps.ref = setRef, 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;
export {
View_default as default
};
//# sourceMappingURL=index.js.map