|
@@ -1,4 +1,4 @@
|
|
|
-import { FC, forwardRef, useImperativeHandle, useRef } from "react";
|
|
|
+import { FC, forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from "react";
|
|
|
import { useSelector } from "react-redux";
|
|
|
|
|
|
export interface KrpanoMiddlewareProps {
|
|
@@ -11,15 +11,18 @@ export interface KrpanoMiddlewareMethods {
|
|
|
|
|
|
export const KrpanoMiddleware = forwardRef<KrpanoMiddlewareMethods, KrpanoMiddlewareProps>(({ children }, ref) => {
|
|
|
const isHH = useSelector((state: any) => state.A0Layout.isHH)
|
|
|
+ const fakeEvent = useMemo(() => !isHH && /Mobi|Android|iPhone/i.test(navigator.userAgent), [isHH])
|
|
|
const startX = useRef(0);
|
|
|
const startY = useRef(0);
|
|
|
|
|
|
const handleTouchStart = (e: React.TouchEvent<HTMLDivElement>) => {
|
|
|
+ if (!fakeEvent) return
|
|
|
const touch = e.touches[0]
|
|
|
startX.current = touch.clientX
|
|
|
startY.current = touch.clientY
|
|
|
}
|
|
|
const handleTouchMove = (e: React.TouchEvent<HTMLDivElement>) => {
|
|
|
+ if (!fakeEvent) return
|
|
|
const touch = e.touches[0]
|
|
|
const deltaX = touch.clientX - startX.current
|
|
|
const deltaY = touch.clientY - startY.current
|
|
@@ -42,12 +45,18 @@ export const KrpanoMiddleware = forwardRef<KrpanoMiddlewareMethods, KrpanoMiddle
|
|
|
|
|
|
useImperativeHandle(ref, () => ({
|
|
|
ready: () => {
|
|
|
- if (!isHH && /Mobi|Android|iPhone/i.test(navigator.userAgent)) {
|
|
|
+ if (fakeEvent) {
|
|
|
window.ReactKrpanoActionProxy?.krpanoRenderer?.call("set(control.usercontrol, 'off');")
|
|
|
}
|
|
|
}
|
|
|
}))
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ if (window.ReactKrpanoActionProxy?.krpanoRenderer) {
|
|
|
+ window.ReactKrpanoActionProxy?.krpanoRenderer?.call(`set(control.usercontrol, '${fakeEvent ? 'off' : 'all'}');`)
|
|
|
+ }
|
|
|
+ }, [fakeEvent])
|
|
|
+
|
|
|
return (
|
|
|
<div style={{width: '100%', height: '100%'}}
|
|
|
onTouchStart={handleTouchStart}
|