UNPKG

@arpitbhalla/rneui-base-dev

Version:
101 lines (100 loc) 5.96 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Image = void 0; var react_1 = __importStar(require("react")); var react_native_1 = require("react-native"); var Image = function (_a) { var onPress = _a.onPress, onLongPress = _a.onLongPress, onPressIn = _a.onPressIn, onPressOut = _a.onPressOut, _b = _a.Component, Component = _b === void 0 ? onPress || onLongPress || onPressIn || onPressOut ? react_native_1.Pressable : react_native_1.View : _b, placeholderStyle = _a.placeholderStyle, PlaceholderContent = _a.PlaceholderContent, containerStyle = _a.containerStyle, _c = _a.childrenContainerStyle, childrenContainerStyle = _c === void 0 ? null : _c, _d = _a.style, style = _d === void 0 ? {} : _d, _e = _a.ImageComponent, ImageComponent = _e === void 0 ? react_native_1.Image : _e, onLoad = _a.onLoad, children = _a.children, transition = _a.transition, _f = _a.transitionDuration, transitionDuration = _f === void 0 ? 360 : _f, pressableProps = _a.pressableProps, props = __rest(_a, ["onPress", "onLongPress", "onPressIn", "onPressOut", "Component", "placeholderStyle", "PlaceholderContent", "containerStyle", "childrenContainerStyle", "style", "ImageComponent", "onLoad", "children", "transition", "transitionDuration", "pressableProps"]); var placeholderOpacity = react_1.default.useRef(new react_native_1.Animated.Value(1)); var onLoadHandler = (0, react_1.useCallback)(function (event) { if (transition) { react_native_1.Animated.timing(placeholderOpacity.current, { toValue: 0, duration: transitionDuration, useNativeDriver: true, }).start(); } else { placeholderOpacity.current.setValue(0); } onLoad === null || onLoad === void 0 ? void 0 : onLoad(event); }, [transition, transitionDuration, onLoad]); var hasImage = Boolean(props.source); return (react_1.default.createElement(Component, __assign({}, pressableProps, { onPress: onPress, onPressIn: onPressIn, onPressOut: onPressOut, onLongPress: onLongPress }, { accessibilityIgnoresInvertColors: true, style: react_native_1.StyleSheet.flatten([styles.container, containerStyle]) }), react_1.default.createElement(ImageComponent, __assign({ testID: "RNE__Image" }, props, { transition: transition, transitionDuration: transitionDuration }, { onLoad: onLoadHandler, style: react_native_1.StyleSheet.flatten([react_native_1.StyleSheet.absoluteFill, style]) })), react_1.default.createElement(react_native_1.Animated.View, { pointerEvents: hasImage ? 'none' : 'auto', accessibilityElementsHidden: hasImage, importantForAccessibility: hasImage ? 'no-hide-descendants' : 'yes', style: [ react_native_1.StyleSheet.absoluteFillObject, { opacity: hasImage ? placeholderOpacity.current : 1, }, ] }, react_1.default.createElement(react_native_1.View, { testID: "RNE__Image__placeholder", style: react_native_1.StyleSheet.flatten([ style, styles.placeholder, placeholderStyle, ]) }, react_1.default.isValidElement(PlaceholderContent) ? PlaceholderContent : PlaceholderContent && (react_1.default.createElement(react_native_1.Text, { testID: "RNE__Image__Placeholder__Content" }, PlaceholderContent)))), react_1.default.createElement(react_native_1.View, { testID: "RNE__Image__children__container", style: childrenContainerStyle !== null && childrenContainerStyle !== void 0 ? childrenContainerStyle : style }, children))); }; exports.Image = Image; var styles = react_native_1.StyleSheet.create({ container: { backgroundColor: 'transparent', position: 'relative', overflow: 'hidden', }, placeholder: { backgroundColor: '#bdbdbd', alignItems: 'center', justifyContent: 'center', }, }); exports.Image.displayName = 'Image';