173 lines
6.7 KiB
TypeScript
173 lines
6.7 KiB
TypeScript
// Metro module 12321 (f12322).
|
|
import * as Module19 from "react";
|
|
import { useRef, useState, useEffect, useCallback, useMemo } from "react";
|
|
import { ScrollView } from "react-native";
|
|
import * as _PlatformUtils from "../../../../utils/PlatformUtils";
|
|
import { dismissKeyboard } from "../../../../utils/native/ChatInputUtils";
|
|
import getMediaViewerStateForScreen from "../getMediaViewerStateForScreen";
|
|
import { useEntranceAnimationState } from "../useEntranceAnimation";
|
|
import { flattenSource } from "../MediaSourceUtil";
|
|
import { MediaViewerSourcesStore, removeSpoiler } from "../useMediaViewerSources";
|
|
import useShouldHideMediaOptions from "../../../media_channel/useShouldHideMediaOptions";
|
|
import { Gesture, GestureDetector } from "../../../../_bundle/Module5273";
|
|
import MediaViewerItemPresenter from "./MediaViewerItemPresenter";
|
|
import ZoomLayout_android from "../../../zoom_layout/ZoomLayout.android";
|
|
const isAndroid = _PlatformUtils.isAndroid();
|
|
const r29 = Module19.memo(function({ entranceAnimationDriver, index, onLongPress, originLayout, panGestureConfig, panGesture, renderMedia, source, useItemVisible, zoomed, windowWidth, windowHeight }) {
|
|
let ref3, ref4, setState3, callback, callback2, obscure, field, memo, c19795_19, callback3, callback4, callback5, callback6, ref5;
|
|
ref3 = void 0;
|
|
ref4 = void 0;
|
|
setState3 = void 0;
|
|
callback = void 0;
|
|
callback2 = void 0;
|
|
obscure = void 0;
|
|
field = void 0;
|
|
memo = void 0;
|
|
c19795_19 = void 0;
|
|
callback3 = void 0;
|
|
callback4 = void 0;
|
|
callback5 = void 0;
|
|
callback6 = void 0;
|
|
ref5 = void 0;
|
|
const ref = useRef(windowWidth);
|
|
const ref2 = useRef(windowHeight);
|
|
const [windowWidth2, setState] = useState(windowWidth);
|
|
const [windowHeight2, setState2] = useState(windowHeight);
|
|
useEffect(() => dismissKeyboard(), []);
|
|
useEffect(() => {
|
|
let c27287_0 = setTimeout(() => {
|
|
setState(windowWidth);
|
|
setState2(windowHeight);
|
|
ref.current = windowWidth;
|
|
ref2.current = windowHeight;
|
|
}, 20);
|
|
return () => clearTimeout(c27287_0);
|
|
}, [windowWidth, windowHeight]);
|
|
const maximumZoomScale = getMediaViewerStateForScreen(windowWidth2, windowHeight2, source).maximumZoomScale;
|
|
ref3 = useRef(null);
|
|
ref4 = useRef(null);
|
|
let state;
|
|
[state, setState3] = useState(false);
|
|
callback = useCallback((a0, a1) => {
|
|
if (ref3.current != null) {
|
|
const current2 = ref.current;
|
|
const current3 = ref2.current;
|
|
const width = current2 / 2;
|
|
const height = current3 / 2;
|
|
ref3.current.getScrollResponder().scrollResponderZoomTo({
|
|
x: a0 - width / 2,
|
|
y: a1 - height / 2,
|
|
width,
|
|
height,
|
|
animated: true
|
|
});
|
|
} else if (ref4.current !== null) {
|
|
const current = ref4.current;
|
|
if (current != null) {
|
|
current.zoomTo({
|
|
x: a0,
|
|
y: a1
|
|
});
|
|
}
|
|
}
|
|
}, []);
|
|
callback2 = useCallback(function(animated = true) {
|
|
if (ref3.current != null) {
|
|
const current = ref.current;
|
|
const current2 = ref2.current;
|
|
ref3.current.getScrollResponder().scrollResponderZoomTo({
|
|
x: 0,
|
|
y: 0,
|
|
width: current,
|
|
height: current2,
|
|
animated
|
|
});
|
|
} else if (ref4.current !== null) {
|
|
ref4.current.unzoom({
|
|
animated
|
|
});
|
|
}
|
|
}, []);
|
|
const callback7 = useCallback((a0) => {
|
|
const r1 = a0.nativeEvent.zoomScale > 1;
|
|
zoomed.set(r1);
|
|
panGestureConfig.isInteracting.set(r1);
|
|
let r16 = isAndroid;
|
|
if (!isAndroid) {
|
|
r16 = !useEntranceAnimationState.getState().isComplete;
|
|
}
|
|
if (!r16) {
|
|
r16 = r1;
|
|
}
|
|
if (!r16) {
|
|
setState3(true);
|
|
setTimeout(() => {
|
|
setState3(false);
|
|
}, 500);
|
|
}
|
|
}, [zoomed, panGestureConfig]);
|
|
let r77 = flattenSource(source);
|
|
if (r77 == null) {
|
|
r77 = {};
|
|
}
|
|
obscure = r77.obscure;
|
|
const channelId = r77.channelId;
|
|
field = MediaViewerSourcesStore.useField("spoilerIndexes");
|
|
memo = useMemo(() => field.has(index), [index, field]);
|
|
const shouldHideMediaOptions = useShouldHideMediaOptions(channelId);
|
|
c19795_19 = shouldHideMediaOptions;
|
|
callback3 = useCallback(() => {
|
|
if (memo) {
|
|
removeSpoiler(index);
|
|
} else if (!c19795_19 && onLongPress != null) {
|
|
onLongPress();
|
|
}
|
|
}, [memo, index, onLongPress, shouldHideMediaOptions]);
|
|
callback4 = useCallback(() => {
|
|
if (!zoomed.get()) {
|
|
panGestureConfig.overlayEnabled.set(!panGestureConfig.overlayEnabled.get());
|
|
}
|
|
}, [zoomed, panGestureConfig]);
|
|
callback5 = useCallback(({ absoluteX, absoluteY }) => {
|
|
if (zoomed.get()) {
|
|
callback2();
|
|
} else if (!zoomed.get()) {
|
|
callback(absoluteX, absoluteY);
|
|
}
|
|
}, [callback2, callback, zoomed]);
|
|
callback6 = useCallback(() => {
|
|
removeSpoiler(index);
|
|
}, [index]);
|
|
const memo2 = useMemo(() => {
|
|
const r26 = Gesture.Tap().runOnJS(true).enabled(!memo).numberOfTaps(2);
|
|
const isAndroid2 = _PlatformUtils.isAndroid();
|
|
let r30 = 10;
|
|
const r15 = r26.maxDistance(isAndroid2 ? 20 : 10).onStart(callback5);
|
|
const r55 = Gesture.Tap().runOnJS(true).enabled(!memo).numberOfTaps(1).maxDistance(_PlatformUtils.isAndroid() ? 20 : 10).onStart(callback4);
|
|
const r67 = Gesture.Tap().runOnJS(true).enabled(memo ? !obscure : memo).numberOfTaps(1);
|
|
if (_PlatformUtils.isAndroid()) {
|
|
r30 = 20;
|
|
}
|
|
return Gesture.Simultaneous(Gesture.Exclusive(r67.maxDistance(r30).onStart(callback6), r15, r55), Gesture.LongPress().runOnJS(true).enabled(!memo).onStart(callback3), panGesture);
|
|
}, [callback5, callback3, callback6, memo, obscure, panGesture, callback4]);
|
|
ref5 = useRef(false);
|
|
useEffect(() => {
|
|
if (ref5.current) {
|
|
callback2(false);
|
|
} else {
|
|
ref5.current = true;
|
|
}
|
|
}, [callback2, windowWidth2, windowHeight2]);
|
|
const r125 = <GestureDetector gesture={memo2}>
|
|
<MediaViewerItemPresenter entranceAnimationDriver={entranceAnimationDriver} index={index} originLayout={originLayout} panGestureConfig={panGestureConfig} renderMedia={renderMedia} source={source} windowWidth={windowWidth2} windowHeight={windowHeight2} useItemVisible={useItemVisible} />
|
|
</GestureDetector>;
|
|
return isAndroid ? <ZoomLayout_android ref={ref4} style={{
|
|
width: windowWidth2,
|
|
height: windowHeight2
|
|
}} minimumZoomScale={1} maximumZoomScale={maximumZoomScale} onZoomChanged={callback7}>{r125}</ZoomLayout_android> : <ScrollView ref={ref3} style={{
|
|
width: windowWidth2,
|
|
height: windowHeight2
|
|
}} automaticallyAdjustContentInsets={false} showsHorizontalScrollIndicator={false} showsVerticalScrollIndicator={false} minimumZoomScale={1} maximumZoomScale={maximumZoomScale} centerContent scrollEventThrottle={16} onScroll={callback7} pointerEvents={state ? "none" : "auto"}>{r125}</ScrollView>;
|
|
});
|
|
export { r29 as MediaViewerItem };
|