// Metro module 14931 (f14932). import _slicedToArray from "../../../_bundle/_slicedToArray"; import { createContext, useCallback, useEffect, useRef, useLayoutEffect, useMemo, useState } from "react"; import HomeDrawerStore, { computeMaxX } from "./HomeDrawerStore"; import HomeDrawerSubtitleStore from "./HomeDrawerSubtitleStore"; import { AnalyticEvents } from "../../../Constants"; import { MobileHomeDrawerExperiment } from "./HomeDrawerExperiment"; import * as _ReanimatedRexport from "../../reanimated/ReanimatedRexport"; import { useSharedValue, useAnimatedReaction, useDerivedValue, useAnimatedStyle } from "../../reanimated/ReanimatedRexport"; import { useNavigation, useIsFocused } from "../../../_bundle/Module1481"; import AnalyticsUtils from "../../../utils/AnalyticsUtils"; import * as _HapticUtils_native from "../../haptics/HapticUtils.native"; import useWindowDimensions_native from "../../screen/useWindowDimensions.native"; import useSafeAreaInsets_native from "../../safe_area/useSafeAreaInsets.native"; import useChatLayout from "../../chat/native/useChatLayout"; import { useHomeDrawerPeekHint } from "./useHomeDrawerPeekHint"; import * as _NavigationRouteUtils_native from "../../main_tabs_v2/helpers/NavigationRouteUtils.native"; import { coerceGuildsRoute } from "../../main_tabs_v2/helpers/NavigationRouteUtils.native"; import * as _spring from "../../../design/animation/reanimated/spring/spring"; import { Gesture } from "../../../_bundle/Module5273"; import { createFakeSharedValue } from "../../reanimated/ReanimatedHelperTypes"; const INITIAL_OPEN_WIDTH = 144; const HOME_GESTURE_DRAG_PHYSICS = { mass: 0.3, damping: 30, stiffness: 400 }; const HOME_DRAWER_FLING_PHYSICS = { mass: 0.4, damping: 100, stiffness: 250 }; const MAX_HOME_DRAWER_ANIMATING_WIDTH = 48; const ServerDrawerInteractAction = { PEEK: "PEEK", OPEN: "OPEN" }; const __initData = { code: "function useHomeDrawerGestureTsx1(){const{dragOffsetX,INITIAL_OPEN_WIDTH}=this.__closure;return dragOffsetX.get()>=INITIAL_OPEN_WIDTH;}" }; const __initData2 = { code: "function useHomeDrawerGestureTsx2(isOpen,wasOpen){const{GestureState,runOnJS,triggerHapticFeedback,HapticFeedbackTypes}=this.__closure;if(!GestureState.get().active||wasOpen===null){return;}if(isOpen===wasOpen){return;}if(isOpen){runOnJS(triggerHapticFeedback)(HapticFeedbackTypes.IMPACT_MEDIUM);}else{runOnJS(triggerHapticFeedback)(HapticFeedbackTypes.SOFT);}}" }; const __initData3 = { code: "function useHomeDrawerGestureTsx3(){const{panelX,peekX}=this.__closure;return panelX.get()+peekX.get();}" }; const __initData4 = { code: "function useHomeDrawerGestureTsx4(){const{isDrawerInitialized,initialPanelX,withSpring,panelX,GestureState,HOME_GESTURE_DRAG_PHYSICS,HOME_DRAWER_FLING_PHYSICS}=this.__closure;if(!isDrawerInitialized.get()){return initialPanelX;}return withSpring(panelX.get(),GestureState.get().active?HOME_GESTURE_DRAG_PHYSICS:HOME_DRAWER_FLING_PHYSICS,'animate-always');}" }; const __initData5 = { code: "function useHomeDrawerGestureTsx5(){const{panelGestureSpringX,peekX}=this.__closure;return panelGestureSpringX.get()+peekX.get();}" }; const __initData6 = { code: "function useHomeDrawerGestureTsx6(){const{safeAreaInsets,panelSpringTranslateX}=this.__closure;return{flex:1,marginTop:safeAreaInsets.top,transform:[{translateX:panelSpringTranslateX.get()}]};}" }; const __initData7 = { code: "function useHomeDrawerGestureTsx7(){const{drawerRevealX,MAX_HOME_DRAWER_ANIMATING_WIDTH,GUILD_DESCRIPTION_ANIMATION_DISTANCE,MIN_HOME_DRAWER_TEXT_OPACITY,MIN_HOME_DRAWER_OPEN_WIDTH,GUILD_LABEL_UNSNAPPED_SCALE,withSpring,HOME_DRAWER_FLING_PHYSICS,clamp}=this.__closure;let x=0;if(drawerRevealX.get()=MAX_HOME_DRAWER_ANIMATING_WIDTH?1:GUILD_LABEL_UNSNAPPED_SCALE;return{transform:[{translateX:withSpring(x,HOME_DRAWER_FLING_PHYSICS)},{scale:withSpring(scale,HOME_DRAWER_FLING_PHYSICS)}],opacity:withSpring(clamp(opacity,0,1),HOME_DRAWER_FLING_PHYSICS)};}" }; const __initData8 = { code: "function useHomeDrawerGestureTsx8(){const{drawerRevealX,MAX_HOME_DRAWER_ANIMATING_WIDTH,MAX_HOME_DRAWER_ICON_DISTANCE,withSpring,HOME_DRAWER_FLING_PHYSICS}=this.__closure;let x=0;if(drawerRevealX.get()FRACTION_OF_WIDTH_FOR_DRAWER_TO_REMAIN_OPEN*MaxX)return true;if(panelX.get()>=INITIAL_OPEN_WIDTH&&dragOffsetX.get()>0)return true;return false;}" }; const __initData12 = { code: "function useHomeDrawerGestureTsx12(){const{panelX,MaxX,settleDrawer,shouldOpenFromPosition,isPanelTouchActive,runOnJS,noteInteraction,GestureState,dragOffsetX}=this.__closure;if(panelX.get()>0&&panelX.get()FLING_MIN_VELOCITY&&dragOffsetX.get()>FLING_MIN_DISTANCE){shouldOpen=true;if(dragOffsetX.get()0;if(shouldOpen){runOnJS(trackServerDrawerInteract)(ServerDrawerInteractAction.OPEN);}else if(!wasOpenAtStart){runOnJS(trackServerDrawerInteract)(ServerDrawerInteractAction.PEEK);}}" }; const __initData14 = { code: "function useHomeDrawerGestureTsx14(event){const{GestureState,dragOffsetX,INITIAL_OPEN_WIDTH,panelX,DRAWER_RESISTANCE}=this.__closure;if(!GestureState.get().active)return;const newXOffset=event.absoluteX-GestureState.get().initialX;dragOffsetX.set(newXOffset);const basePosition=newXOffset+GestureState.get().panelX;if(GestureState.get().panelX===0&&newXOffset>=0&&newXOffsetabsoluteXDiff||panelX.get()===0&&touchX0&&touchX>GestureState.get().initialX){manager.fail();return;}if(absoluteXDiffGestureState.get().initialX){GestureState.set({...GestureState.get(),active:true,initialX:touchX,panelX:panelX.get()});manager.activate();}else if(touchX { AnalyticsUtils.track(AnalyticEvents.SERVER_DRAWER_INTERACT, { action: a0 }); }, []); const W = () => sharedValue.get() >= INITIAL_OPEN_WIDTH; W.__closure = { dragOffsetX: sharedValue, INITIAL_OPEN_WIDTH }; W.__workletHash = 2525772891435; W.__initData = __initData; const C = function C(a0, a1) { if (GestureState.get().active && a1 !== null && a0 !== a1) { const r20 = _ReanimatedRexport.runOnJS(_HapticUtils_native.triggerHapticFeedback); if (a0) { r20(_HapticUtils_native.HapticFeedbackTypes.IMPACT_MEDIUM); } else { r20(_HapticUtils_native.HapticFeedbackTypes.SOFT); } } }; C.__closure = { GestureState, runOnJS: _ReanimatedRexport.runOnJS, triggerHapticFeedback: _HapticUtils_native.triggerHapticFeedback, HapticFeedbackTypes: _HapticUtils_native.HapticFeedbackTypes }; C.__workletHash = 11947599708940; C.__initData = __initData2; useAnimatedReaction(W, C); const windowDimensions_native = useWindowDimensions_native(); c21462_11 = windowDimensions_native; const safeAreaInsets_native = useSafeAreaInsets_native(); c21462_12 = safeAreaInsets_native; const isChatBesideChannelList = useChatLayout().isChatBesideChannelList; if (enableHome) { enableHome = !isChatBesideChannelList; } c21462_13 = enableHome; const isFocused2 = useIsFocused(); isFocused = enableHome ? isFocused2 : enableHome; sharedValue3 = useSharedValue(0); useHomeDrawerPeekHint(enableHome ? enablePeekHint : enableHome, sharedValue3); const ne = () => panelX.get() + sharedValue3.get(); ne.__closure = { panelX, peekX: sharedValue3 }; ne.__workletHash = 4654854314200; ne.__initData = __initData3; derivedValue = useDerivedValue(ne); const state = navigation.getState(); const r4 = state == null; let r106 = void 0; if (!r4) { const routes = state.routes; const r107 = routes == null; r106 = void 0; if (!r107) { let r32 = state?.index; if (r32 == null) { r32 = 0; } r106 = routes[r32]; } } const r109 = coerceGuildsRoute(r106); let r110 = enableHome; if (r110) { let r112 = r109 == null ? void 0 : r109.params?.drawerOpen; if (r112 == null) { r112 = landOnHome2; } r110 = r112; } landOnHome = r110; const initialPanelX = landOnHome ? computeMaxX(windowDimensions_native, safeAreaInsets_native) : 0; c21462_18 = initialPanelX; useEffect(() => { if (c21462_13) { updateMaxX(c21462_11, c21462_12); } else { updateMaxX({ width: 0, height: 0 }, { top: 0, bottom: 0, left: 0, right: 0 }); } }, [windowDimensions_native, safeAreaInsets_native, updateMaxX, enableHome]); useEffect(() => { if (!c21462_13) { panelX.set(0); _NavigationRouteUtils_native.setHomeDrawerState(false); } }, [enableHome, panelX]); useEffect(() => { const handleStateChange2 = function handleStateChange(a0) { const state = a0.data.state; const r3 = state == null; let r15 = void 0; if (!r3) { const routes = state.routes; const r16 = routes == null; r15 = void 0; if (!r16) { let r8 = state?.index; if (r8 == null) { r8 = 0; } r15 = routes[r8]; } } const r18 = coerceGuildsRoute(r15); if (r18 != null && c21462_13) { const r25 = r18.params?.drawerOpen === true; setPanelX(r25 ? "open" : "closed"); const state2 = HomeDrawerSubtitleStore.getState(); if (r25) { state2.startTimer(); } else { state2.stopTimer(); } } }; navigation.addListener("state", handleStateChange2); return () => { navigation.removeListener("state", handleStateChange2); HomeDrawerSubtitleStore.getState().stopTimer(); }; }, [navigation, setPanelX, enableHome]); ref = useRef(false); useLayoutEffect(() => { if (c21462_13 && !ref.current) { panelX.set(c21462_18); if (landOnHome) { HomeDrawerSubtitleStore.getState().startTimer(); } ref.current = true; } }, [enableHome, landOnHome, initialPanelX, panelX]); useEffect(() => { if (ref.current) { sharedValue2.set(true); } }, [enableHome, sharedValue2]); const Ie = function Ie() { return sharedValue2.get() ? _spring.withSpring(panelX.get(), GestureState.get().active ? HOME_GESTURE_DRAG_PHYSICS : HOME_DRAWER_FLING_PHYSICS, "animate-always") : c21462_18; }; Ie.__closure = { isDrawerInitialized: sharedValue2, initialPanelX, withSpring: _spring.withSpring, panelX, GestureState, HOME_GESTURE_DRAG_PHYSICS, HOME_DRAWER_FLING_PHYSICS }; Ie.__workletHash = 11078734703352; Ie.__initData = __initData4; derivedValue2 = useDerivedValue(Ie); const ge = () => derivedValue2.get() + sharedValue3.get(); ge.__closure = { panelGestureSpringX: derivedValue2, peekX: sharedValue3 }; ge.__workletHash = 2927026959998; ge.__initData = __initData5; derivedValue3 = useDerivedValue(ge); const Se = () => ({ flex: 1, marginTop: c21462_12.top, transform: [{ translateX: derivedValue3.get() }] }); Se.__closure = { safeAreaInsets: safeAreaInsets_native, panelSpringTranslateX: derivedValue3 }; Se.__workletHash = 13544610996653; Se.__initData = __initData6; animatedStyle = useAnimatedStyle(Se); const Ae = function Ae() { const r13 = derivedValue.get() < MAX_HOME_DRAWER_ANIMATING_WIDTH ? Math.min(12, derivedValue.get() / MAX_HOME_DRAWER_ANIMATING_WIDTH * 12) : 0; const r23 = derivedValue.get() / 150; const r1 = derivedValue.get() >= MAX_HOME_DRAWER_ANIMATING_WIDTH ? 1 : 0.98; const r29 = 0 + r23 * 1; return { transform: [{ translateX: _spring.withSpring(r13, HOME_DRAWER_FLING_PHYSICS) }, { scale: _spring.withSpring(r1, HOME_DRAWER_FLING_PHYSICS) }], opacity: _spring.withSpring(_ReanimatedRexport.clamp(r29, 0, 1), HOME_DRAWER_FLING_PHYSICS) }; }; Ae.__closure = { drawerRevealX: derivedValue, MAX_HOME_DRAWER_ANIMATING_WIDTH, GUILD_DESCRIPTION_ANIMATION_DISTANCE: 12, MIN_HOME_DRAWER_TEXT_OPACITY: 0, MIN_HOME_DRAWER_OPEN_WIDTH: 150, GUILD_LABEL_UNSNAPPED_SCALE: 0.98, withSpring: _spring.withSpring, HOME_DRAWER_FLING_PHYSICS, clamp: _ReanimatedRexport.clamp }; Ae.__workletHash = 11639414708115; Ae.__initData = __initData7; animatedStyle2 = useAnimatedStyle(Ae); const De = function De() { return { transform: [{ translateX: _spring.withSpring(derivedValue.get() < MAX_HOME_DRAWER_ANIMATING_WIDTH ? Math.min(8, derivedValue.get() / MAX_HOME_DRAWER_ANIMATING_WIDTH * 8) : 0, HOME_DRAWER_FLING_PHYSICS) }] }; }; De.__closure = { drawerRevealX: derivedValue, MAX_HOME_DRAWER_ANIMATING_WIDTH, MAX_HOME_DRAWER_ICON_DISTANCE: 8, withSpring: _spring.withSpring, HOME_DRAWER_FLING_PHYSICS }; De.__workletHash = 16360618332998; De.__initData = __initData8; animatedStyle3 = useAnimatedStyle(De); const pe = function pe() { return { transform: [{ translateX: _spring.withSpring(derivedValue.get() < MAX_HOME_DRAWER_ANIMATING_WIDTH ? -Math.min(4, derivedValue.get() / MAX_HOME_DRAWER_ANIMATING_WIDTH * 4) : 0, HOME_DRAWER_FLING_PHYSICS) }] }; }; pe.__closure = { drawerRevealX: derivedValue, MAX_HOME_DRAWER_ANIMATING_WIDTH, UNREAD_INDICATOR_ANIMATION_DISTANCE: 4, withSpring: _spring.withSpring, HOME_DRAWER_FLING_PHYSICS }; pe.__workletHash = 8561772429103; pe.__initData = __initData9; animatedStyle4 = useAnimatedStyle(pe); memo = useMemo(() => { let settleDrawer2, shouldOpenFromPosition2; const settleDrawer = function settleDrawer(a0) { panelX.set(a0 ? MaxX : 0); _ReanimatedRexport.runOnJS(_NavigationRouteUtils_native.setHomeDrawerState)(a0); }; settleDrawer.__closure = { panelX, MaxX, runOnJS: _ReanimatedRexport.runOnJS, setHomeDrawerState: _NavigationRouteUtils_native.setHomeDrawerState }; settleDrawer.__workletHash = 8226756372642; settleDrawer.__initData = __initData10; settleDrawer2 = settleDrawer; const shouldOpenFromPosition = function shouldOpenFromPosition() { return panelX.get() !== 0 && (panelX.get() > 0.5 * MaxX || panelX.get() >= INITIAL_OPEN_WIDTH && sharedValue.get() > 0); }; shouldOpenFromPosition.__closure = { panelX, FRACTION_OF_WIDTH_FOR_DRAWER_TO_REMAIN_OPEN: 0.5, MaxX, INITIAL_OPEN_WIDTH, dragOffsetX: sharedValue }; shouldOpenFromPosition.__workletHash = 11654084007114; shouldOpenFromPosition.__initData = __initData11; shouldOpenFromPosition2 = shouldOpenFromPosition; const r44 = Gesture.Pan().enabled(isFocused).manualActivation(true).shouldCancelWhenOutside(false).maxPointers(1); const _ = function _(a0) { isPanelTouchActive.set(true); GestureState.set({ active: false, initialX: a0.absoluteX, initialY: a0.absoluteY, panelX: panelX.get() }); }; _.__closure = { isPanelTouchActive, GestureState, panelX }; _.__workletHash = 8825829705900; _.__initData = __initData16; const r49 = r44.onBegin(_); const r51 = function(a0, a1) { L14: { if (!GestureState.get().active) { L13: { const absoluteX = a0.changedTouches[0].absoluteX; const absoluteY = a0.changedTouches[0].absoluteY; const r26 = Math.abs(absoluteX - GestureState.get().initialX); if (!(Math.abs(absoluteY - GestureState.get().initialY) > r26)) { if (panelX.get() === 0 && absoluteX < GestureState.get().initialX) { break L13; } if (panelX.get() > 0 && absoluteX > GestureState.get().initialX) { break L13; } if (r26 < 10) { break L14; } if (!(panelX.get() === 0 && absoluteX > GestureState.get().initialX || absoluteX < GestureState.get().initialX)) { break L14; } GestureState.set({ ...GestureState.get(), active: true, initialX: absoluteX, panelX: panelX.get() }); a1.activate(); break L14; } } a1.fail(); } } }; r51.__closure = { GestureState, panelX, ACTIVATION_MIN_DISTANCE: 10 }; r51.__workletHash = 7484113391171; r51.__initData = __initData15; const r55 = r49.onTouchesMove(r51); const n = function n(a0) { L6: { if (GestureState.get().active) { const r15 = a0.absoluteX - GestureState.get().initialX; sharedValue.set(r15); const r21 = r15 + GestureState.get().panelX; if (GestureState.get().panelX === 0 && r15 >= 0 && r15 < INITIAL_OPEN_WIDTH) { panelX.set(Math.max(r21 / 3, 0)); break L6; } panelX.set(Math.max(r21, 0)); } } }; n.__closure = { GestureState, dragOffsetX: sharedValue, INITIAL_OPEN_WIDTH, panelX, DRAWER_RESISTANCE: 3 }; n.__workletHash = 15118338555898; n.__initData = __initData14; const r61 = r55.onChange(n); const t = function t(a0) { let r3; L16: { if (a0.velocityX > 50 && sharedValue.get() > 40) { const r67 = sharedValue.get() < INITIAL_OPEN_WIDTH; r3 = true; if (!r67) { break L16; } _ReanimatedRexport.runOnJS(_HapticUtils_native.triggerHapticFeedback)(_HapticUtils_native.HapticFeedbackTypes.IMPACT_MEDIUM); r3 = true; } else if (a0.velocityX < -50 && sharedValue.get() < -40) { _ReanimatedRexport.runOnJS(_HapticUtils_native.triggerHapticFeedback)(_HapticUtils_native.HapticFeedbackTypes.SOFT); r3 = false; } else { r3 = panelX.get() !== 0 && (panelX.get() > 0.5 * MaxX || panelX.get() >= INITIAL_OPEN_WIDTH && sharedValue.get() > 0); } } panelX.set(r3 ? MaxX : 0); _ReanimatedRexport.runOnJS(_NavigationRouteUtils_native.setHomeDrawerState)(r3); const r114 = GestureState.get().panelX > 0; if (r3) { _ReanimatedRexport.runOnJS(callback)(ServerDrawerInteractAction.OPEN); } else if (!r114) { _ReanimatedRexport.runOnJS(callback)(ServerDrawerInteractAction.PEEK); } }; t.__closure = { FLING_MIN_VELOCITY: 50, dragOffsetX: sharedValue, FLING_MIN_DISTANCE: 40, INITIAL_OPEN_WIDTH, runOnJS: _ReanimatedRexport.runOnJS, triggerHapticFeedback: _HapticUtils_native.triggerHapticFeedback, HapticFeedbackTypes: _HapticUtils_native.HapticFeedbackTypes, shouldOpenFromPosition: shouldOpenFromPosition2, settleDrawer: settleDrawer2, GestureState, trackServerDrawerInteract: callback, ServerDrawerInteractAction }; t.__workletHash = 11139594764616; t.__initData = __initData13; const r77 = r61.onEnd(t); const e = function e() { if (panelX.get() > 0 && panelX.get() < MaxX) { const r4 = panelX.get() !== 0 && (panelX.get() > 0.5 * MaxX || panelX.get() >= INITIAL_OPEN_WIDTH && sharedValue.get() > 0); panelX.set(r4 ? MaxX : 0); _ReanimatedRexport.runOnJS(_NavigationRouteUtils_native.setHomeDrawerState)(r4); } isPanelTouchActive.set(false); _ReanimatedRexport.runOnJS(noteInteraction)(); GestureState.set({ active: false, initialX: 0, initialY: 0, panelX: 0 }); sharedValue.set(0); }; e.__closure = { panelX, MaxX, settleDrawer: settleDrawer2, shouldOpenFromPosition: shouldOpenFromPosition2, isPanelTouchActive, runOnJS: _ReanimatedRexport.runOnJS, noteInteraction, GestureState, dragOffsetX: sharedValue }; e.__workletHash = 15210416953749; e.__initData = __initData12; return r77.onFinalize(e); }, [GestureState, panelX, sharedValue, isFocused, MaxX, isPanelTouchActive, noteInteraction, callback]); return { gesture: memo, panelStyles: animatedStyle, homeDrawerState: _slicedToArray(useState(() => ({ gesture: memo, panelStyles: animatedStyle, GestureState, panelX, panelSpringTranslateX: derivedValue3, guildsBarLabelDrawerStyle: animatedStyle2, guildsBarIconDrawerStyle: animatedStyle3, guildsBarUnreadDrawerStyle: animatedStyle4 })), 1)[0] }; } export { context as HomeDrawerStateContext };