A drawer component for React.
Improve keyboard detection and logic (#83)
Emil Kowalski561a523e76ed
diff --git a/src/helpers.ts b/src/helpers.tsindex 179c912..17fe73d 100644--- a/src/helpers.ts+++ b/src/helpers.ts@@ -13,7 +13,7 @@ export function isInView(el: HTMLElement): boolean {rect.top >= 0 &&rect.left >= 0 &&// Need + 40 for safari detection- rect.bottom <= window.visualViewport.height + 40 &&+ rect.bottom <= window.visualViewport.height - 40 &&rect.right <= window.visualViewport.width);}diff --git a/src/index.tsx b/src/index.tsxindex bea023a..792ea2c 100644--- a/src/index.tsx+++ b/src/index.tsx@@ -175,7 +175,7 @@ function Root({return false;}- if (isDraggingDown && element !== document.body && !swipeAmount) {+ if (isDraggingDown && element !== document.body && !swipeAmount && swipeAmount !== 0) {lastTimeDragPrevented.current = new Date();// Element is scrolled to the top, but we are dragging down so we should allow scrolling@@ -282,7 +282,7 @@ function Root({if (!drawerRef.current) return;const focusedElement = document.activeElement as HTMLElement;- if ((!isInView(focusedElement) && isInput(focusedElement)) || keyboardIsOpen.current) {+ if (isInput(focusedElement) || keyboardIsOpen.current) {const visualViewportHeight = window.visualViewport?.height || 0;// This is the height of the keyboardlet diffFromInitial = window.innerHeight - visualViewportHeight;