UNPKG

@fruits-chain/react-native-xiaoshu

Version:
51 lines (48 loc) 2.24 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 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 { useTheme, widthStyle } from '../theme'; import { isDef } from '../helpers'; import { createStyles } 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 THEME_VAR = useTheme(); const STYLES = widthStyle(THEME_VAR, createStyles); const messageJSX = isDef(message) ? /*#__PURE__*/isValidElement(message) ? message : /*#__PURE__*/React.createElement(Text, { style: [STYLES.text, { color: isDef(color) ? color : THEME_VAR.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: isDef(backgroundColor) ? backgroundColor : THEME_VAR[`notify_${type}_background_color`] || THEME_VAR.notify_primary_background_color, paddingTop: insets.top }, style] }, messageJSX))); }; export default /*#__PURE__*/memo(Notify); //# sourceMappingURL=notify.js.map