react-native-keyboard-controller
Version:
Keyboard manager which works in identical way on both iOS and Android
85 lines • 2.87 kB
JavaScript
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import React, { forwardRef, useEffect, useMemo, useRef } from "react";
import { StyleSheet, View } from "react-native";
import { KEYBOARD_BORDER_RADIUS, KEYBOARD_HAS_ROUNDED_CORNERS } from "../../constants";
import { KeyboardController } from "../../module";
import KeyboardStickyView from "../KeyboardStickyView";
const translucentStack = [];
let currentTranslucent = false;
const applyTranslucent = () => {
const next = translucentStack.length > 0 ? translucentStack[translucentStack.length - 1].translucent : false;
if (next !== currentTranslucent) {
currentTranslucent = next;
KeyboardController.setTranslucent(next);
}
};
const pushTranslucentEntry = entry => {
translucentStack.push(entry);
applyTranslucent();
};
const removeTranslucentEntry = entry => {
const index = translucentStack.indexOf(entry);
if (index !== -1) {
translucentStack.splice(index, 1);
}
applyTranslucent();
};
/**
* A component that renders content behind the keyboard. Since the keyboard
* is translucent, the content (colors, gradients, animations) will blend
* through and create visual effects on the keyboard.
*
* On iOS 26+ the keyboard has rounded corners, and the effect view
* automatically matches that shape.
*
* @returns A view component positioned behind the keyboard.
* @example
* ```tsx
* <KeyboardEffects>
* <View style={{ flex: 1, backgroundColor: "purple" }} />
* </KeyboardEffects>
* ```
*/
const KeyboardEffects = /*#__PURE__*/forwardRef(({
translucent,
rounded = true,
children,
...props
}, ref) => {
const stackEntry = useRef({
translucent: Boolean(translucent)
}).current;
const containerStyle = useMemo(() => [styles.container, KEYBOARD_HAS_ROUNDED_CORNERS && rounded && styles.rounded], [rounded]);
useEffect(() => {
pushTranslucentEntry(stackEntry);
return () => {
removeTranslucentEntry(stackEntry);
};
}, [stackEntry]);
useEffect(() => {
stackEntry.translucent = Boolean(translucent);
applyTranslucent();
}, [stackEntry, translucent]);
return /*#__PURE__*/React.createElement(KeyboardStickyView, _extends({
ref: ref
}, props), /*#__PURE__*/React.createElement(View, {
style: containerStyle
}, children));
});
const styles = StyleSheet.create({
container: {
position: "absolute",
bottom: 0,
top: 0,
left: 0,
right: 0,
height: 999
},
rounded: {
borderTopLeftRadius: KEYBOARD_BORDER_RADIUS,
borderTopRightRadius: KEYBOARD_BORDER_RADIUS,
overflow: "hidden"
}
});
export default KeyboardEffects;
//# sourceMappingURL=index.js.map