From 1f14670c31efe6008c6627e2cb942b40bd022a74 Mon Sep 17 00:00:00 2001 From: Daniil Suvorov Date: Thu, 19 Oct 2023 15:11:42 +0300 Subject: [PATCH] fix: rm useAdaptivityHasHover --- .../vkui/src/components/Tappable/Tappable.tsx | 4 +-- .../src/hooks/useAdaptivityHasHover.test.tsx | 29 ------------------- .../vkui/src/hooks/useAdaptivityHasHover.ts | 26 ----------------- 3 files changed, 1 insertion(+), 58 deletions(-) delete mode 100644 packages/vkui/src/hooks/useAdaptivityHasHover.test.tsx delete mode 100644 packages/vkui/src/hooks/useAdaptivityHasHover.ts diff --git a/packages/vkui/src/components/Tappable/Tappable.tsx b/packages/vkui/src/components/Tappable/Tappable.tsx index cb2aa13e9c..634d590558 100644 --- a/packages/vkui/src/components/Tappable/Tappable.tsx +++ b/packages/vkui/src/components/Tappable/Tappable.tsx @@ -2,7 +2,6 @@ import * as React from 'react'; import { classNames, noop } from '@vkontakte/vkjs'; import mitt from 'mitt'; import { useAdaptivity } from '../../hooks/useAdaptivity'; -import { useAdaptivityHasHover } from '../../hooks/useAdaptivityHasHover'; import { useAdaptivityHasPointer } from '../../hooks/useAdaptivityHasPointer'; import { useBooleanState } from '../../hooks/useBooleanState'; import { useExternRef } from '../../hooks/useExternRef'; @@ -224,9 +223,8 @@ export const Tappable = ({ const insideTouchRoot = React.useContext(TouchRootContext); const platform = usePlatform(); const { focusVisible, onBlur, onFocus } = useFocusVisible(); - const { sizeX = 'none' } = useAdaptivity(); + const { sizeX = 'none', hasHover: hasHoverContext = true } = useAdaptivity(); const hasPointerContext = useAdaptivityHasPointer(); - const hasHoverContext = useAdaptivityHasHover(); const [clicks, setClicks] = React.useState([]); const [childHover, setChildHover] = React.useState(false); diff --git a/packages/vkui/src/hooks/useAdaptivityHasHover.test.tsx b/packages/vkui/src/hooks/useAdaptivityHasHover.test.tsx deleted file mode 100644 index 82ce3718c5..0000000000 --- a/packages/vkui/src/hooks/useAdaptivityHasHover.test.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import * as React from 'react'; -import { renderHook } from '@testing-library/react-hooks'; -import { AdaptivityProvider } from '../components/AdaptivityProvider/AdaptivityProvider'; -import { useAdaptivityHasHover } from './useAdaptivityHasHover'; - -describe(useAdaptivityHasHover, () => { - it('returns on client', () => { - const { result } = renderHook(useAdaptivityHasHover, {}); - expect(result.current).toEqual(true); - }); - - it('context hasHover={true}', () => { - const { result } = renderHook(useAdaptivityHasHover, { - wrapper: ({ children }) => ( - {children} - ), - }); - expect(result.current).toEqual(true); - }); - - it('context hasHover={false}', () => { - const { result } = renderHook(useAdaptivityHasHover, { - wrapper: ({ children }) => ( - {children} - ), - }); - expect(result.current).toEqual(false); - }); -}); diff --git a/packages/vkui/src/hooks/useAdaptivityHasHover.ts b/packages/vkui/src/hooks/useAdaptivityHasHover.ts deleted file mode 100644 index 38247c3821..0000000000 --- a/packages/vkui/src/hooks/useAdaptivityHasHover.ts +++ /dev/null @@ -1,26 +0,0 @@ -import * as React from 'react'; -import { hasHover as hasHoverLib } from '@vkontakte/vkjs'; -import { AdaptivityContext } from '../components/AdaptivityProvider/AdaptivityContext'; -import { useIsClient } from './useIsClient'; - -/** - * Определение происходит с помощью `window.matchMedia`. Для того, чтобы не было ошибок при гидратации, по умолчанию - * откладываем определение на второй рендер. - * - * [No SSR] Если передать `false`, то определение будет сразу. - */ -export function useAdaptivityHasHover(deferDetect?: true): undefined | boolean; -export function useAdaptivityHasHover(deferDetect?: false): boolean; -export function useAdaptivityHasHover(deferDetect = true): undefined | boolean { - const { hasHover: hasHoverContext } = React.useContext(AdaptivityContext); - const hasHover = hasHoverContext === undefined ? hasHoverLib : hasHoverContext; - - const needTwoPassRendering = deferDetect || hasHoverContext === undefined; - - const isClient = useIsClient(!needTwoPassRendering); - if (!isClient || hasHoverContext !== undefined) { - return hasHoverContext; - } - - return hasHover; -}