@fruits-chain/react-native-xiaoshu
Version:
🌈 React Native UI library
76 lines (66 loc) • 2.68 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 Color from 'color';
import isNil from 'lodash/isNil';
import React, { memo } from 'react';
import { TouchableWithoutFeedback, View } from 'react-native';
import { Svg } from 'react-native-svg';
import { getDefaultValue, pickTouchablePropsField, omitTouchablePropsField } from '../../helpers';
import Theme from '../../theme';
import { varCreator } from './style';
import * as helper from './';
const touchableOpacityStyle = {
alignSelf: 'center',
justifyContent: 'center',
alignItems: 'center' // backgroundColor: '#f30',
};
/**
* 生成一个 Outline 类型的 icon 组件
*/
export const genIcon = _ref => {
let {
render,
size = 'default'
} = _ref;
return /*#__PURE__*/memo(_ref2 => {
let {
size: iconSize,
color,
svgStyle,
// 点击相关的属性
style,
hitSlop,
...restProps
} = _ref2;
const TOKENS = Theme.useThemeTokens();
const CV = Theme.createVar(TOKENS, varCreator);
/** 适用于点击的属性 */
const touchableOpacityProps = pickTouchablePropsField(restProps);
/** 剔除点击相关的属性 */
const svgProps = omitTouchablePropsField(restProps);
/** viewBox 的尺寸 */
const viewBoxSize = size === 'default' ? helper.DEFAULT_SIZE : helper.SMALL_SIZE;
/** 向外延伸的点击范围 */
const hitSlopSize = size === 'default' ? helper.DEFAULT_HIT_SLOP : helper.SMALL_HIT_SLOP; // 修正数据
iconSize = getDefaultValue(iconSize, viewBoxSize);
color = getDefaultValue(color, CV.icon_color);
hitSlop = getDefaultValue(hitSlop, hitSlopSize); // 继续修正
if (restProps.disabled) {
color = Color(color).alpha(0.4).string();
}
return /*#__PURE__*/React.createElement(TouchableWithoutFeedback, _extends({}, touchableOpacityProps, {
hitSlop: hitSlop
}), /*#__PURE__*/React.createElement(View, {
style: style || touchableOpacityStyle,
pointerEvents: !isNil(touchableOpacityProps.onPress) ? svgProps.pointerEvents : 'none'
}, /*#__PURE__*/React.createElement(Svg, _extends({}, svgProps, {
style: svgStyle || touchableOpacityStyle,
height: iconSize,
width: iconSize,
viewBox: `0 0 ${viewBoxSize} ${viewBoxSize}`
}), render(color, {
token: TOKENS,
disabled: restProps.disabled
}))));
});
};
//# sourceMappingURL=gen.js.map