import * as React from "react"; import {Platform, StyleProp, Text, TextStyle} from 'react-native'; import app, {ThemeCss} from "../../app"; import {IProps} from "./props"; import _hooks from "./_hooks"; const BasicText: React.FC = (props) => { const css = app.theme.useGet(); const { onPressTime, notPressTime, } = _hooks.useData(props); // 默认样式 const defaultStyle: StyleProp = {color: css.font.color, fontSize: 14, lineHeight: 20}; if (Platform.OS === 'android') defaultStyle.fontFamily = 'lucida grande, tahoma, verdana, arial, sans-serif'; // 操作样式 const styleCss: StyleProp = {}; if (props.color) styleCss.color = props.color; if (props.size) styleCss.fontSize = props.size; if (props.width) styleCss.width = props.width; if (props.height) styleCss.height = props.height; if (props.weight) styleCss.fontWeight = props.weight; if (props.lineHeight) styleCss.lineHeight = props.lineHeight; if (props.textAlign) styleCss.textAlign = props.textAlign; if (props.t) styleCss.marginTop = props.t; if (props.b) styleCss.marginBottom = props.b; if (props.l) styleCss.marginLeft = props.l; if (props.r) styleCss.marginRight = props.r; if (props.p) styleCss.padding = props.p; if (props.pv) styleCss.paddingVertical = props.pv; if (props.ph) styleCss.paddingHorizontal = props.ph; if (props.pt) styleCss.paddingTop = props.pt; if (props.pb) styleCss.paddingBottom = props.pb; if (props.pl) styleCss.paddingLeft = props.pl; if (props.pr) styleCss.paddingRight = props.pr; if (props.m) styleCss.margin = props.m; if (props.mv) styleCss.marginVertical = props.mv; if (props.mh) styleCss.marginHorizontal = props.mh; if (props.mt) styleCss.marginTop = props.mt; if (props.mb) styleCss.marginBottom = props.mb; if (props.ml) styleCss.marginLeft = props.ml; if (props.mr) styleCss.marginRight = props.mr; if (typeof props.onPress === "function" || typeof props.onLongPress === "function" || props.isSelectable) { return { const time = new Date().getTime(); if (onPressTime.current > time) return; onPressTime.current = (time + notPressTime); if (typeof props.onPress === "function") props.onPress(event); }} onLongPress={event => { if (typeof props.onLongPress === "function") props.onLongPress(event); }} > {props.children ?? props.text ?? ''} } return {props.children ?? props.text ?? ''} } export default BasicText