diff --git a/packages/clientNative/globals.js b/packages/clientNative/globals.js index 69a8c941f57..fe05640cd1d 100644 --- a/packages/clientNative/globals.js +++ b/packages/clientNative/globals.js @@ -32,7 +32,6 @@ import {TextEncoder, TextDecoder} from 'text-encoding-shim'; import structuredClone from '@ungap/structured-clone'; import performance from 'react-native-performance'; import {URL} from 'whatwg-url-without-unicode'; -import {Dimensions} from 'react-native'; window.location = new URL('https://mariale.ir.world/location/marbar'); @@ -59,14 +58,8 @@ global.localStorage = { // Window polyfill const listenerRegistry = new Map(); -const resizeSubscriptions = new Map(); window.addEventListener = (type, handler) => { - // if (type === 'resize') { - // const subscription = Dimensions.addEventListener('change', handler); - // resizeSubscriptions.set(handler, subscription); - // return; - // } let registry = listenerRegistry.get(type); if (!registry) { @@ -76,13 +69,6 @@ window.addEventListener = (type, handler) => { registry.add(handler); }; window.removeEventListener = (type, handler) => { - // if (type === 'resize') { - // const subscription = resizeSubscriptions.get(handler); - // subscription?.remove(); - // resizeSubscriptions.delete(handler); - // return; - // } - const registry = listenerRegistry.get(type); if (registry) { registry.delete(handler); @@ -97,6 +83,9 @@ window.dispatchEvent = (eventType, evt) => { } }; +document.addEventListener = window.addEventListener; +document.removeEventListener = window.removeEventListener; + // Using PixelRatio.get() was causing issues with frame buffers. Let's default to 1. window.devicePixelRatio = 1; diff --git a/packages/spatial/src/input/functions/ClientInputHooks.tsx b/packages/spatial/src/input/functions/ClientInputHooks.tsx index 4c0b1f24259..042baf03add 100644 --- a/packages/spatial/src/input/functions/ClientInputHooks.tsx +++ b/packages/spatial/src/input/functions/ClientInputHooks.tsx @@ -6,8 +6,8 @@ Version 1.0. (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://github.com/ir-engine/ir-engine/blob/dev/LICENSE. The License is based on the Mozilla Public License Version 1.1, but Sections 14 -and 15 have been added to cover use of software over a computer network and -provide for limited attribution for the Original Developer. In addition, +and 15 have been added to cover use of software over a computer network and +provide for limited attribution for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B. Software distributed under the License is distributed on an "AS IS" basis, @@ -19,7 +19,7 @@ The Original Code is Infinite Reality Engine. The Original Developer is the Initial Developer. The Initial Developer of the Original Code is the Infinite Reality Engine team. -All portions of the code written by the Infinite Reality Engine team are Copyright © 2021-2023 +All portions of the code written by the Infinite Reality Engine team are Copyright © 2021-2023 Infinite Reality Engine. All Rights Reserved. */ @@ -63,9 +63,9 @@ export const useNonSpatialInputSources = () => { setComponent(eid, NameComponent, 'InputSource-nonspatial') const inputSourceComponent = getComponent(eid, InputSourceComponent) - // document.addEventListener('DOMMouseScroll', ClientInputFunctions.preventDefault, false) - // document.addEventListener('gesturestart', ClientInputFunctions.preventDefault) - // document.addEventListener('keydown', ClientInputFunctions.preventDefaultKeyDown, false) + document.addEventListener('DOMMouseScroll', ClientInputFunctions.preventDefault, false) + document.addEventListener('gesturestart', ClientInputFunctions.preventDefault) + document.addEventListener('keydown', ClientInputFunctions.preventDefaultKeyDown, false) const onKeyEvent = (event: KeyboardEvent) => { ClientInputFunctions.preventDefaultKeyDown(event) @@ -80,8 +80,8 @@ export const useNonSpatialInputSources = () => { if (down) buttonState[code] = createInitialButtonState(eid) else if (buttonState[code]) buttonState[code].up = true } - // document.addEventListener('keyup', onKeyEvent) - // document.addEventListener('keydown', onKeyEvent) + document.addEventListener('keyup', onKeyEvent) + document.addEventListener('keydown', onKeyEvent) const handleTouchDirectionalPad = (event: CustomEvent): void => { const { stick, value }: { stick: 'LeftStick' | 'RightStick'; value: { x: number; y: number } } = event.detail @@ -91,29 +91,29 @@ export const useNonSpatialInputSources = () => { axes[index + 0] = value.x axes[index + 1] = value.y } - window.addEventListener('touchstickmove', handleTouchDirectionalPad) + document.addEventListener('touchstickmove', handleTouchDirectionalPad) const handleTouchGamepadButtonDown = (event: CustomEvent) => { const buttonState = inputSourceComponent.buttons buttonState[event.detail.button] = createInitialButtonState(eid) } - window.addEventListener('touchgamepadbuttondown', handleTouchGamepadButtonDown) + document.addEventListener('touchgamepadbuttondown', handleTouchGamepadButtonDown) const handleTouchGamepadButtonUp = (event: CustomEvent) => { const buttonState = inputSourceComponent.buttons if (buttonState[event.detail.button]) buttonState[event.detail.button].up = true } - window.addEventListener('touchgamepadbuttonup', handleTouchGamepadButtonUp) + document.addEventListener('touchgamepadbuttonup', handleTouchGamepadButtonUp) return () => { - // document.removeEventListener('DOMMouseScroll', ClientInputFunctions.preventDefault, false) - // document.removeEventListener('gesturestart', ClientInputFunctions.preventDefault) - // document.removeEventListener('keyup', onKeyEvent) - // document.removeEventListener('keydown', onKeyEvent) - // document.removeEventListener('keydown', ClientInputFunctions.preventDefaultKeyDown, false) - window.removeEventListener('touchstickmove', handleTouchDirectionalPad) - window.removeEventListener('touchgamepadbuttondown', handleTouchGamepadButtonDown) - window.removeEventListener('touchgamepadbuttonup', handleTouchGamepadButtonUp) + document.removeEventListener('DOMMouseScroll', ClientInputFunctions.preventDefault, false) + document.removeEventListener('gesturestart', ClientInputFunctions.preventDefault) + document.removeEventListener('keyup', onKeyEvent) + document.removeEventListener('keydown', onKeyEvent) + document.removeEventListener('keydown', ClientInputFunctions.preventDefaultKeyDown, false) + document.removeEventListener('touchstickmove', handleTouchDirectionalPad) + document.removeEventListener('touchgamepadbuttondown', handleTouchGamepadButtonDown) + document.removeEventListener('touchgamepadbuttonup', handleTouchGamepadButtonUp) removeEntity(eid) } }, []) @@ -208,7 +208,6 @@ export const CanvasInputReactor = () => { const rendererComponent = useComponent(cameraEntity, RendererComponent) useEffect(() => { - console.log('Loaded Canvas Input Reactor') if (xrState.session.value) return // pointer input sources are automatically handled by webxr const canvas = rendererComponent.canvas.value