@fruits-chain/react-native-xiaoshu
Version:
React Native UI library
62 lines (56 loc) • 2.6 kB
JavaScript
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, { memo } from 'react';
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
import { useTheme, widthStyle } from '../theme';
import { getArrowFill } from '../icon/helper/arrow';
import { getDefaultValue } from '../helpers';
import { useDropdownConfig } from './context';
import { createStyles } from './style.text';
const DropdownText = _ref => {
let {
textStyle,
iconStyle,
disabled = false,
title,
active = false,
pressable = true,
activeColor,
direction,
// TouchableOpacity 属性
style,
activeOpacity,
...restProps
} = _ref;
const config = useDropdownConfig();
const THEME_VAR = useTheme();
const STYLES = widthStyle(THEME_VAR, createStyles); // 修正数据
activeColor = getDefaultValue(activeColor, config.activeColor);
activeOpacity = getDefaultValue(activeOpacity, THEME_VAR.active_opacity);
direction = getDefaultValue(direction, config.direction);
const textColor = disabled ? THEME_VAR.dropdown_menu_title_disabled_text_color : active ? activeColor : THEME_VAR.dropdown_menu_title_text_color;
const itemStyleSummary = StyleSheet.flatten([STYLES.item, config.titleStyle, style]);
const textStyleSummary = StyleSheet.flatten([STYLES.text, config.titleTextStyle, {
color: textColor
}, textStyle]);
const iconStyles = [config.iconStyle, iconStyle].filter(Boolean);
const ArrowFill = getArrowFill(active ? direction === 'up' ? 'down' : 'up' : direction);
const ctxJSX = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Text, {
style: textStyleSummary
}, title), /*#__PURE__*/React.createElement(ArrowFill, {
style: iconStyles.length ? StyleSheet.flatten(iconStyles) : undefined,
size: THEME_VAR.dropdown_menu_title_icon_size,
color: active ? activeColor : textColor
}));
if (pressable) {
return /*#__PURE__*/React.createElement(TouchableOpacity, _extends({}, restProps, {
disabled: disabled,
style: itemStyleSummary,
activeOpacity: activeOpacity
}), ctxJSX);
}
return /*#__PURE__*/React.createElement(View, _extends({}, restProps, {
style: itemStyleSummary
}), ctxJSX);
};
export default /*#__PURE__*/memo(DropdownText);
//# sourceMappingURL=text.js.map