UNPKG

@fruits-chain/react-native-xiaoshu

Version:
52 lines (49 loc) 2.35 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import isNil from 'lodash/isNil'; import React, { isValidElement, memo } from 'react'; import { View, Text, TouchableWithoutFeedback } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import Popup from '../popup/popup'; import Theme from '../theme'; import { varCreator, styleCreator } from './style'; /** * Notify 消息提示 * @description 在页面顶部展示消息提示,支持函数调用和组件调用两种方式。 * @description 原计划 Notify 的 Props 继承 TouchableWithoutFeedbackProps,更贴近 React Native 提供的组件,这里需要把 Popup 中通用的属性提取出来,如果以后涉及到改动,有点麻烦,等大部分组件完整后看看怎么优化。 */ const Notify = _ref => { let { children, style, textStyle, type = 'primary', message, color, backgroundColor, onPress, ...restProps } = _ref; const insets = useSafeAreaInsets(); const TOKENS = Theme.useThemeTokens(); const CV = Theme.createVar(TOKENS, varCreator); const STYLES = Theme.createStyle(CV, styleCreator); const messageJSX = !isNil(message) ? /*#__PURE__*/isValidElement(message) ? message : /*#__PURE__*/React.createElement(Text, { style: [STYLES.text, { color: !isNil(color) ? color : CV.notify_text_color }, textStyle], numberOfLines: 1 }, message) : children; return /*#__PURE__*/React.createElement(Popup, _extends({}, restProps, { overlay: false, position: "top" }), /*#__PURE__*/React.createElement(TouchableWithoutFeedback, { onPress: onPress }, /*#__PURE__*/React.createElement(View, { style: [STYLES.notify, { backgroundColor: !isNil(backgroundColor) ? backgroundColor : CV[`notify_${type}_background_color`] || CV.notify_primary_background_color, paddingTop: insets.top > CV.notify_padding_vertical ? insets.top : CV.notify_padding_vertical }, style] }, messageJSX))); }; export default /*#__PURE__*/memo(Notify); //# sourceMappingURL=notify.js.map