UNPKG

@oxyhq/services

Version:

Reusable OxyHQ module to handle authentication, user management, karma system, device-based session management and more 🚀

213 lines (203 loc) • 6.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = require("react"); var _reactNative = require("react-native"); var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated")); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } // Example component showcasing improved Reanimated usage const AnimationExample = () => { const [currentStep, setCurrentStep] = (0, _react.useState)(0); // Shared values for better performance const opacity = (0, _reactNativeReanimated.useSharedValue)(1); const scale = (0, _reactNativeReanimated.useSharedValue)(1); const translateX = (0, _reactNativeReanimated.useSharedValue)(0); const rotation = (0, _reactNativeReanimated.useSharedValue)(0); const progress = (0, _reactNativeReanimated.useSharedValue)(0); const colorProgress = (0, _reactNativeReanimated.useSharedValue)(0); // Animated styles with proper interpolation const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => { return { opacity: opacity.value, transform: [{ scale: scale.value }, { translateX: translateX.value }, { rotate: `${rotation.value}deg` }] }; }); const progressStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => { return { width: `${progress.value * 100}%`, backgroundColor: (0, _reactNativeReanimated.interpolateColor)(colorProgress.value, [0, 1], ['#3498db', '#e74c3c']) }; }); const backgroundStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => { return { backgroundColor: (0, _reactNativeReanimated.interpolateColor)(colorProgress.value, [0, 1], ['#ecf0f1', '#f39c12']) }; }); // Complex animation sequence const animateSequence = () => { 'worklet'; // Staggered animations for smooth transitions opacity.value = (0, _reactNativeReanimated.withTiming)(0.5, { duration: 200 }); scale.value = (0, _reactNativeReanimated.withSpring)(0.8, { damping: 15, stiffness: 150 }); // Delayed follow-up animations translateX.value = (0, _reactNativeReanimated.withDelay)(100, (0, _reactNativeReanimated.withSpring)(50, { damping: 20, stiffness: 100 }, finished => { if (finished) { translateX.value = (0, _reactNativeReanimated.withSpring)(0, { damping: 15, stiffness: 150 }); } })); // Sequential animations rotation.value = (0, _reactNativeReanimated.withSequence)((0, _reactNativeReanimated.withTiming)(10, { duration: 150 }), (0, _reactNativeReanimated.withTiming)(-10, { duration: 150 }), (0, _reactNativeReanimated.withTiming)(0, { duration: 150 })); // Progress animation with easing progress.value = (0, _reactNativeReanimated.withTiming)(1, { duration: 1000, easing: _reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.exp) }, finished => { if (finished) { (0, _reactNativeReanimated.runOnJS)(setCurrentStep)(currentStep + 1); } }); // Color transition colorProgress.value = (0, _reactNativeReanimated.withTiming)(1, { duration: 800 }); // Reset animations setTimeout(() => { opacity.value = (0, _reactNativeReanimated.withSpring)(1); scale.value = (0, _reactNativeReanimated.withSpring)(1); progress.value = (0, _reactNativeReanimated.withTiming)(0, { duration: 500 }); colorProgress.value = (0, _reactNativeReanimated.withTiming)(0, { duration: 500 }); }, 1500); }; return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNativeReanimated.default.View, { style: [styles.container, backgroundStyle], children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: styles.title, children: "Advanced Reanimated Example" }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Text, { style: styles.subtitle, children: ["Step: ", currentStep] }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, { style: [styles.box, animatedStyle], children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: styles.boxText, children: "Animated Box" }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: styles.progressContainer, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, { style: [styles.progressBar, progressStyle] }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, { style: styles.button, onPress: animateSequence, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: styles.buttonText, children: "Animate Sequence" }) })] }); }; const styles = _reactNative.StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', padding: 20 }, title: { fontSize: 24, fontWeight: 'bold', marginBottom: 10, color: '#2c3e50' }, subtitle: { fontSize: 16, marginBottom: 30, color: '#7f8c8d' }, box: { width: 150, height: 150, backgroundColor: '#3498db', borderRadius: 20, justifyContent: 'center', alignItems: 'center', marginBottom: 30, shadowColor: '#000', shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.3, shadowRadius: 8, elevation: 8 }, boxText: { color: 'white', fontSize: 16, fontWeight: 'bold' }, progressContainer: { width: '100%', height: 10, backgroundColor: '#ecf0f1', borderRadius: 5, marginBottom: 30, overflow: 'hidden' }, progressBar: { height: '100%', borderRadius: 5 }, button: { backgroundColor: '#e74c3c', paddingHorizontal: 30, paddingVertical: 15, borderRadius: 25, shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.2, shadowRadius: 4, elevation: 4 }, buttonText: { color: 'white', fontSize: 16, fontWeight: 'bold' } }); var _default = exports.default = AnimationExample; //# sourceMappingURL=AnimationExample.js.map