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

101 lines
3.7 KiB
TypeScript

// Metro module 14955 (f14956).
import { memo, useCallback, useEffect, useState } from "react";
import { View } from "react-native";
import ReanimatedRexport, { Easing, useSharedValue, useAnimatedProps } from "../../reanimated/ReanimatedRexport";
import Module8531, { Circle } from "../../../_bundle/Module8531";
import { createStyles } from "../../../design/components/Styles/native/createStyles";
import Module712 from "../../../_bundle/Module712";
import { BADGE_PADDING } from "../../../design/void/native";
import * as _LurkerPreviewManager from "../LurkerPreviewManager";
import { useToken } from "../../../design/tokens/native/useToken";
import { withTiming } from "../../../design/animation/reanimated/timing/timing";
const PROGRESS_CIRCUMFERENCE = 2 * Math.PI * 6;
let c10581_8 = {
duration: 1000,
easing: Easing.linear
};
const AnimatedComponent = ReanimatedRexport.createAnimatedComponent(Circle);
const useStyles = createStyles({
outerRing: {
borderRadius: 20,
backgroundColor: Module712.colors.BACKGROUND_BASE_LOWEST,
position: "absolute",
bottom: -BADGE_PADDING,
right: -BADGE_PADDING,
padding: BADGE_PADDING,
height: 22,
width: 22,
alignItems: "center",
justifyContent: "center"
},
innerFill: {
borderRadius: 20,
backgroundColor: Module712.colors.BACKGROUND_MOD_STRONG,
height: 16,
width: 16,
alignItems: "center",
justifyContent: "center"
},
progressRing: {
position: "absolute",
transform: [{
rotate: "90deg"
}, {
scaleX: -1
}]
}
});
const __initData = {
code: "function LurkerPreviewCooldownBadgeTsx1(){const{PROGRESS_CIRCUMFERENCE,animatedProgress}=this.__closure;return{strokeDashoffset:PROGRESS_CIRCUMFERENCE*(1-animatedProgress.get())};}"
};
const r74 = memo(function LurkerPreviewCooldownBadge(props) {
let sharedValue;
const { expiresAt, totalDurationMs = _LurkerPreviewManager.LURKER_PREVIEW_PERSIST_MS } = props;
const LURKER_PREVIEW_PERSIST_MS = totalDurationMs;
const style = props.style;
sharedValue = void 0;
const styles = useStyles();
const token = useToken(Module712.colors.BACKGROUND_BRAND);
const callback = useCallback(() => {
const r9 = (expiresAt - Date.now()) / LURKER_PREVIEW_PERSIST_MS;
return 0.9 * (r9 < 0 ? 0 : r9 > 1 ? 1 : r9);
}, [expiresAt, LURKER_PREVIEW_PERSIST_MS]);
sharedValue = useSharedValue(callback());
useEffect(() => {
sharedValue.set(withTiming(callback(), c10581_8, "animate-always"));
let c27874_0 = setInterval(() => {
sharedValue.set(withTiming(callback(), c10581_8, "animate-always"));
}, 1000);
return () => {
clearInterval(c27874_0);
};
}, [sharedValue, callback]);
const r43 = () => ({
strokeDashoffset: PROGRESS_CIRCUMFERENCE * (1 - sharedValue.get())
});
r43.__closure = {
PROGRESS_CIRCUMFERENCE,
animatedProgress: sharedValue
};
r43.__workletHash = 7162520447613;
r43.__initData = __initData;
return <View style={[styles.outerRing, style]} pointerEvents="none" accessibilityElementsHidden importantForAccessibility="no-hide-descendants">
<View style={styles.innerFill}>
<Module8531 width={16} height={16} style={styles.progressRing}>
<AnimatedComponent cx={8} cy={8} r={6} fill="none" stroke={token} strokeWidth={4} strokeDasharray={PROGRESS_CIRCUMFERENCE} strokeLinecap="butt" animatedProps={useAnimatedProps(r43)} />
</Module8531>
</View>
</View>;
});
export default r74;
export function useHasExpired(a0) {
const [state, setState] = useState(null);
useEffect(() => {
if (a0 != null) {
let c27875_0 = setTimeout(() => setState(a0), Math.max(0, a0 - Date.now()));
return () => clearTimeout(c27875_0);
}
}, [a0]);
return a0 != null && state === a0;
}