UNPKG

@arpitbhalla/rneui-base-dev

Version:
132 lines (131 loc) 5.86 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; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Skeleton = void 0; var react_1 = __importStar(require("react")); var react_native_1 = require("react-native"); var helpers_1 = require("../helpers"); var color_1 = __importDefault(require("color")); var Skeleton = function (_a) { var _b, _c; var circle = _a.circle, _d = _a.width, width = _d === void 0 ? '100%' : _d, height = _a.height, _e = _a.animation, animation = _e === void 0 ? 'pulse' : _e, style = _a.style, skeletonStyle = _a.skeletonStyle, _f = _a.theme, theme = _f === void 0 ? helpers_1.defaultTheme : _f, LinearGradientComponent = _a.LinearGradientComponent, rest = __rest(_a, ["circle", "width", "height", "animation", "style", "skeletonStyle", "theme", "LinearGradientComponent"]); var animationRef = (0, react_1.useRef)(new react_native_1.Animated.Value(0)); var animationLoop = (0, react_1.useRef)(); var _g = react_1.default.useState(0), layoutWidth = _g[0], setLayoutWidth = _g[1]; (0, react_1.useEffect)(function () { animationLoop.current = react_native_1.Animated.timing(animationRef.current, { toValue: 2, delay: 400, duration: 1500, useNativeDriver: !!react_native_1.Platform.select({ web: false, native: true, }), }); animationRef.current.setValue(0); react_native_1.Animated.loop(animationLoop.current).start(); }, []); return (react_1.default.createElement(react_native_1.View, __assign({ accessibilityRole: "none", accessibilityLabel: "loading...", accessible: false, testID: "RNE__Skeleton", onLayout: function (_a) { var nativeEvent = _a.nativeEvent; setLayoutWidth(nativeEvent.layout.width); }, style: [ styles.container, { width: width, height: height || 12, backgroundColor: (_b = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _b === void 0 ? void 0 : _b.grey4, }, circle && { borderRadius: 50, height: height || width, }, style, ] }, rest), animation !== 'none' && (react_1.default.createElement(react_native_1.Animated.View, { style: [ styles.skeleton, !LinearGradientComponent && { backgroundColor: (0, color_1.default)((_c = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _c === void 0 ? void 0 : _c.grey4) .darken(0.1) .rgb() .string(), }, animation === 'pulse' && { width: '100%', opacity: animationRef.current.interpolate({ inputRange: [0, 1, 2], outputRange: [1, 0, 1], }), }, animation === 'wave' && { transform: [ { translateX: animationRef.current.interpolate({ inputRange: [0, 2], outputRange: [-layoutWidth * 2, layoutWidth * 2], }), }, ], }, skeletonStyle, ] }, LinearGradientComponent && (react_1.default.createElement(LinearGradientComponent, { style: styles.skeleton, colors: [ theme.colors.grey4, theme.colors.grey5, theme.colors.grey4, ], start: { x: 0, y: 0 }, end: { x: 1, y: 0 } })))))); }; exports.Skeleton = Skeleton; var styles = react_native_1.StyleSheet.create({ container: { overflow: 'hidden', borderRadius: 2, }, skeleton: { height: '100%', }, });