Files
discord-decomp/components_native/calls/CallPTTButton.tsx
T
2026-11-01 12:12:55 +02:00

165 lines
5.9 KiB
TypeScript

// Metro module 10411 (f10412).
import { memo, useState, useRef, useEffect } from "react";
import ChannelStore from "../../stores/ChannelStore";
import MediaEngineStore from "../../stores/MediaEngineStore";
import RTCConnectionStore from "../../stores/RTCConnectionStore";
import { InputModes } from "../../Constants";
import { createStyles } from "../../design/components/Styles/native/createStyles";
import Module712 from "../../_bundle/Module712";
import { hexWithOpacity } from "../../utils/ColorUtils";
import { useStateFromStores } from "../../_bundle/Module589";
import useCanSpeakInChannel from "../../modules/stage_channels/useCanSpeakInChannel";
import { useVoiceChatNavigationContext } from "../../modules/voice_chat/native/VoiceChatModalContext";
import { setPushToTalkState } from "../../modules/media_engine/MediaEngineActionCreators";
import { Gesture, GestureDetector } from "../../_bundle/Module5273";
import * as _ReanimatedRexport from "../../modules/reanimated/ReanimatedRexport";
import ReanimatedRexport from "../../modules/reanimated/ReanimatedRexport";
import { Button } from "../../design/void/native";
import { intl, t } from "../../intl/index.native";
let c6966_10 = {
BRAND: "brand",
BLUR: "blur"
};
const useStyles = createStyles({
button: {
margin: 13
},
container: {
borderRadius: Module712.radii.xs,
overflow: "hidden",
backgroundColor: hexWithOpacity(Module712.unsafe_rawColors.WHITE, 0.24)
},
buttonBlur: {
backgroundColor: "transparent"
},
buttonBlurPressed: {
backgroundColor: hexWithOpacity(Module712.unsafe_rawColors.BLACK, 0.6)
},
textStyle: {
fontSize: 16
},
brandButtonContainer: {
backgroundColor: Module712.colors.BACKGROUND_BASE_LOW
}
});
const __initData = {
code: "function CallPTTButtonTsx1(){const{runOnJS,setDragging}=this.__closure;runOnJS(setDragging)(false);}"
};
const __initData2 = {
code: "function CallPTTButtonTsx2(){const{runOnJS,setDragging,setPressed,setIsSwipeToChatDisabled}=this.__closure;runOnJS(setDragging)(true);runOnJS(setPressed)(false);if(setIsSwipeToChatDisabled!=null){runOnJS(setIsSwipeToChatDisabled)(false);}}"
};
const r73 = memo((a0) => {
let style2, style3;
let look = a0.look;
if (look === void 0) {
look = c6966_10.BRAND;
}
let stateFromStores, state, setState, state2, setState2, ref, setIsSwipeToChatDisabled;
const { style, sendCallback, stopCallback } = a0;
stateFromStores = void 0;
state = void 0;
setState = void 0;
state2 = void 0;
setState2 = void 0;
ref = void 0;
setIsSwipeToChatDisabled = void 0;
const styles = useStyles();
const stateFromStores2 = useStateFromStores([MediaEngineStore], () => MediaEngineStore.getMode());
stateFromStores = useStateFromStores([RTCConnectionStore], () => RTCConnectionStore.getChannelId());
const stateFromStores3 = useStateFromStores([ChannelStore], () => ChannelStore.getChannel(stateFromStores), [stateFromStores]);
const canSpeakInChannel = useCanSpeakInChannel(stateFromStores);
[state, setState] = useState(false);
[state2, setState2] = useState(false);
const r57 = (stateFromStores3 == null ? void 0 : stateFromStores3.isGuildStageVoice()) && !canSpeakInChannel;
ref = useRef(false);
setIsSwipeToChatDisabled = useVoiceChatNavigationContext()?.setIsSwipeToChatDisabled;
useEffect(() => {
let current = state;
if (!state) {
current = state2;
}
if (current !== ref.current) {
setPushToTalkState(current);
if (current) {
if (sendCallback != null) {
sendCallback();
}
} else if (stopCallback != null) {
stopCallback();
}
}
ref.current = current;
}, [ref, state, state2, sendCallback, stopCallback]);
const r73 = Gesture.Pan();
const F = function F() {
_ReanimatedRexport.runOnJS(setState2)(true);
_ReanimatedRexport.runOnJS(setState)(false);
if (setIsSwipeToChatDisabled != null) {
_ReanimatedRexport.runOnJS(setIsSwipeToChatDisabled)(false);
}
};
F.__closure = {
runOnJS: _ReanimatedRexport.runOnJS,
setDragging: setState2,
setPressed: setState,
setIsSwipeToChatDisabled
};
F.__workletHash = 10056118853836;
F.__initData = __initData2;
const r82 = r73.onStart(F);
const N = function N() {
_ReanimatedRexport.runOnJS(setState2)(false);
};
N.__closure = {
runOnJS: _ReanimatedRexport.runOnJS,
setDragging: setState2
};
N.__workletHash = 8439106360958;
N.__initData = __initData;
const gesture = r82.onEnd(N);
const r92 = stateFromStores == null;
let r93 = null;
if (!r92) {
const VOICE_ACTIVITY = InputModes.VOICE_ACTIVITY;
r93 = null;
if (VOICE_ACTIVITY !== stateFromStores2) {
r93 = null;
if (!r57) {
L18: {
if (look === c6966_10.BRAND) {
const r103 = [styles.brandButtonContainer];
style3 = [styles.button, style];
style2 = r103;
} else {
style2 = [styles.button, styles.container, style];
if (!state && !state2) {
style3 = styles.buttonBlur;
break L18;
}
style3 = styles.buttonBlurPressed;
}
}
r93 = <GestureDetector gesture={gesture}>
<ReanimatedRexport.View style={style2}>
<Button style={style3} textStyle={styles.textStyle} text={intl.string(t.Q8gkVL)} onTouchStart={function onTouchStart() {
setState(true);
setState2(false);
if (setIsSwipeToChatDisabled != null) {
setIsSwipeToChatDisabled(true);
}
}} onTouchEnd={function onTouchEnd() {
setState(false);
if (setIsSwipeToChatDisabled != null) {
setIsSwipeToChatDisabled(false);
}
}} darkenOnPress />
</ReanimatedRexport.View>
</GestureDetector>;
}
}
}
return r93;
});
export default r73;
export { c6966_10 as CallPTTButtonLooks };