@nghinv/react-native-app-tour
Version:
React Native app tour Library
92 lines (75 loc) • 2.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getCurrentNode = getCurrentNode;
exports.withAnimation = withAnimation;
exports.circlePathCalculator = circlePathCalculator;
exports.circlePath = circlePath;
exports.rectPath = rectPath;
exports.getRectPath = getRectPath;
exports.timingConfig = exports.springConfig = void 0;
var _reactNativeReanimated = require("react-native-reanimated");
/**
* Created by nghinv on Wed Jun 23 2021
* Copyright (c) 2021 nghinv@lumi.biz
*/
const springConfig = {
stiffness: 1000,
damping: 500,
mass: 3,
overshootClamping: true,
restDisplacementThreshold: 0.01,
restSpeedThreshold: 0.01
};
exports.springConfig = springConfig;
const timingConfig = {
duration: 400,
easing: _reactNativeReanimated.Easing.bezier(0.25, 0.1, 0.25, 1)
};
exports.timingConfig = timingConfig;
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
};
}
function withAnimation(value, animated = true) {
'worklet';
return animated ? (0, _reactNativeReanimated.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
// "
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`;
}
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);
}
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(' ');
}
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