UNPKG

@interactify-live/pindo-wizard-react-native

Version:

React Native PindoWizard component for media capture and interaction management

106 lines (105 loc) 4.57 kB
"use strict"; 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 () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const react_native_1 = require("react-native"); const react_native_svg_1 = __importStar(require("react-native-svg")); const VideoType = "video"; const CONTAINER_SIZE = 80; const BUTTON_SIZE = 70; const BORDER_WIDTH = 4; const RADIUS = (CONTAINER_SIZE - BORDER_WIDTH) / 2; const CIRCUMFERENCE = 2 * Math.PI * RADIUS; const CaptureButton = (0, react_1.forwardRef)(({ onPress, captureType, disabled = false }, ref) => { const animatedValue = (0, react_1.useRef)(new react_native_1.Animated.Value(0)).current; const animationRef = (0, react_1.useRef)(null); const start = (animationDurationInMilliSeconds) => { // Stop any existing animation if (animationRef.current) { animationRef.current.stop(); } // Reset to 0 animatedValue.setValue(0); // Start new animation animationRef.current = react_native_1.Animated.timing(animatedValue, { toValue: 1, duration: animationDurationInMilliSeconds, easing: react_native_1.Easing.linear, useNativeDriver: false, // We need this for strokeDashoffset }); animationRef.current.start(); }; const stop = () => { if (animationRef.current) { animationRef.current.stop(); animationRef.current = null; } animatedValue.setValue(0); // Reset to initial state }; (0, react_1.useImperativeHandle)(ref, () => ({ start, stop, })); const strokeDashoffset = animatedValue.interpolate({ inputRange: [0, 1], outputRange: [CIRCUMFERENCE, 0], }); return ((0, jsx_runtime_1.jsxs)(react_native_1.TouchableOpacity, { onPress: disabled ? undefined : onPress, style: [styles.container, disabled && styles.disabled], activeOpacity: disabled ? 1 : 0.7, disabled: disabled, children: [(0, jsx_runtime_1.jsx)(react_native_svg_1.default, { width: CONTAINER_SIZE, height: CONTAINER_SIZE, style: react_native_1.StyleSheet.absoluteFillObject, children: (0, jsx_runtime_1.jsx)(react_native_svg_1.Circle, { cx: CONTAINER_SIZE / 2, cy: CONTAINER_SIZE / 2, r: RADIUS, stroke: "white", strokeWidth: BORDER_WIDTH, fill: "none", strokeDasharray: CIRCUMFERENCE, strokeDashoffset: strokeDashoffset, rotation: "-90", originX: CONTAINER_SIZE / 2, originY: CONTAINER_SIZE / 2 }) }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: [ styles.button, { backgroundColor: captureType === VideoType ? "#FF3F17" : "#FFFFFF", }, ] })] })); }); const styles = react_native_1.StyleSheet.create({ container: { width: CONTAINER_SIZE, height: CONTAINER_SIZE, position: "relative", alignItems: "center", justifyContent: "center", overflow: "visible", }, button: { width: BUTTON_SIZE, height: BUTTON_SIZE, borderRadius: BUTTON_SIZE / 2, }, disabled: { opacity: 0.6, }, }); exports.default = CaptureButton;