-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1289 from core-ds/feat/bottom-sheet-native-keyboard
feat(bottom-sheet): added virtual keyboard support
- Loading branch information
Showing
5 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@alfalab/core-components-bottom-sheet': minor | ||
--- | ||
|
||
Добавлен проп для случаев, когда необходима отзывчивость компонента из-за изменении видимой части браузера при открытии клавиатуры устройства |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { useVisibleViewportSize } from './use-visualviewport-size'; |
39 changes: 39 additions & 0 deletions
39
packages/bottom-sheet/src/hooks/use-visualviewport-size.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { fnUtils, isClient } from '@alfalab/core-components-shared'; | ||
|
||
type VisualViewportSize = Pick<VisualViewport, 'height' | 'offsetTop'>; | ||
|
||
const measureVisualViewport = ( | ||
visualViewport: VisualViewport | null, | ||
): VisualViewportSize | null => { | ||
if (!visualViewport) return null; | ||
const { height, offsetTop } = visualViewport; | ||
|
||
return { height, offsetTop }; | ||
}; | ||
|
||
export function useVisibleViewportSize(enabled = false): VisualViewportSize | null { | ||
const [size, setSize] = useState<Pick<VisualViewport, 'height' | 'offsetTop'> | null>(() => | ||
isClient() ? measureVisualViewport(window.visualViewport) : null, | ||
); | ||
|
||
useEffect(() => { | ||
const { visualViewport } = window; | ||
|
||
if (!isClient() || !enabled || !visualViewport) return fnUtils.noop; | ||
|
||
const listener = (event: Event) => | ||
setSize(measureVisualViewport(event.target as VisualViewport)); | ||
|
||
visualViewport.addEventListener('resize', listener); | ||
visualViewport.addEventListener('scroll', listener); | ||
|
||
return () => { | ||
visualViewport.removeEventListener('resize', listener); | ||
visualViewport.removeEventListener('scroll', listener); | ||
}; | ||
}, [enabled]); | ||
|
||
return size; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters