react-modal-sheet 5.3.0 → 5.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +13 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/sheet.tsx +24 -8
package/src/sheet.tsx
CHANGED
|
@@ -290,17 +290,33 @@ export const Sheet = forwardRef<any, SheetProps>(
|
|
|
290
290
|
avoidKeyboard &&
|
|
291
291
|
keyboard.isKeyboardOpen
|
|
292
292
|
) {
|
|
293
|
+
const focusedElement = document.activeElement as HTMLElement | null;
|
|
293
294
|
const visibleSheetHeight = yInverted.get() - keyboard.keyboardHeight;
|
|
294
295
|
|
|
295
|
-
|
|
296
|
+
// If the keyboard is covering the sheet content, move the sheet up to reveal it
|
|
297
|
+
if (visibleSheetHeight <= 0 && focusedElement) {
|
|
296
298
|
const currentY = y.get();
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
299
|
+
const diffY = Math.max(currentY - Math.abs(visibleSheetHeight), 0);
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Get the position of the focused input relative to the sheet container
|
|
303
|
+
* and calculate how much we need to move the sheet up to ensure
|
|
304
|
+
* the focused input is visible above the keyboard.
|
|
305
|
+
*
|
|
306
|
+
* NOTE: RAF is needed to ensure the `top` values are correct.
|
|
307
|
+
*/
|
|
308
|
+
requestAnimationFrame(() => {
|
|
309
|
+
const inputRect = focusedElement.getBoundingClientRect();
|
|
310
|
+
const sheetRect = sheetRef.current?.getBoundingClientRect();
|
|
311
|
+
|
|
312
|
+
let inputOffset = 0;
|
|
313
|
+
|
|
314
|
+
if (sheetRect) {
|
|
315
|
+
inputOffset = inputRect.top - sheetRect.top + inputRect.height;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
animate(y, diffY - inputOffset, animationOptions);
|
|
319
|
+
});
|
|
304
320
|
|
|
305
321
|
// When keyboard closes animate back to the original snap point
|
|
306
322
|
return () => {
|