Files
discord-decomp/modules/parent_tools/hooks/useIsOnMainSurface.native.tsx
T
2026-11-01 12:12:55 +02:00

64 lines
1.9 KiB
TypeScript

// Metro module 15824 (f15825).
import { useState, useEffect } from "react";
import { getRootNavigationRef } from "../../main_tabs_v2/RootNavigationRef.native";
let c11318_4;
const getIsOnMainSurface = function getIsOnMainSurface() {
const rootNavigationRef2 = getRootNavigationRef();
if (rootNavigationRef2 != null && rootNavigationRef2.isReady()) {
const rootState = rootNavigationRef2.getRootState();
const r3 = rootState != null;
let r16 = void 0;
if (r3) {
const length = rootState.routes.length;
r16 = void 0;
if (length !== 0) {
const routes = rootState.routes;
let index = rootState.index;
if (index == null) {
index = rootState.routes.length - 1;
}
r16 = routes[index];
}
}
if (r16?.name !== "main") {
return false;
}
const state = r16.state;
const r27 = state != null;
let r28 = void 0;
if (r27) {
const length2 = state.routes.length;
r28 = void 0;
if (length2 !== 0) {
const routes2 = state.routes;
let index2 = state.index;
if (index2 == null) {
index2 = state.routes.length - 1;
}
r28 = routes2[index2];
}
}
return r28 != null && c11318_4.has(r28.name);
}
return false;
};
c11318_4 = new Set(["tabs", "channel"]);
export function useIsOnMainSurface() {
const [state, setState] = useState(getIsOnMainSurface);
useEffect(() => {
let rootNavigationRef;
const handleNavigationChange2 = function handleNavigationChange() {
return setState(getIsOnMainSurface());
};
rootNavigationRef = getRootNavigationRef();
if (rootNavigationRef != null) {
setState(getIsOnMainSurface());
rootNavigationRef.addListener("state", handleNavigationChange2);
return () => {
rootNavigationRef.removeListener("state", handleNavigationChange2);
};
}
}, []);
return state;
}