UNPKG

@shayrn/react-native-keyboard-safearea-view

Version:

React Native component to handle keyboard + safe area insets without breaking layout. Works with Expo and bare projects.

75 lines (74 loc) 2.36 kB
"use strict"; import { Keyboard, StyleSheet, View } from 'react-native'; import { KeyboardAwareScrollView, KeyboardProvider } from 'react-native-keyboard-controller'; import React, { useEffect } from 'react'; import { SafeAreaView } from 'react-native-safe-area-context'; import { scale } from '@shayrn/react-native-scaler'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; export function KeyboardSafeAreaView({ header, children, disableEnhancedInputHandling = false, bottomOffset = 0, footer, resetPaddings = false, keyboardAwareScrollView = true, safeAreaStyle, keyboardAwareScrollViewStyle }) { useEffect(() => { if (disableEnhancedInputHandling) return; const keyboardDidShow = Keyboard.addListener('keyboardDidShow', () => { // Optional: Adjust layout if needed }); const keyboardDidHide = Keyboard.addListener('keyboardDidHide', () => { // Optional: Reset scroll position if needed }); return () => { keyboardDidShow.remove(); keyboardDidHide.remove(); }; }, [disableEnhancedInputHandling]); const content = keyboardAwareScrollView ? /*#__PURE__*/_jsx(KeyboardProvider, { children: /*#__PURE__*/_jsx(KeyboardAwareScrollView, { nestedScrollEnabled: true, contentContainerStyle: [styles.container, { paddingTop: resetPaddings ? 0 : scale(16) }, keyboardAwareScrollViewStyle], keyboardShouldPersistTaps: "handled" // Add these props to improve touch handling , bottomOffset: bottomOffset // Ensure touches are properly handled , scrollEventThrottle: 16, showsVerticalScrollIndicator: false // Important: Remove any potential interference with touch events , removeClippedSubviews: false, children: children }) }) : /*#__PURE__*/_jsx(View, { style: { flex: 1, paddingTop: resetPaddings ? 0 : scale(16) }, children: children }); return /*#__PURE__*/_jsxs(SafeAreaView, { style: [styles.safeArea, { paddingHorizontal: resetPaddings ? 0 : scale(12) }, safeAreaStyle], edges: ['top', 'left', 'right', 'bottom'], children: [header, content, footer] }); } const styles = StyleSheet.create({ safeArea: { flex: 1 }, container: { flexGrow: 1 } }); //# sourceMappingURL=KeyboardSafeAreaView.js.map