Files
discord-decomp/modules/app_launcher/native/AppLauncherKeyboard.tsx
T
2026-11-01 12:12:55 +02:00

197 lines
8.2 KiB
TypeScript

// Metro module 11208 (f11209).
import { memo, useRef, useCallback, useEffect, useLayoutEffect } from "react";
import { View } from "react-native";
import { AnalyticEvents } from "../../../Constants";
import { ContentDismissActionType } from "../../dismissible_content/DismissibleContentConstants";
import { KEYBOARD_ANIMATION_CONFIG } from "../../keyboard/native/PortalKeyboardConstants";
import { createStyles } from "../../../design/components/Styles/native/createStyles";
import Module712 from "../../../_bundle/Module712";
import { useDefaultAppLauncherWidth } from "./hooks/useDefaultAppLauncherWidth";
import { AppLauncherKeyboardCloseReason, AppLauncherBottomSheetExpandReason } from "./AppLauncherContext";
import useKeyboardActionSheetHeight from "../../action_sheet/native/useKeyboardActionSheetHeight";
import { useIsScreenReaderEnabled } from "../../a11y/native/useIsScreenReaderEnabled.native";
import useAppLauncherOnboardingContent from "./onboarding/hooks/useAppLauncherOnboardingContent";
import * as _ReanimatedRexport from "../../reanimated/ReanimatedRexport";
import { useSharedValue, useAnimatedReaction } from "../../reanimated/ReanimatedRexport";
import completeAppLauncherOnboarding from "./onboarding/utils/completeAppLauncherOnboarding";
import { TransitionStates } from "../../../design/components/TransitionGroup/TransitionGroup";
import { BottomSheetBackdrop, ANIMATION_SOURCE } from "../../../_bundle/Module5245";
import AppLauncherOnboardingLayer from "./onboarding/banner/AppLauncherOnboardingLayer";
import { isAndroid } from "../../../utils/PlatformUtils";
import { trackWithMetadata } from "../../app_analytics/AppAnalyticsUtils";
import { isMetaQuest } from "../../device/MetaQuestUtils.android";
import { setKeyboardType } from "../../keyboard/native/KeyboardUIStore.native";
import { KeyboardTypes } from "../../keyboard/native/KeyboardTypes";
import { setAccessibilityFocus } from "../../a11y/native/setAccessibilityFocus.android";
import PortalKeyboardBottomSheet from "../../keyboard/native/PortalKeyboardBottomSheet";
import { AppLauncherEntrypoint } from "../AppLauncherTypes";
import AppLauncherNavigator from "./AppLauncherNavigator";
const useStyles = createStyles({
onboardingRoundingView: {
borderTopLeftRadius: Module712.radii.sm,
borderTopRightRadius: Module712.radii.sm
},
onboardingHeader: {
borderWidth: 2,
borderBottomWidth: 0,
borderColor: Module712.colors.BACKGROUND_BRAND,
borderBottomColor: "transparent",
borderTopLeftRadius: Module712.radii.sm,
borderTopRightRadius: Module712.radii.sm
},
onboardingNavigatorContent: {
borderWidth: 2,
borderColor: Module712.colors.BACKGROUND_BRAND,
borderTopLeftRadius: Module712.radii.sm,
borderTopRightRadius: Module712.radii.sm
}
});
const ref = null;
const __initData = {
code: "function AppLauncherKeyboardTsx1(){const{bottomSheetIndex}=this.__closure;return bottomSheetIndex.get();}"
};
const __initData2 = {
code: "function AppLauncherKeyboardTsx2(i,prev){const{runOnJS,handleOnboardingParamChange,showOnboarding}=this.__closure;if(i===prev)return;runOnJS(handleOnboardingParamChange)(i,showOnboarding);}"
};
const r77 = memo(function AppLauncherKeyboard(props) {
let callback;
const { context, chatInputRef, onClose, transitionState, entrypoint } = props;
callback = void 0;
const defaultAppLauncherWidth = useDefaultAppLauncherWidth(entrypoint);
const ref2 = useRef(AppLauncherKeyboardCloseReason.DISMISSED);
const ref3 = useRef(void 0);
const styles = useStyles();
const keyboardActionSheetHeight = useKeyboardActionSheetHeight();
const { maximum, minimum } = keyboardActionSheetHeight;
const ref4 = useRef(Date.now());
const ref5 = useRef(false);
let forceMaxHeight = useIsScreenReaderEnabled();
const isScreenReaderEnabled = forceMaxHeight;
const visibleContent = useAppLauncherOnboardingContent({
channelId: context.channel.id
}).visibleContent;
let showOnboarding = visibleContent != null;
let c18623_11 = showOnboarding;
const sharedValue = useSharedValue(-1);
const sharedValue2 = useSharedValue(0);
const ref6 = useRef(null);
const callback2 = useCallback(() => {
if (ref6 != null) {
const current = ref6.current;
if (current != null) {
current.expandActionSheet();
}
}
}, [ref6]);
callback = useCallback((a0, a1) => {
if (a1 ? a0 === 1 : a1) {
completeAppLauncherOnboarding(ContentDismissActionType.TAKE_ACTION);
}
}, []);
useEffect(() => {
callback(sharedValue.get(), c18623_11);
}, [showOnboarding, sharedValue, callback]);
const O = () => sharedValue.get();
O.__closure = {
bottomSheetIndex: sharedValue
};
O.__workletHash = 15587451723262;
O.__initData = __initData;
const _ = function _(a0, a1) {
if (a0 !== a1) {
_ReanimatedRexport.runOnJS(callback)(a0, c18623_11);
}
};
_.__closure = {
runOnJS: _ReanimatedRexport.runOnJS,
handleOnboardingParamChange: callback,
showOnboarding
};
_.__workletHash = 14003176039781;
_.__initData = __initData2;
useAnimatedReaction(O, _);
useLayoutEffect(() => {
if (transitionState === TransitionStates.YEETED) {
completeAppLauncherOnboarding(ContentDismissActionType.USER_DISMISS);
}
}, [transitionState]);
const callback3 = useCallback((a0) => <>
{[<BottomSheetBackdrop {...a0} pressBehavior="collapse" />, c18623_11 && <AppLauncherOnboardingLayer context={context} visibleContent={visibleContent} bottomOffset={isAndroid() ? 0 : minimum} />]}
</>, [visibleContent, context, minimum, showOnboarding]);
const callback4 = useCallback((a0, a1, a2) => {
if (a0 !== 1 && a1 === 1) {
trackWithMetadata(AnalyticEvents.APP_LAUNCHER_EXPANDED, {
reason: a2 === ANIMATION_SOURCE.KEYBOARD ? AppLauncherBottomSheetExpandReason.KEYBOARD : a2 === ANIMATION_SOURCE.GESTURE ? AppLauncherBottomSheetExpandReason.GESTURE : a2 !== ANIMATION_SOURCE.USER ? AppLauncherBottomSheetExpandReason.OTHER : ref3.current
});
ref3.current = void 0;
}
}, [ref3]);
const callback5 = useCallback(() => {
if (!ref5.current) {
trackWithMetadata(AnalyticEvents.APP_LAUNCHER_CLOSED, {
time_spent: Date.now() - ref4.current,
reason: ref2.current
});
}
ref5.current = true;
completeAppLauncherOnboarding(ContentDismissActionType.USER_DISMISS);
if (onClose != null) {
onClose();
}
if (isMetaQuest()) {
const current = chatInputRef.current;
if (current != null) {
current.closeCustomKeyboard();
}
}
if (isScreenReaderEnabled) {
setKeyboardType({
type: KeyboardTypes.SYSTEM
});
if (ref?.current != null) {
setAccessibilityFocus({
ref
});
ref = null;
}
}
}, [chatInputRef, isScreenReaderEnabled, ref2, onClose]);
if (!isScreenReaderEnabled) {
forceMaxHeight = isMetaQuest();
}
const props2 = {
ref: ref6,
animationConfigs: KEYBOARD_ANIMATION_CONFIG,
animatedIndex: sharedValue,
animatedPosition: sharedValue2,
chatInputRef,
forceMaxHeight,
enablePanDownToClose: isMetaQuest(),
onAnimate: callback4,
onClose: callback5,
transitionState,
backdropComponent: callback3,
disableHeaderRoundingAnimation: showOnboarding ? showOnboarding : entrypoint === AppLauncherEntrypoint.VOICE,
roundingViewStyle: showOnboarding ? styles.onboardingRoundingView : showOnboarding,
headerStyle: showOnboarding ? styles.onboardingHeader : showOnboarding,
isAppsKeyboard: true,
rendersHandle: entrypoint !== AppLauncherEntrypoint.VOICE,
width: defaultAppLauncherWidth,
children: null
};
if (showOnboarding) {
showOnboarding = styles.onboardingNavigatorContent;
}
props2.children = <View style={{
position: "relative",
height: maximum
}}>
<AppLauncherNavigator bottomSheetExpandReasonRef={ref3} bottomSheetIndex={sharedValue} bottomSheetPosition={sharedValue2} context={context} chatInputRef={chatInputRef} contentStyle={showOnboarding} entrypoint={entrypoint} expandBottomSheet={callback2} keyboardCloseReasonRef={ref2} width={defaultAppLauncherWidth} />
</View>;
return <PortalKeyboardBottomSheet {...props2} />;
});
export default r77;
export function setAppLauncherA11yFocusReturnRef(a0) {
ref = a0;
}