UNPKG

@nghinv/react-native-app-tour

Version:
70 lines (62 loc) 2.11 kB
/** * Created by nghinv on Wed Jun 23 2021 * Copyright (c) 2021 nghinv@lumi.biz */ import { Easing, withSpring } from 'react-native-reanimated'; export const springConfig = { stiffness: 1000, damping: 500, mass: 3, overshootClamping: true, restDisplacementThreshold: 0.01, restSpeedThreshold: 0.01 }; export const timingConfig = { duration: 400, easing: Easing.bezier(0.25, 0.1, 0.25, 1) }; export function getCurrentNode(nodes, scene, currentStep, defaultTarget) { 'worklet'; var _nodes$value$find; const nodeId = scene[currentStep.value].id; const defaultNode = { target: defaultTarget, maskType: 'rect', title: '', describe: '' }; return { node: (_nodes$value$find = nodes.value.find(n => n.id === nodeId)) !== null && _nodes$value$find !== void 0 ? _nodes$value$find : defaultNode }; } export function withAnimation(value, animated = true) { 'worklet'; return animated ? withSpring(value, springConfig) : value; } // d=" // M cx cy // m -r, 0 // a r,r 0 1,1 (r * 2),0 // a r,r 0 1,1 -(r * 2),0 // " export function circlePathCalculator(cx, cy, r) { 'worklet'; return `M ${cx} ${cy} m -${r}, 0 a ${r},${r} 0 1,0 ${r * 2},0 a ${r},${r} 0 1,0 -${r * 2},0`; } export function circlePath(target) { 'worklet'; const cx = target.x.value + target.width.value / 2; const cy = target.y.value + target.height.value / 2; const r = Math.max(target.width.value, target.height.value) / 2; return circlePathCalculator(cx, cy, r); } export function rectPath(target) { 'worklet'; const pathRects = [`M${target.x.value} ${target.y.value}`, `L${target.x.value} ${target.y.value + target.height.value}`, `L${target.x.value + target.width.value} ${target.y.value + target.height.value}`, `L${target.x.value + target.width.value} ${target.y.value}`, 'Z']; return pathRects.join(' '); } export function getRectPath(target) { 'worklet'; const pathRects = ['M0 0', `L0 ${target.height.value}`, `L${target.width.value} ${target.height.value}`, `L${target.width.value} 0`, 'Z']; return pathRects.join(' '); } //# sourceMappingURL=math.js.map