// Metro module 388 (f389). import _slicedToArray from "./_slicedToArray"; import { useCallback, useContext, useEffect, useInsertionEffect, useReducer, useRef } from "react"; import { createAnimatedPropsMemoHook } from "./createCompositeKeyForProps"; import * as _Module27 from "./Module27"; import { cxxNativeAnimatedEnabled } from "./Module27"; import { RootTagContext } from "./Module253"; import AnimatedProps from "./AnimatedProps"; import Module357 from "./Module357"; import useRefEffect from "./useRefEffect"; import AnimatedValue from "./AnimatedValue"; import { isPublicInstance } from "./Module390"; const addListenersToPropsValue = function addListenersToPropsValue(a0, a1) { if (a0 instanceof AnimatedValue) { a1.push({ propValue: a0, listenerId: a0.addListener(() => {}) }); } else if (Array.isArray(a0)) { for (const item of a0) { addListenersToPropsValue(item, a1); } } else if (a0 instanceof Object) { (function addAnimatedValuesListenersToProps(a0, a1) { for (const key in a0) { addListenersToPropsValue(a0[key], a1); } })(a0, a1); } }; export default function createAnimatedPropsHook(a0) { let c12301_0 = a0; const animatedPropsMemoHook = createAnimatedPropsMemoHook(a0); const shouldUseSetNativePropsInFabric = _Module27.shouldUseSetNativePropsInFabric(); return function useAnimatedProps(a0) { let ref, ref2, context, c23769_5; let c23770_0, ref3; let c23769_0 = a0; const [, dispatch] = useReducer((a0) => a0 + 1, 0); ref = useRef(null); ref2 = useRef(null); context = useContext(RootTagContext); const r28 = animatedPropsMemoHook(() => new AnimatedProps(c23769_0, () => { const current = ref.current; return current == null ? void 0 : current.call(ref); }, c12301_0, context), a0); c23769_5 = r28; useEffect(() => { if (!Module357.shouldSignalBatch) { Module357.API.flushQueue(); } let c28650_0 = null; if (c23769_5.__isNative) { c28650_0 = Module357.nativeEventEmitter.addListener("onUserDrivenAnimationEnded", (a0) => { c23769_5.update(); }); } return () => { if (c28650_0 != null) { c28650_0.remove(); } }; }); c23770_0 = r28; ref3 = void 0; ref3 = useRef(false); useInsertionEffect(() => { ref3.current = true; c23770_0.__attach(); return () => { ref3.current = false; queueMicrotask(() => { if (ref3.current) { c23770_0.__restoreDefaultValues(); } c23770_0.__detach(); }); }; }, [r28]); const refEffect = useRefEffect(useCallback((a0) => { let eventTarget, c28651_2, c28651_3; let c28651_0 = a0; c23769_5.setNativeView(a0); ref.current = () => { let r15 = isPublicInstance(c28651_0); if (!r15) { const r3 = c28651_0 == null; let r17 = void 0; if (!r3) { const getNativeScrollRef = c28651_0.getNativeScrollRef; r17 = getNativeScrollRef == null ? void 0 : getNativeScrollRef.call(c28651_0); } r15 = isPublicInstance(r17); } if (!r15) { const r23 = c28651_0 == null; let r24 = void 0; if (!r23) { const getScrollResponder = c28651_0.getScrollResponder; const r26 = getScrollResponder == null; r24 = void 0; if (!r26) { const r27 = getScrollResponder.call(c28651_0); const r28 = r27 == null; r24 = void 0; if (!r28) { const getNativeScrollRef2 = r27.getNativeScrollRef; r24 = getNativeScrollRef2 == null ? void 0 : getNativeScrollRef2.call(r27); } } } r15 = isPublicInstance(r24); } L29: { if (!c23769_5.__isNative) { if (typeof c28651_0 === "object" && typeof c28651_0?.setNativeProps === "function") { if (r15) { if (shouldUseSetNativePropsInFabric) { c28651_0.setNativeProps(c23769_5.__getAnimatedValue()); if (ref2.current != null) { clearTimeout(ref2.current); } ref2.current = setTimeout(() => { ref2.current = null; dispatch(); }, 48); break L29; } return dispatch(); } return c28651_0.setNativeProps(c23769_5.__getAnimatedValue()); } return dispatch(); } const r65 = cxxNativeAnimatedEnabled(); if (r15) { r15 = !r65; } if (r15) { dispatch(); } } }; eventTarget = (function getEventTarget(a0) { return typeof a0 === "object" ? typeof a0?.getScrollableNode === "function" ? a0.getScrollableNode() : a0 : a0; })(a0); const r5 = []; c28651_2 = r5; const r29 = c23769_5.__getNativeAnimatedEventTuples(); c28651_3 = r29; for (const item of r29) { const [r11, r38] = item; r38.__attach(eventTarget, r11); addListenersToPropsValue(r38, r5); } return () => { ref.current = null; for (const item of c28651_3) { const r30 = _slicedToArray(item, 2); r30[1].__detach(eventTarget, r30[0]); } for (const item2 of c28651_2) { item2.propValue.removeListener(item2.listenerId); } }; }, [r28])); return [{ ...r28.__getValueWithStaticProps(a0), collapsable: false }, refEffect]; }; };