UNPKG

react-native-micro-interactions

Version:

Effortlessly enhance your React Native components with subtle micro-interactions and animations.

47 lines (46 loc) 1.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buzz = void 0; var _reactNativeReanimated = require("react-native-reanimated"); var _animOptionsFilter = require("../utils/animOptionsFilter.js"); var _react = require("react"); const buzz = (config, props) => { const animationOptions = (0, _animOptionsFilter.filterBuzzAnimOptions)(config, props); let rotation = (0, _reactNativeReanimated.useSharedValue)(0); let size = (0, _reactNativeReanimated.useSharedValue)(1); const runIndividualAnimation = (0, _react.useCallback)(() => { size.value = (0, _reactNativeReanimated.withTiming)(0.95, { duration: 50 }); rotation.value = (0, _reactNativeReanimated.withSequence)((0, _reactNativeReanimated.withRepeat)((0, _reactNativeReanimated.withSequence)((0, _reactNativeReanimated.withTiming)(-animationOptions.rotation, { duration: animationOptions.duration }), (0, _reactNativeReanimated.withTiming)(animationOptions.rotation, { duration: animationOptions.duration })), animationOptions.frequency, false, finished => { if (finished) { size.value = (0, _reactNativeReanimated.withTiming)(1, { duration: 100 }); } }), (0, _reactNativeReanimated.withTiming)(0, { duration: animationOptions.duration })); }, [animationOptions, size, rotation]); const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => { return { transform: [{ rotateZ: `${rotation.value}deg` }, { scale: size.value }] }; }, [size, rotation]); return { animatedStyle, runIndividualAnimation }; }; exports.buzz = buzz; //# sourceMappingURL=buzz.js.map