// Metro module 14042 (f14043). import { useState, useRef, useCallback, useEffect } from "react"; import { AppState } from "react-native"; import { QuestsExperimentLocations } from "../../QuestConstants"; import { BountiesVerticalScrollExperiment } from "../../experiments/BountiesVerticalScrollExperiment"; import { useForceBountiesSwipeUpNux } from "./bountiesSwipeUpNuxDevTools"; import { useSharedValue } from "../../../reanimated/ReanimatedRexport"; import { withTiming } from "../../../../design/animation/reanimated/timing/timing"; import { timingSlow, timingStandard } from "../../../../design/animation/reanimated/timing/timingPresets"; import { getIsInAppBrowserOpen, subscribeToIsInAppBrowserOpen } from "../../../links/native/BrowserManager"; let c9818_6 = new Set(); export const AUTO_SCROLL_PEEK_SCALE = 0.83; export const AUTO_SCROLL_PEEK_TOP_OFFSET = 54; export function clearDismissedScrollAffordanceBountyIds() { c9818_6.clear(); } export function useBountiesAutoScroll({ listRef, enabled, mode, activeIndex, activeBountyId, slotHeight, onCountdownCancelled }) { let callback2, callback3, callback4, callback5, callback6, callback7, callback8, callback9, callback10, callback11, callback12, callback13; callback2 = void 0; callback3 = void 0; callback4 = void 0; callback5 = void 0; callback6 = void 0; callback7 = void 0; callback8 = void 0; callback9 = void 0; callback10 = void 0; callback11 = void 0; callback12 = void 0; callback13 = void 0; const config = BountiesVerticalScrollExperiment.useConfig({ location: QuestsExperimentLocations.VIDEO_MODAL_MOBILE }); const { autoScrollLeadMs, autoScrollEndCardMs, ctaTimerMilliSeconds } = config; const r4 = autoScrollLeadMs / 1000; let c20867_8 = r4; const current = r4 + autoScrollEndCardMs / 1000; const [r48] = useForceBountiesSwipeUpNux(); let c20867_10 = r48; const [visible, setState] = useState(false); const [peekActive, setState2] = useState(false); const [progress, setState3] = useState(0); const [showProgressRing, setState4] = useState(false); const ref = useRef(false); const ref2 = useRef(false); const ref3 = useRef(false); const ref4 = useRef(false); const ref5 = useRef(null); const ref6 = useRef(null); const ref7 = useRef(0); const ref8 = useRef(null); const ref9 = useRef(false); const ref10 = useRef(false); const sharedValue = useSharedValue(1); const ref11 = useRef(current); const callback = useCallback(() => { if (ref5.current != null) { clearInterval(ref5.current); ref5.current = null; } ref8.current = null; }, []); callback2 = useCallback(() => { if (ref6.current != null) { clearTimeout(ref6.current); ref6.current = null; } }, []); callback3 = useCallback((a0) => { if (!(c20867_10 || a0 == null)) { c9818_6.add(a0); } }, [r48]); callback4 = useCallback((a0) => (c20867_10 ? !c20867_10 : a0 != null) && c9818_6.has(a0), [r48]); callback5 = useCallback(() => { setState(false); setState2(false); setState3(0); setState4(false); }, []); const [state, setState5] = useState(activeIndex); const [state2, setState6] = useState(activeBountyId); if (!(state === activeIndex && state2 === activeBountyId)) { setState5(activeIndex); setState6(activeBountyId); callback5(); } useEffect(() => { callback(); callback2(); ref.current = callback4(activeBountyId); ref2.current = callback4(activeBountyId); ref3.current = false; ref4.current = false; ref7.current = 0; ref9.current = false; ref10.current = false; sharedValue.set(1); }, [activeIndex, activeBountyId, callback, callback2, sharedValue, callback4]); useEffect(() => () => { callback(); callback2(); }, [callback, callback2]); useEffect(() => { ref11.current = current; }, [current]); callback6 = useCallback(function(r7 = 0) { const r6 = ref2.current || ref.current || callback4(activeBountyId); let r1 = !r6; if (!r6) { ref2.current = true; callback3(activeBountyId); callback2(); ref6.current = setTimeout(() => { ref6.current = null; if (!(ref.current || ref4.current)) { sharedValue.set(withTiming(0.83, timingSlow)); setState2(true); ref6.current = setTimeout(() => { ref6.current = null; if (!(ref.current || ref4.current)) { setState(true); } }, 500); } }, r7); r1 = true; } return r1; }, [activeBountyId, callback2, callback3, sharedValue, callback4]); callback7 = useCallback(() => { if (!(ref4.current || ref.current)) { ref4.current = true; callback3(activeBountyId); callback(); callback2(); callback5(); sharedValue.set(1); const current2 = listRef.current; if (current2 != null) { current2.scrollToOffset({ offset: (activeIndex + 1) * slotHeight, animated: true }); } } }, [activeBountyId, activeIndex, callback, callback2, listRef, callback3, sharedValue, callback5, slotHeight]); callback8 = useCallback(() => { if (!ref.current && !ref9.current) { const current3 = Date.now(); if (ref8.current != null) { ref7.current = ref7.current + (current3 - ref8.current); } ref8.current = current3; const current2 = ref11.current; const r22 = ref7.current / 1000; if (r22 >= current2) { callback7(); } else { setState3(r22 / current2); } } }, [callback7]); callback9 = useCallback(() => { if (!(ref3.current || ref5.current != null || ref9.current)) { ref3.current = true; ref7.current = 0; ref8.current = Date.now(); setState3(0); setState4(true); ref5.current = setInterval(callback8, 50); } }, [callback8]); callback10 = useCallback(() => { if (ref3.current && !ref9.current && ref5.current != null) { const r6 = Date.now(); if (ref8.current != null) { ref7.current = ref7.current + (r6 - ref8.current); } ref9.current = true; callback(); } }, [callback]); callback11 = useCallback(() => { if (ref3.current && ref9.current && !ref.current && !ref4.current) { ref9.current = false; ref8.current = Date.now(); ref5.current = setInterval(callback8, 50); } }, [callback8]); callback12 = useCallback(() => { if (!ref9.current) { callback10(); ref10.current = true; } }, [callback10]); callback13 = useCallback(() => { if (ref10.current && !getIsInAppBrowserOpen()) { ref10.current = false; callback11(); } }, [callback11]); useEffect(() => { let c27615_1; let c27615_0 = AppState.addEventListener("change", (a0) => { if (a0 === "active") { callback13(); } else { callback12(); } }); c27615_1 = subscribeToIsInAppBrowserOpen((a0) => { if (a0) { callback12(); } else { callback13(); } }); return () => { c27615_0.remove(); c27615_1(); }; }, [callback12, callback13]); return { visible, peekActive, progress, showProgressRing, peekScale: sharedValue, cancel: useCallback((a0) => { const current2 = ref2.current; if (!((current2 ? ref.current : !current2) || ref4.current)) { ref.current = true; callback3(activeBountyId); callback(); setState(false); setState3(0); sharedValue.set(withTiming(1, timingStandard)); if (mode === "countdown" && onCountdownCancelled != null) { onCountdownCancelled(a0); } callback2(); callback5(); } }, [activeBountyId, callback, callback2, callback3, mode, onCountdownCancelled, sharedValue, callback5]), dismissOnClose: useCallback(() => { if (ref2.current) { ref.current = true; callback3(activeBountyId); callback(); callback2(); callback5(); sharedValue.set(1); } }, [activeBountyId, callback, callback2, callback3, sharedValue, callback5]), takeDidAutoScroll: useCallback(() => { const current2 = ref4.current; ref4.current = false; callback2(); callback5(); return current2; }, [callback2, callback5]), onPlaybackTimeChange: useCallback((a0, a1, a2, a3, a4) => { if (!((enabled ? mode !== "countdown" : !enabled) || ref.current || ref4.current || a1 <= 0)) { const current2 = ref2.current; if (current2 ? !current2 : a4 ? a4 : 1000 * a3 > ctaTimerMilliSeconds) { callback6(5000); } if ((a2 ? !ref3.current : a2) && !(a1 - a0 > c20867_8)) { callback9(); } } }, [r4, ctaTimerMilliSeconds, enabled, mode, callback6, callback9]), onEndCardVisible: useCallback(() => { if (!((enabled ? ref.current : !enabled) || callback4(activeBountyId))) { if (mode !== "hint") { if (!ref2.current) { callback6(); } if (ref3.current) { if (ref9.current) { callback11(); } } else { callback9(); } } else { callback6(); } } }, [activeBountyId, enabled, mode, callback11, callback6, callback9, callback4]), pauseCountdown: callback10, resumeCountdown: callback11 }; }