198 lines
8.4 KiB
TypeScript
198 lines
8.4 KiB
TypeScript
// Metro module 10657 (f10658).
|
|
import { useState, useLayoutEffect, memo, useCallback } from "react";
|
|
import { ActivityIndicator, View } from "react-native";
|
|
import EmbeddedActivitiesStore from "../EmbeddedActivitiesStore";
|
|
import { ActivityLayoutMode, ActivityScreenOrientation } from "../Constants";
|
|
import { OBEY_SILENT_HARDWARE_SWITCH_APP_IDS } from "../../applications/ApplicationConstants";
|
|
import { createStyles } from "../../../design/components/Styles/native/createStyles";
|
|
import * as _getDefaultOrientationLockState from "./getDefaultOrientationLockState";
|
|
import { getDefaultOrientationLockState } from "./getDefaultOrientationLockState";
|
|
import useWindowDimensions_native from "../../screen/useWindowDimensions.native";
|
|
import Dispatcher from "../../../Dispatcher";
|
|
import doesOrientationMatchLockState from "./doesOrientationMatchLockState";
|
|
import WakeLock from "../../device/native/WakeLock";
|
|
import useCurrentEmbeddedApplication from "../utils/useCurrentEmbeddedApplication";
|
|
import { useStateFromStores } from "../../../_bundle/Module589";
|
|
import useDispatchOpenActivity from "../useDispatchOpenActivity";
|
|
import EmbeddedActivitiesNativeManager, { EMBEDDED_ACTIVITY_WEB_VIEW_KEY } from "./EmbeddedActivitiesNativeManager";
|
|
import EmbeddedActivityWebView from "./EmbeddedActivityWebView";
|
|
import * as _allowPopups from "../utils/allowPopups";
|
|
let useStyles, ActivityViewLoadingIndicator, BaseActivityView;
|
|
const useBaseActivityView = function useBaseActivityView({ orientationLockState, showLoadingIndicator, setShowLoadingStateForLockingOrientation, application, setOrientationLockState }) {
|
|
const [state, setIsResetting2] = useState(false);
|
|
const defaultOrientationLockState = getDefaultOrientationLockState(application);
|
|
const id = application?.id;
|
|
const [state2, setState] = useState(false);
|
|
const windowDimensions_native = useWindowDimensions_native();
|
|
const isLandscape = windowDimensions_native.width > windowDimensions_native.height;
|
|
let c18165_9 = isLandscape;
|
|
useLayoutEffect(() => {
|
|
Dispatcher.dispatch({
|
|
type: "ACTIVITY_SCREEN_ORIENTATION_UPDATE",
|
|
screenOrientation: c18165_9 ? ActivityScreenOrientation.LANDSCAPE : ActivityScreenOrientation.PORTRAIT
|
|
});
|
|
}, [isLandscape]);
|
|
useLayoutEffect(() => {
|
|
setState(false);
|
|
}, [id]);
|
|
useLayoutEffect(() => {
|
|
if (!state2 && (orientationLockState == null && !doesOrientationMatchLockState(c18165_9, defaultOrientationLockState))) {
|
|
setShowLoadingStateForLockingOrientation(true);
|
|
} else {
|
|
setShowLoadingStateForLockingOrientation(false);
|
|
}
|
|
if (application != null) {
|
|
setOrientationLockState(application, orientationLockState);
|
|
}
|
|
}, [defaultOrientationLockState, application, orientationLockState, isLandscape, state2, setShowLoadingStateForLockingOrientation, setOrientationLockState]);
|
|
useLayoutEffect(() => {
|
|
if (doesOrientationMatchLockState(c18165_9, orientationLockState)) {
|
|
setShowLoadingStateForLockingOrientation(false);
|
|
}
|
|
}, [orientationLockState, isLandscape, setShowLoadingStateForLockingOrientation]);
|
|
useLayoutEffect(() => {
|
|
let r3 = showLoadingIndicator;
|
|
if (!showLoadingIndicator) {
|
|
r3 = state;
|
|
}
|
|
if (!r3) {
|
|
setState(true);
|
|
}
|
|
}, [showLoadingIndicator, state]);
|
|
return {
|
|
isResetting: state,
|
|
setIsResetting: setIsResetting2,
|
|
isLandscape
|
|
};
|
|
};
|
|
ActivityViewLoadingIndicator = function ActivityViewLoadingIndicator() {
|
|
return <View style={useStyles().loadingContainer}>
|
|
<ActivityIndicator size="large" />
|
|
</View>;
|
|
};
|
|
BaseActivityView = function BaseActivityView(props) {
|
|
const { children, wakeLockKey, showLoadingIndicator: showLoadingIndicator2, isResetting } = props;
|
|
return showLoadingIndicator2 ? <ActivityViewLoadingIndicator /> : isResetting ? null : <>
|
|
<WakeLock wakeLockKey={wakeLockKey} />
|
|
{children}
|
|
</>;
|
|
};
|
|
useStyles = createStyles({
|
|
loadingContainer: {
|
|
flex: 1,
|
|
justifyContent: "center"
|
|
}
|
|
});
|
|
const r46 = memo(function EmbeddedActivityViewInner(props) {
|
|
let queryParams;
|
|
let setIsResetting;
|
|
const { channel, layoutMode } = props;
|
|
let portraitSafeAreasConfig = props.portraitSafeAreasConfig;
|
|
const landscapeSafeAreasConfig = props.landscapeSafeAreasConfig;
|
|
setIsResetting = void 0;
|
|
const currentEmbeddedActivity = EmbeddedActivitiesStore.getCurrentEmbeddedActivity();
|
|
const currentEmbeddedApplication = useCurrentEmbeddedApplication();
|
|
let c18166_2 = currentEmbeddedApplication;
|
|
const stateFromStores = useStateFromStores([EmbeddedActivitiesStore], () => c18166_2 != null ? EmbeddedActivitiesStore.getOrientationLockStateForApp(c18166_2.id) : void 0, [currentEmbeddedApplication]);
|
|
const [state, setShowLoadingStateForLockingOrientation2] = useState(true);
|
|
if (currentEmbeddedActivity == null) {
|
|
queryParams = {
|
|
instance_id: ""
|
|
};
|
|
} else {
|
|
let compositeInstanceId = currentEmbeddedActivity.compositeInstanceId;
|
|
if (compositeInstanceId == null) {
|
|
compositeInstanceId = currentEmbeddedActivity.launchId;
|
|
}
|
|
const r41 = {
|
|
instance_id: compositeInstanceId,
|
|
location_id: currentEmbeddedActivity.location?.id,
|
|
launch_id: currentEmbeddedActivity.launchId
|
|
};
|
|
if (currentEmbeddedActivity.proxyTicket != null) {
|
|
r41.discord_proxy_ticket = currentEmbeddedActivity.proxyTicket;
|
|
}
|
|
if (channel != null && channel.id != null && channel.id !== "") {
|
|
r41.channel_id = channel.id;
|
|
}
|
|
const r53 = channel?.guild_id != null && channel?.guild_id !== "";
|
|
queryParams = r41;
|
|
if (r53) {
|
|
r41.guild_id = channel?.guild_id;
|
|
queryParams = r41;
|
|
}
|
|
}
|
|
useDispatchOpenActivity({
|
|
connectedEmbeddedActivity: currentEmbeddedActivity
|
|
});
|
|
useLayoutEffect(() => {
|
|
if (currentEmbeddedActivity != null) {
|
|
Dispatcher.dispatch({
|
|
type: "ACTIVITY_LAYOUT_MODE_UPDATE",
|
|
layoutMode,
|
|
applicationId: currentEmbeddedActivity.applicationId
|
|
});
|
|
}
|
|
}, [layoutMode, currentEmbeddedActivity]);
|
|
const callback = useCallback(() => {
|
|
EmbeddedActivitiesNativeManager.leaveActivity({
|
|
location: currentEmbeddedActivity?.location,
|
|
applicationId: c18166_2?.id
|
|
});
|
|
}, [currentEmbeddedApplication, currentEmbeddedActivity]);
|
|
const id = currentEmbeddedApplication?.id;
|
|
const showLoadingIndicator2 = currentEmbeddedActivity == null || currentEmbeddedActivity?.launchId == null || state || id == null || currentEmbeddedApplication == null;
|
|
const baseActivityView = useBaseActivityView({
|
|
orientationLockState: stateFromStores,
|
|
showLoadingIndicator: showLoadingIndicator2,
|
|
setShowLoadingStateForLockingOrientation: setShowLoadingStateForLockingOrientation2,
|
|
application: currentEmbeddedApplication,
|
|
setOrientationLockState: _getDefaultOrientationLockState.setOrientationLockState
|
|
});
|
|
const isResetting = baseActivityView.isResetting;
|
|
setIsResetting = baseActivityView.setIsResetting;
|
|
const isLandscape = baseActivityView.isLandscape;
|
|
const r82 = currentEmbeddedActivity == null;
|
|
let r83 = null;
|
|
if (!r82) {
|
|
const r84 = id == null;
|
|
r83 = null;
|
|
if (!r84) {
|
|
const props2 = {
|
|
onActivityCrash: () => {
|
|
setIsResetting(true);
|
|
setTimeout(() => setIsResetting(false), 0);
|
|
},
|
|
applicationId: id,
|
|
channelId: channel?.id,
|
|
guildId: channel?.guild_id,
|
|
activityUrl: currentEmbeddedActivity.url,
|
|
currentEmbeddedActivity,
|
|
activitySessionId: currentEmbeddedActivity?.compositeInstanceId,
|
|
queryParams,
|
|
onLoadError: callback,
|
|
allowPopups: _allowPopups.allowPopups(currentEmbeddedApplication),
|
|
referrerPolicy: "origin",
|
|
isPipOrGridMode: layoutMode === ActivityLayoutMode.PIP || layoutMode === ActivityLayoutMode.GRID,
|
|
webViewKey: EMBEDDED_ACTIVITY_WEB_VIEW_KEY,
|
|
safeAreasConfig: null,
|
|
ignoreSilentHardwareSwitch: null
|
|
};
|
|
if (isLandscape) {
|
|
portraitSafeAreasConfig = landscapeSafeAreasConfig;
|
|
}
|
|
props2.safeAreasConfig = portraitSafeAreasConfig;
|
|
props2.ignoreSilentHardwareSwitch = !OBEY_SILENT_HARDWARE_SWITCH_APP_IDS.has(id);
|
|
r83 = <BaseActivityView wakeLockKey="EmbeddedActivities" showLoadingIndicator={showLoadingIndicator2} isResetting={isResetting}>
|
|
<EmbeddedActivityWebView {...props2} />
|
|
</BaseActivityView>;
|
|
}
|
|
}
|
|
return r83;
|
|
});
|
|
export default r46;
|
|
export { useBaseActivityView };
|
|
export { ActivityViewLoadingIndicator };
|
|
export { BaseActivityView };
|
|
export { r46 as EmbeddedActivityView };
|