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

195 lines
8.6 KiB
TypeScript

// Metro module 10334 (f10335).
import { useMemo, useCallback, useEffect } from "react";
import { MIN_SWIPE_VELOCITY, STARTED_SWIPE_THRESHOLD, NOTIFICATION_MAX_WIDTH } from "./InAppNotificationConstants";
import { AnalyticEvents } from "../../../Constants";
import { createStyles } from "../../../design/components/Styles/native/createStyles";
import Module712 from "../../../_bundle/Module712";
import { extractMetadataFromNotification } from "./InAppNotificationUtils";
import { useInAppNotificationContext } from "./InAppNotificationContext";
import * as _ReanimatedRexport from "../../reanimated/ReanimatedRexport";
import ReanimatedRexport, { useSharedValue, useAnimatedStyle, cancelAnimation } from "../../reanimated/ReanimatedRexport";
import * as _spring from "../../../design/animation/reanimated/spring/spring";
import { useCanExpandInAppNotification } from "./InAppNotificationExpandExperiment";
import * as _timing from "../../../design/animation/reanimated/timing/timing";
import AppAnalyticsUtils from "../../app_analytics/AppAnalyticsUtils";
import { PressableHighlight } from "../../../design/void/Pressables/native/Pressables";
import NotificationContent from "./NotificationContent";
import NotificationProgress from "./NotificationProgress";
const useStyles = createStyles({
shadow: {
...Module712.shadows.SHADOW_HIGH,
backgroundColor: Module712.colors.MOBILE_ALERT_BACKGROUND_DEFAULT,
borderRadius: Module712.radii.lg,
maxWidth: NOTIFICATION_MAX_WIDTH,
width: "100%",
alignSelf: "center",
borderWidth: 1,
borderColor: Module712.colors.BORDER_SUBTLE
},
container: {
borderRadius: Module712.radii.lg,
overflow: "hidden"
}
});
const ON_PRESS_SPRING_CONFIG = {
mass: 1,
overshootClamping: true,
damping: 27,
stiffness: 300
};
const __initData = {
code: "function NotificationTsx1(){const{withSpring,scale,ON_PRESS_SPRING_CONFIG}=this.__closure;return{transform:[{scale:withSpring(scale.get(),ON_PRESS_SPRING_CONFIG)}]};}"
};
const __initData2 = {
code: "function NotificationTsx2(finished){const{runOnJS,handleDismissNotification}=this.__closure;if(finished){runOnJS(handleDismissNotification)('timeout');}}"
};
const __initData3 = {
code: "function NotificationTsx3(){const{withTiming,expandedSV,tokens,Easing}=this.__closure;return{borderRadius:withTiming(expandedSV.get()?tokens.radii.xl:tokens.radii.lg,{duration:220,easing:Easing.bezier(0.16,1,0.3,1)})};}"
};
export function NotificationPressable(props) {
let guildId, channelId, messageId, type, notificationGestureY, velocityY, autoDismissing, isExpanded, expandedSV, setExpanded, handleDismissNotification, initialized, panning, isExpandableNotification, sharedValue, sharedValue2, c17881_19, callback, callback2;
const { notification, expandableContent, icon, children, accessoryLabelNode, rightAccessory, header, showDragHandle = false, onAccessibilityExpand, bodyStyle, expandedContentVisible = false, onPress, onSettingsPress, ...props2 } = props;
guildId = void 0;
channelId = void 0;
messageId = void 0;
type = void 0;
notificationGestureY = void 0;
velocityY = void 0;
autoDismissing = void 0;
isExpanded = void 0;
expandedSV = void 0;
setExpanded = void 0;
handleDismissNotification = void 0;
initialized = void 0;
panning = void 0;
isExpandableNotification = void 0;
sharedValue = void 0;
sharedValue2 = void 0;
c17881_19 = void 0;
callback = void 0;
callback2 = void 0;
const styles = useStyles();
const memo = useMemo(() => ({
type: notification.type,
...extractMetadataFromNotification(notification)
}), [notification]);
guildId = memo.guildId;
channelId = memo.channelId;
messageId = memo.messageId;
type = memo.type;
const inAppNotificationContext = useInAppNotificationContext();
notificationGestureY = inAppNotificationContext.notificationGestureY;
velocityY = inAppNotificationContext.velocityY;
autoDismissing = inAppNotificationContext.autoDismissing;
isExpanded = inAppNotificationContext.isExpanded;
expandedSV = inAppNotificationContext.expandedSV;
setExpanded = inAppNotificationContext.setExpanded;
handleDismissNotification = inAppNotificationContext.handleDismissNotification;
initialized = inAppNotificationContext.initialized;
panning = inAppNotificationContext.panning;
isExpandableNotification = inAppNotificationContext.isExpandableNotification;
sharedValue = useSharedValue(1);
const callback3 = useCallback(() => sharedValue.set(0.95), [sharedValue]);
const callback4 = useCallback(() => sharedValue.set(1), [sharedValue]);
const R = function R() {
return {
transform: [{
scale: _spring.withSpring(sharedValue.get(), ON_PRESS_SPRING_CONFIG)
}]
};
};
R.__closure = {
withSpring: _spring.withSpring,
scale: sharedValue,
ON_PRESS_SPRING_CONFIG
};
R.__workletHash = 5485274967370;
R.__initData = __initData;
let r74 = useAnimatedStyle(R);
const canExpand = useCanExpandInAppNotification("NotificationPressable").canExpand;
const memo2 = useMemo(() => ({
foreground: true
}), []);
sharedValue2 = useSharedValue(100);
const r2 = notification.duration !== Infinity;
c17881_19 = r2;
useEffect(() => {
const duration = notification.duration;
if (initialized && !panning && c17881_19 && !isExpanded && !autoDismissing) {
const r31 = {
duration: sharedValue2.get() / 100 * duration,
easing: _ReanimatedRexport.Easing.linear
};
const r32 = function(a0) {
if (a0) {
_ReanimatedRexport.runOnJS(handleDismissNotification)("timeout");
}
};
r32.__closure = {
runOnJS: _ReanimatedRexport.runOnJS,
handleDismissNotification
};
r32.__workletHash = 5704836747866;
r32.__initData = __initData2;
sharedValue2.set(_timing.withTiming(0, r31, "animate-always", r32));
return () => {
cancelAnimation(sharedValue2);
};
}
}, [initialized, panning, notification, sharedValue2, handleDismissNotification, isExpanded, autoDismissing, r2]);
callback = useCallback(() => Math.abs(velocityY.get()) >= MIN_SWIPE_VELOCITY || Math.abs(notificationGestureY.get()) >= STARTED_SWIPE_THRESHOLD, [velocityY, notificationGestureY]);
callback2 = useCallback((a0, a1) => {
const r4 = callback();
if ((r4 ? isExpanded : !r4) || autoDismissing) {
AppAnalyticsUtils.trackWithMetadata(a0, {
type,
notif_guild_id: guildId,
notif_channel_id: channelId,
message_id: messageId,
in_app_notification_id: notification.inAppNotificationId,
percent: c17881_19 ? Math.floor(typeof sharedValue2 !== "number" ? sharedValue2.get() : sharedValue2) : void 0
});
if (a1 != null) {
a1();
}
}
}, [callback, autoDismissing, type, notification.inAppNotificationId, guildId, channelId, messageId, sharedValue2, isExpanded, r2]);
const callback5 = useCallback(() => callback2(AnalyticEvents.IN_APP_NOTIFICATION_CLICKED, onPress), [callback2, onPress]);
const callback6 = useCallback(() => {
if (isExpandableNotification) {
setExpanded(true, "long_press");
} else {
callback2(AnalyticEvents.IN_APP_NOTIFICATION_LONG_PRESSED, onSettingsPress);
}
}, [callback2, isExpandableNotification, onSettingsPress, setExpanded]);
const ai = function ai() {
return {
borderRadius: _timing.withTiming(expandedSV.get() ? Module712.radii.xl : Module712.radii.lg, {
duration: 220,
easing: _ReanimatedRexport.Easing.bezier(0.16, 1, 0.3, 1)
})
};
};
ai.__closure = {
withTiming: _timing.withTiming,
expandedSV,
tokens: Module712,
Easing: _ReanimatedRexport.Easing
};
ai.__workletHash = 15276203537259;
ai.__initData = __initData3;
const animatedStyle = useAnimatedStyle(ai);
const style = [styles.shadow, ,];
if (isExpandableNotification) {
r74 = animatedStyle;
}
style[1] = r74;
return <ReanimatedRexport.View style={style}>
<PressableHighlight {...props2} onAccessibilityEscape={() => handleDismissNotification("accessibility_escape")} style={styles.container} androidRippleConfig={memo2} onPress={callback5} onPressIn={callback3} onPressOut={callback4} onLongPress={callback6} accessibilityRole="button">
<NotificationContent icon={icon} accessoryLabelNode={accessoryLabelNode} rightAccessory={rightAccessory} header={header} showDragHandle={showDragHandle} onAccessibilityExpand={onAccessibilityExpand} bodyStyle={bodyStyle} expandedContentVisible={expandedContentVisible}>{children}</NotificationContent>
{r2 ? <NotificationProgress canExpand={canExpand} percent={sharedValue2} type={type} /> : null}
{expandableContent}
</PressableHighlight>
</ReanimatedRexport.View>;
}