UNPKG

@fruits-chain/react-native-xiaoshu

Version:
91 lines (88 loc) 4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _reactNativeSafeAreaContext = require("react-native-safe-area-context"); var _style = require("../divider/style.js"); var _index = require("../helpers/index.js"); var _easing = _interopRequireDefault(require("../helpers/easing.js")); var _index2 = _interopRequireDefault(require("../theme/index.js")); var _style2 = require("./style.js"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } const BottomBar = ({ theme, safeAreaInsetBottom = true, backgroundColor, height, hidden = false, keyboardShowNotRender = true, divider = true, style, ...restProps }) => { const { bottom } = (0, _reactNativeSafeAreaContext.useSafeAreaInsets)(); const [CV] = _index2.default.useStyle({ varCreator: _style2.varCreator, theme }); const [CV_DIVIDER] = _index2.default.useStyle({ varCreator: _style.varCreator }); backgroundColor = (0, _index.getDefaultValue)(backgroundColor, CV.bottom_bar_background_color); height = (0, _index.getDefaultValue)(height, CV.bottom_bar_height); const realHeight = height + (safeAreaInsetBottom ? bottom : 0); const heightAnimated = (0, _react.useRef)(new _reactNative.Animated.Value(realHeight)); // 监听键盘 (0, _react.useEffect)(() => { // 安卓才隐藏底部 if (keyboardShowNotRender && _reactNative.Platform.OS === 'android') { // 注意如果你把 android:windowSoftInputMode 设置为 adjustResize 或是 adjustPan,则在 Android 上只有 keyboardDidShow 和 keyboardDidHide 事件有效。 const keyboardDidShow = _reactNative.Keyboard.addListener('keyboardDidShow', () => { _reactNative.Animated.timing(heightAnimated.current, { toValue: 0, duration: 300, useNativeDriver: false, easing: _easing.default.easeInQuint }).start(); }); const keyboardDidHide = _reactNative.Keyboard.addListener('keyboardDidHide', () => { _reactNative.Animated.timing(heightAnimated.current, { toValue: realHeight, duration: 100, useNativeDriver: false, delay: 200 }).start(); }); return () => { keyboardDidShow.remove(); keyboardDidHide.remove(); }; } }, [keyboardShowNotRender, realHeight]); const viewStyles = (0, _react.useMemo)(() => [{ height: heightAnimated.current, paddingBottom: safeAreaInsetBottom ? bottom : 0, backgroundColor, borderTopColor: CV_DIVIDER.divider_color_light, borderTopWidth: divider ? 1 : 0, overflow: 'hidden' }, style], [bottom, backgroundColor, divider, CV_DIVIDER.divider_color_light, safeAreaInsetBottom, style]); // 本身隐藏 if (hidden) { return null; } return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, { ...restProps, style: viewStyles }); }; var _default = exports.default = /*#__PURE__*/(0, _react.memo)(BottomBar); //# sourceMappingURL=bottom-bar.js.map