Files
discord-decomp/modules/quests/native/QuestDock/QuestDockHooks.tsx
T
2026-11-01 12:12:55 +02:00

205 lines
13 KiB
TypeScript

// Metro module 14119 (f14120).
import { useContext, useMemo, useEffect, useCallback } from "react";
import QuestDockStore from "./QuestDockStore";
import { QuestDockMode } from "../../QuestConstants";
import { QUEST_DOCK_CLOSED_HEIGHT, QUEST_DOCK_COLLAPSED_HEIGHT, QUEST_DOCK_EXTERNAL_OFFSET_CLOSED, QUEST_DOCK_EXTERNAL_OFFSET_COLLAPSED_WITH_YOU_BAR, QUEST_DOCK_EXTERNAL_OFFSET_EXPANDED_WITH_YOU_BAR, QUEST_DOCK_VERTICAL_EDGE_GUTTER_EXPANDED } from "./QuestDockConstants";
import { QuestDockGestureContext } from "./QuestDockGestureContext";
import { QuestDockExternalCoordinationContext } from "./QuestDockExternalCoordinationContext";
import useSafeAreaInsetsSharedValue_native from "../../../safe_area/useSafeAreaInsetsSharedValue.native";
import { useYouBarHorizontalMargin } from "../../../main_tabs_v2/native/you_bar/hooks/useYouBarMargins";
import { useYouBarTotalHeight } from "../../../main_tabs_v2/native/you_bar/hooks/useYouBarTotalHeight";
import * as _ReanimatedRexport from "../../../reanimated/ReanimatedRexport";
import { useAnimatedReaction } from "../../../reanimated/ReanimatedRexport";
import * as _cheapWorkletShallowEqual from "../../../reanimated/native/cheapWorkletShallowEqual";
import * as _QuestDockUtils from "./QuestDockUtils";
import { isSoftDismissed } from "./QuestDockUtils";
import { useStateFromStoresArray } from "../../../../_bundle/Module589";
import Durations from "../../../../utils/Durations";
import { useTrackQuestContentClickedWithImpression } from "../../lib/analytics/AnalyticsHooks";
import { useQuestImpressionId } from "../../lib/analytics/ContentImpressionTrackerHooks";
import { shouldMigrateToAdAnalyticsInterface, AdAnalyticsInterfaceExperimentStep } from "../../experiments/AdAnalyticsInterfaceExperiment";
import { captureAdUserAction } from "../../../ads/analytics/captureAdUserAction";
import { AdUserActionType } from "../../../ads/analytics/captureAdUserActionTypes";
import { AdCreativeType } from "../../../../_bundle/Module6013";
import { QuestContentCTA } from "../../lib/analytics/AnalyticsTypes";
import { QuestContent } from "../../QuestTypes";
import ActionSheetActionCreators from "../../../action_sheet/native/ActionSheetActionCreators";
const __initData = {
code: "function QuestDockHooksTsx1(){const{restingQuestDockMode,minExpandedContentHeight,windowDimensions,safeArea}=this.__closure;return{restingQuestDockMode:restingQuestDockMode.get(),minExpandedContentHeight:minExpandedContentHeight.get(),windowWidth:windowDimensions.get().width,windowHeight:windowDimensions.get().height,safeArea:safeArea.get()};}"
};
const __initData2 = {
code: "function QuestDockHooksTsx2(props,previous){const{cheapWorkletShallowEqual,QuestDockMode,runOnJS,setRestingQuestDockMode,questDockWrapperSpecs,getQuestDockCollapsedWidth,youBarHorizontalMargin,QUEST_DOCK_COLLAPSED_HEIGHT,activeQuestDockMode,getQuestDockClosedWidth,QUEST_DOCK_CLOSED_HEIGHT,getQuestDockExpandedHeightLimits,youBarHeight,QUEST_DOCK_VERTICAL_EDGE_GUTTER_EXPANDED,getQuestDockExpandedWidth}=this.__closure;var _previous$restingQues;if(cheapWorkletShallowEqual(props,previous!==null&&previous!==void 0?previous:undefined))return;const{restingQuestDockMode:restingQuestDockMode,minExpandedContentHeight:minExpandedContentHeight,windowWidth:windowWidth,windowHeight:windowHeight,safeArea:safeArea}=props;switch(restingQuestDockMode){case QuestDockMode.RESET_TO_PREVIOUS:runOnJS(setRestingQuestDockMode)((_previous$restingQues=previous===null||previous===void 0?void 0:previous.restingQuestDockMode)!==null&&_previous$restingQues!==void 0?_previous$restingQues:QuestDockMode.COLLAPSED);return;case QuestDockMode.COLLAPSED:questDockWrapperSpecs.set({...questDockWrapperSpecs.get(),x:0,y:0,width:getQuestDockCollapsedWidth(windowWidth,youBarHorizontalMargin,youBarHorizontalMargin),height:QUEST_DOCK_COLLAPSED_HEIGHT});activeQuestDockMode.set(QuestDockMode.COLLAPSED);break;case QuestDockMode.CLOSED:case QuestDockMode.SOFT_DISMISSED:questDockWrapperSpecs.set({...questDockWrapperSpecs.get(),x:0,y:0,width:getQuestDockClosedWidth(windowWidth,youBarHorizontalMargin,youBarHorizontalMargin),height:QUEST_DOCK_CLOSED_HEIGHT});activeQuestDockMode.set(restingQuestDockMode);break;case QuestDockMode.EXPANDED:const minContentHeight=minExpandedContentHeight;const{minHeight:minHeight,maxHeight:maxHeight}=getQuestDockExpandedHeightLimits(windowHeight,safeArea.top,minContentHeight);const heightMidpoint=(maxHeight+minHeight)/2;let height;if(questDockWrapperSpecs.get().height<=QUEST_DOCK_COLLAPSED_HEIGHT){height=maxHeight;}else if(previous!=null&&questDockWrapperSpecs.get().height===getQuestDockExpandedHeightLimits(previous.windowHeight,previous.safeArea.top,minContentHeight).maxHeight){height=maxHeight;}else if(questDockWrapperSpecs.get().height>=heightMidpoint){height=maxHeight;}else{height=maxHeight;}questDockWrapperSpecs.set({...questDockWrapperSpecs.get(),x:0,y:youBarHeight>0?youBarHeight:QUEST_DOCK_VERTICAL_EDGE_GUTTER_EXPANDED,width:getQuestDockExpandedWidth(windowWidth,safeArea.left,safeArea.right),height:height});activeQuestDockMode.set(QuestDockMode.EXPANDED);break;}}"
};
export function useQuestDockModeAnimatedReaction() {
const context = useContext(QuestDockGestureContext);
const { questDockWrapperSpecs, windowDimensions, activeQuestDockMode, minExpandedContentHeight } = context;
const context2 = useContext(QuestDockExternalCoordinationContext);
const { restingQuestDockMode, setRestingQuestDockMode } = context2;
const safeAreaInsetsSharedValue_native = useSafeAreaInsetsSharedValue_native();
let c20926_6 = safeAreaInsetsSharedValue_native;
const youBarHorizontalMargin = useYouBarHorizontalMargin();
const youBarTotalHeight = useYouBarTotalHeight();
const r39 = () => ({
restingQuestDockMode: restingQuestDockMode.get(),
minExpandedContentHeight: minExpandedContentHeight.get(),
windowWidth: windowDimensions.get().width,
windowHeight: windowDimensions.get().height,
safeArea: c20926_6.get()
});
r39.__closure = {
restingQuestDockMode,
minExpandedContentHeight,
windowDimensions,
safeArea: safeAreaInsetsSharedValue_native
};
r39.__workletHash = 9502251090521;
r39.__initData = __initData;
const t = function t(a0, a1) {
const r26 = a1 == null ? void 0 : a1;
L24: {
if (!_cheapWorkletShallowEqual.cheapWorkletShallowEqual(a0, r26)) {
const { restingQuestDockMode: restingQuestDockMode2, minExpandedContentHeight: minExpandedContentHeight2, windowWidth, windowHeight, safeArea } = a0;
if (QuestDockMode.RESET_TO_PREVIOUS === restingQuestDockMode2) {
const r114 = _ReanimatedRexport.runOnJS(setRestingQuestDockMode);
let r116 = a1?.restingQuestDockMode;
if (r116 == null) {
r116 = QuestDockMode.COLLAPSED;
}
r114(r116);
return void 0;
}
if (QuestDockMode.COLLAPSED === restingQuestDockMode2) {
questDockWrapperSpecs.set({
...questDockWrapperSpecs.get(),
x: 0,
y: 0,
width: _QuestDockUtils.getQuestDockCollapsedWidth(windowWidth, youBarHorizontalMargin, youBarHorizontalMargin),
height: QUEST_DOCK_COLLAPSED_HEIGHT
});
activeQuestDockMode.set(QuestDockMode.COLLAPSED);
} else {
if (QuestDockMode.CLOSED !== restingQuestDockMode2 && QuestDockMode.SOFT_DISMISSED !== restingQuestDockMode2) {
if (QuestDockMode.EXPANDED !== restingQuestDockMode2) {
break L24;
}
const questDockExpandedHeightLimits = _QuestDockUtils.getQuestDockExpandedHeightLimits(windowHeight, safeArea.top, minExpandedContentHeight2);
questDockExpandedHeightLimits.minHeight;
const maxHeight = questDockExpandedHeightLimits.maxHeight;
if (!(questDockWrapperSpecs.get().height <= QUEST_DOCK_COLLAPSED_HEIGHT || a1 != null && questDockWrapperSpecs.get().height === _QuestDockUtils.getQuestDockExpandedHeightLimits(a1.windowHeight, a1.safeArea.top, minExpandedContentHeight2).maxHeight)) {
questDockWrapperSpecs.get().height;
}
const r58 = {
...questDockWrapperSpecs.get(),
x: 0
};
let r61 = youBarTotalHeight;
if (!(youBarTotalHeight > 0)) {
r61 = QUEST_DOCK_VERTICAL_EDGE_GUTTER_EXPANDED;
}
r58.y = r61;
r58.width = _QuestDockUtils.getQuestDockExpandedWidth(windowWidth, safeArea.left, safeArea.right);
r58.height = maxHeight;
questDockWrapperSpecs.set(r58);
activeQuestDockMode.set(QuestDockMode.EXPANDED);
break L24;
}
questDockWrapperSpecs.set({
...questDockWrapperSpecs.get(),
x: 0,
y: 0,
width: _QuestDockUtils.getQuestDockClosedWidth(windowWidth, youBarHorizontalMargin, youBarHorizontalMargin),
height: QUEST_DOCK_CLOSED_HEIGHT
});
activeQuestDockMode.set(restingQuestDockMode2);
}
}
}
};
t.__closure = {
cheapWorkletShallowEqual: _cheapWorkletShallowEqual.cheapWorkletShallowEqual,
QuestDockMode,
runOnJS: _ReanimatedRexport.runOnJS,
setRestingQuestDockMode,
questDockWrapperSpecs,
getQuestDockCollapsedWidth: _QuestDockUtils.getQuestDockCollapsedWidth,
youBarHorizontalMargin,
QUEST_DOCK_COLLAPSED_HEIGHT,
activeQuestDockMode,
getQuestDockClosedWidth: _QuestDockUtils.getQuestDockClosedWidth,
QUEST_DOCK_CLOSED_HEIGHT,
getQuestDockExpandedHeightLimits: _QuestDockUtils.getQuestDockExpandedHeightLimits,
youBarHeight: youBarTotalHeight,
QUEST_DOCK_VERTICAL_EDGE_GUTTER_EXPANDED,
getQuestDockExpandedWidth: _QuestDockUtils.getQuestDockExpandedWidth
};
t.__workletHash = 2510234714195;
t.__initData = __initData2;
useAnimatedReaction(r39, t);
}
export function useQuestDockExternalOffset() {
let c20927_0, c20927_1;
const [r15, r16] = useStateFromStoresArray([QuestDockStore], () => [QuestDockStore.prevRestingQuestDockMode, QuestDockStore.isEligibleToBeVisible]);
c20927_0 = r15;
c20927_1 = r16;
return useMemo(() => {
if (c20927_1) {
if (QuestDockMode.COLLAPSED === c20927_0) {
return QUEST_DOCK_EXTERNAL_OFFSET_COLLAPSED_WITH_YOU_BAR;
}
if (QuestDockMode.EXPANDED === c20927_0) {
return QUEST_DOCK_EXTERNAL_OFFSET_EXPANDED_WITH_YOU_BAR;
}
if (QuestDockMode.CLOSED !== c20927_0 && QuestDockMode.SOFT_DISMISSED !== c20927_0) {
return 0;
}
return QUEST_DOCK_EXTERNAL_OFFSET_CLOSED;
}
return 0;
}, [r16, r15]);
}
export function useQuestDockDismissalReset() {
const setRestingQuestDockMode2 = useContext(QuestDockExternalCoordinationContext).setRestingQuestDockMode;
const activeQuestDockMode2 = useContext(QuestDockGestureContext).activeQuestDockMode;
useEffect(() => {
if (!(activeQuestDockMode2.get() !== QuestDockMode.SOFT_DISMISSED || isSoftDismissed(QuestDockStore.questDockSoftDismissedAt))) {
setRestingQuestDockMode2(QuestDockMode.COLLAPSED);
}
let c27641_0 = setInterval(function maybeResetSoftDismissal() {
if (!(activeQuestDockMode2.get() !== QuestDockMode.SOFT_DISMISSED || isSoftDismissed(QuestDockStore.questDockSoftDismissedAt))) {
setRestingQuestDockMode2(QuestDockMode.COLLAPSED);
}
}, 5 * Durations.Millis.MINUTE);
return () => {
clearInterval(c27641_0);
};
}, [setRestingQuestDockMode2, activeQuestDockMode2]);
}
export function useActionSheetPressHandler(a0) {
const quest = a0;
const trackQuestContentClickedWithImpression = useTrackQuestContentClickedWithImpression();
const questImpressionId = useQuestImpressionId();
return useCallback(() => {
if (shouldMigrateToAdAnalyticsInterface(AdAnalyticsInterfaceExperimentStep.STEP_2_CLICKED_INTERNAL, "quest_dock_action_sheet")) {
captureAdUserAction({
type: AdUserActionType.CLICK_INTERNAL,
adCreativeType: AdCreativeType.QUEST,
adCreativeId: quest.id,
questContentCTA: QuestContentCTA.OPEN_CONTEXT_MENU,
surfaceId: QuestContent.QUEST_BAR_MOBILE,
sourceQuestContent: QuestContent.QUEST_BAR_MOBILE,
impressionId: questImpressionId
});
} else {
trackQuestContentClickedWithImpression({
questId: quest.id,
questContent: QuestContent.QUEST_BAR_MOBILE,
questContentCTA: QuestContentCTA.OPEN_CONTEXT_MENU,
sourceQuestContent: QuestContent.QUEST_BAR_MOBILE
});
}
ActionSheetActionCreators.openLazy(import("./QuestDockContextMenuActionSheet"), "QuestDockContextMenuActionSheet", {
quest
});
}, [a0, trackQuestContentClickedWithImpression, questImpressionId]);
}