From f726572df72828c146fad16bd6873993612ad45e Mon Sep 17 00:00:00 2001 From: yandadaFreedom Date: Wed, 5 Nov 2025 16:46:39 +0800 Subject: [PATCH 01/14] =?UTF-8?q?feat:=20=E8=B7=A8=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20max-lines=20=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/template-compiler/compiler.js | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/packages/webpack-plugin/lib/template-compiler/compiler.js b/packages/webpack-plugin/lib/template-compiler/compiler.js index a77da16905..7fbd9b0db4 100644 --- a/packages/webpack-plugin/lib/template-compiler/compiler.js +++ b/packages/webpack-plugin/lib/template-compiler/compiler.js @@ -2933,6 +2933,95 @@ function processMpxTagName (el) { } } +// 处理 max-lines 跨平台属性 +function processMaxLines (el) { + const maxLinesAttr = getAndRemoveAttr(el, 'max-lines') + if (!maxLinesAttr.val) return + + const parsed = parseMustacheWithContext(maxLinesAttr.val) + + if (isReact(mode)) { + // iOS/Android 环境:转换为 numberOfLines + addAttrs(el, [{ name: 'numberOfLines', value: maxLinesAttr.val }]) + } else if (isWeb(mode)) { + // Web 环境 + + // 构建多行截断样式对象 + const linesStyleObj = `{ + display: (${parsed.result}) <= 1 ? 'inline-block' : '-webkit-box', + maxWidth: '100%', + overflow: 'hidden', + textOverflow: (${parsed.result}) <= 1 ? 'ellipsis' : '', + WebkitBoxOrient: 'vertical', + WebkitLineClamp: ${parsed.result} +}` + + // 查找已有的 style 或 wx:style + const existingStyles = [] + el.attrsList.forEach(attr => { + if (attr.name === 'style' || attr.name === 'wx:style') { + const styleParsed = parseMustacheWithContext(attr.value) + existingStyles.push(styleParsed.result) + } + }) + + if (existingStyles.length > 0) { + // 有现有样式,删除原有的 style/wx:style,添加合并后的 :style + getAndRemoveAttr(el, 'style') + getAndRemoveAttr(el, 'wx:style') + existingStyles.push(linesStyleObj) + addAttrs(el, [{ + name: ':style', + value: `[${existingStyles.join(', ')}] | transRpxStyle` + }]) + } else { + // 没有现有样式,直接添加 :style + addAttrs(el, [{ + name: ':style', + value: `[${linesStyleObj}] | transRpxStyle` + }]) + } + } else { + // 小程序环境:保留 max-lines,添加 wx:style + addAttrs(el, [{ name: 'max-lines', value: maxLinesAttr.val }, { name: 'overflow', value: 'ellipsis' }]) + + const linesStyleObj = `{ + display: (${parsed.result}) <= 1 ? 'inline-block' : '-webkit-box', + maxWidth: '100%', + overflow: 'hidden', + textOverflow: (${parsed.result}) <= 1 ? 'ellipsis' : '', + WebkitBoxOrient: 'vertical', + WebkitLineClamp: ${parsed.result} +}` + + // 循环获取所有的 style 或 wx:style + const styleExpressions = [] + + // 获取所有 wx:style + let wxStyleAttr + while ((wxStyleAttr = getAndRemoveAttr(el, 'wx:style')).val) { + const parsed = parseMustacheWithContext(wxStyleAttr.val) + styleExpressions.push(parsed.result) + } + + if (styleExpressions.length > 0) { + // 有现有样式,使用数组形式合并 + // wx:style="{{[style1, style2, linesStyle]}}" + const styleArray = [...styleExpressions, linesStyleObj].join(', ') + addAttrs(el, [{ + name: 'wx:style', + value: `{{[${styleArray}]}}` + }]) + } else { + // 没有现有样式,直接添加 + addAttrs(el, [{ + name: 'wx:style', + value: `{{${linesStyleObj}}}` + }]) + } + } +} + function processElement (el, root, options, meta) { processAtMode(el) // 如果已经标记了这个元素要被清除,直接return跳过后续处理步骤 @@ -2942,6 +3031,9 @@ function processElement (el, root, options, meta) { processMpxTagName(el) + // 处理 max-lines 跨平台属性(在平台规则处理之前) + processMaxLines(el) + if (runtimeCompile && options.dynamicTemplateRuleRunner) { options.dynamicTemplateRuleRunner(el, options, config[mode]) } From 4c087bf6621b53e53cd34baf451fd4a108d8de3d Mon Sep 17 00:00:00 2001 From: yandadaFreedom Date: Wed, 5 Nov 2025 17:10:50 +0800 Subject: [PATCH 02/14] =?UTF-8?q?feat:=20text=E7=BB=84=E4=BB=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81text-align-vertical?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/react/mpx-inline-text.tsx | 21 ++++++++++++---- .../components/react/mpx-simple-text.tsx | 24 +++++++++++++++---- .../lib/runtime/components/react/mpx-text.tsx | 9 +++++-- .../lib/runtime/components/react/utils.tsx | 2 +- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-inline-text.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-inline-text.tsx index 2f7fc48ad3..3ef29c2807 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-inline-text.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-inline-text.tsx @@ -1,13 +1,26 @@ -import { Text, TextProps } from 'react-native' -import { JSX, createElement } from 'react' +import { Text, TextProps, TextStyle } from 'react-native' +import { JSX, createElement, ReactNode } from 'react' import { extendObject } from './utils' -const InlineText = (props: TextProps): JSX.Element => { +interface _TextProps extends TextProps { + style?: TextStyle + children?: ReactNode + 'text-align-vertical'?: boolean +} + +const InlineText = (props: _TextProps): JSX.Element => { const { - allowFontScaling = false + allowFontScaling = false, + 'text-align-vertical': textAlignVertical } = props + const extendStyle = textAlignVertical ? { includeFontPadding: false, textAlignVertical: 'center' } : null + + if (extendStyle) { + props.style = extendObject({}, props.style, extendStyle) + } + return createElement(Text, extendObject({}, props, { allowFontScaling })) diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-simple-text.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-simple-text.tsx index bdebcccedf..917f68a27e 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-simple-text.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-simple-text.tsx @@ -1,14 +1,27 @@ -import { Text, TextProps } from 'react-native' -import { JSX, createElement } from 'react' +import { Text, TextProps, TextStyle } from 'react-native' +import { JSX, createElement, ReactNode } from 'react' import useInnerProps from './getInnerListeners' import { extendObject } from './utils' -const SimpleText = (props: TextProps): JSX.Element => { +interface _TextProps extends TextProps { + style?: TextStyle + children?: ReactNode + 'text-align-vertical'?: boolean +} + +const SimpleText = (props: _TextProps): JSX.Element => { const { allowFontScaling = false, - children + children, + 'text-align-vertical': textAlignVertical } = props + const extendStyle = textAlignVertical ? { includeFontPadding: false, textAlignVertical: 'center' } : null + + if (extendStyle) { + props.style = extendObject({}, props.style, extendStyle) + } + const innerProps = useInnerProps( extendObject( {}, @@ -16,7 +29,8 @@ const SimpleText = (props: TextProps): JSX.Element => { { allowFontScaling } - ) + ), + ['text-align-vertical'] ) return createElement(Text, innerProps, children) diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx index 9d771aea7b..baff8ff8f4 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx @@ -47,6 +47,7 @@ interface _TextProps extends TextProps { 'parent-font-size'?: number 'parent-width'?: number 'parent-height'?: number + 'text-align-vertical'?: boolean decode?: boolean } @@ -57,6 +58,7 @@ const _Text = forwardRef, _TextProps>((props, ref): selectable, 'enable-var': enableVar, 'external-var-context': externalVarContext, + 'text-align-vertical': textAlignVertical, 'user-select': userSelect, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, @@ -64,12 +66,14 @@ const _Text = forwardRef, _TextProps>((props, ref): decode } = props + const extendStyle = textAlignVertical ? { includeFontPadding: false, textAlignVertical: 'center' } : null + const { normalStyle, hasVarDec, varContextRef, hasPositionFixed - } = useTransformStyle(style, { + } = useTransformStyle(extendStyle ? extendObject({}, style, extendStyle) : style, { enableVar, externalVarContext, parentFontSize, @@ -95,7 +99,8 @@ const _Text = forwardRef, _TextProps>((props, ref): ), [ 'user-select', - 'decode' + 'decode', + 'text-align-vertical' ] ) diff --git a/packages/webpack-plugin/lib/runtime/components/react/utils.tsx b/packages/webpack-plugin/lib/runtime/components/react/utils.tsx index a24f5058b3..c5a533ef2f 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/utils.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/utils.tsx @@ -14,7 +14,7 @@ export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/ export const URL_REGEX = /^\s*url\(["']?(.*?)["']?\)\s*$/ export const SVG_REGEXP = /https?:\/\/.*\.(?:svg)/i export const BACKGROUND_REGEX = /^background(Image|Size|Repeat|Position)$/ -export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines|allowFontScaling/ +export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines|allowFontScaling|text-align-vertical/ export const DEFAULT_FONT_SIZE = 16 export const HIDDEN_STYLE = { opacity: 0 From c35f6a35339e0b4e393a5bb38e07484062e368e6 Mon Sep 17 00:00:00 2001 From: yandadaFreedom Date: Wed, 5 Nov 2025 17:27:29 +0800 Subject: [PATCH 03/14] =?UTF-8?q?feat:=20text=E7=BB=84=E4=BB=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8A=A0=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/react/mpx-inline-text.tsx | 20 +++++++++++--- .../components/react/mpx-simple-text.tsx | 26 +++++++++++++------ .../lib/runtime/components/react/mpx-text.tsx | 20 +++++++++++--- .../lib/runtime/components/react/utils.tsx | 2 +- .../lib/template-compiler/compiler.js | 2 +- 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-inline-text.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-inline-text.tsx index 3ef29c2807..39d962602c 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-inline-text.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-inline-text.tsx @@ -7,22 +7,34 @@ interface _TextProps extends TextProps { style?: TextStyle children?: ReactNode 'text-align-vertical'?: boolean + 'enable-add-space'?: boolean + 'space-font-size'?: number } const InlineText = (props: _TextProps): JSX.Element => { const { allowFontScaling = false, - 'text-align-vertical': textAlignVertical + 'text-align-vertical': textAlignVertical, + 'enable-add-space': enableAddSpace, + 'space-font-size': spaceFontSize } = props const extendStyle = textAlignVertical ? { includeFontPadding: false, textAlignVertical: 'center' } : null - if (extendStyle) { - props.style = extendObject({}, props.style, extendStyle) + let children = props.children + + // 如果启用了 enable-add-space,在末尾追加一个空格节点 + if (enableAddSpace) { + const spaceNode = createElement(Text, { + style: spaceFontSize ? { fontSize: spaceFontSize } : undefined + }, ' ') + children = createElement(Text, null, children, spaceNode) } return createElement(Text, extendObject({}, props, { - allowFontScaling + allowFontScaling, + children, + style: extendStyle ? extendObject({}, props.style, extendStyle) : props.style })) } diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-simple-text.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-simple-text.tsx index 917f68a27e..cbd58d552c 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-simple-text.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-simple-text.tsx @@ -7,32 +7,42 @@ interface _TextProps extends TextProps { style?: TextStyle children?: ReactNode 'text-align-vertical'?: boolean + 'enable-add-space'?: boolean + 'space-font-size'?: number } const SimpleText = (props: _TextProps): JSX.Element => { const { allowFontScaling = false, - children, - 'text-align-vertical': textAlignVertical + 'text-align-vertical': textAlignVertical, + 'enable-add-space': enableAddSpace, + 'space-font-size': spaceFontSize } = props const extendStyle = textAlignVertical ? { includeFontPadding: false, textAlignVertical: 'center' } : null - if (extendStyle) { - props.style = extendObject({}, props.style, extendStyle) - } - const innerProps = useInnerProps( extendObject( {}, props, { - allowFontScaling + allowFontScaling, + style: extendStyle ? extendObject({}, props.style, extendStyle) : props.style } ), - ['text-align-vertical'] + ['text-align-vertical', 'enable-add-space', 'space-font-size'] ) + let children = props.children + + // 如果启用了 enable-add-space,在末尾追加一个空格节点 + if (enableAddSpace) { + const spaceNode = createElement(Text, { + style: spaceFontSize ? { fontSize: spaceFontSize } : undefined + }, ' ') + children = createElement(Text, null, children, spaceNode) + } + return createElement(Text, innerProps, children) } diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx index baff8ff8f4..f9acec8b92 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx @@ -49,6 +49,8 @@ interface _TextProps extends TextProps { 'parent-height'?: number 'text-align-vertical'?: boolean decode?: boolean + 'enable-add-space'?: boolean + 'space-font-size'?: number } const _Text = forwardRef, _TextProps>((props, ref): JSX.Element => { @@ -63,7 +65,9 @@ const _Text = forwardRef, _TextProps>((props, ref): 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, - decode + decode, + 'enable-add-space': enableAddSpace, + 'space-font-size': spaceFontSize } = props const extendStyle = textAlignVertical ? { includeFontPadding: false, textAlignVertical: 'center' } : null @@ -100,11 +104,21 @@ const _Text = forwardRef, _TextProps>((props, ref): [ 'user-select', 'decode', - 'text-align-vertical' + 'text-align-vertical', + 'enable-add-space', + 'space-font-size' ] ) - const children = decode ? getDecodedChildren(props.children) : props.children + let children = decode ? getDecodedChildren(props.children) : props.children + + // 如果启用了 enable-add-space,在末尾追加一个空格节点,规避小米手机文字被截断问题 + if (enableAddSpace) { + const spaceNode = createElement(Text, { + style: spaceFontSize ? { fontSize: spaceFontSize } : undefined + }, ' ') + children = createElement(Text, null, children, spaceNode) + } let finalComponent:JSX.Element = createElement(Text, innerProps, wrapChildren( extendObject({}, props, { diff --git a/packages/webpack-plugin/lib/runtime/components/react/utils.tsx b/packages/webpack-plugin/lib/runtime/components/react/utils.tsx index c5a533ef2f..23679efeb4 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/utils.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/utils.tsx @@ -14,7 +14,7 @@ export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/ export const URL_REGEX = /^\s*url\(["']?(.*?)["']?\)\s*$/ export const SVG_REGEXP = /https?:\/\/.*\.(?:svg)/i export const BACKGROUND_REGEX = /^background(Image|Size|Repeat|Position)$/ -export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines|allowFontScaling|text-align-vertical/ +export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines|allowFontScaling|text-align-vertical|enable-add-space|space-font-size/ export const DEFAULT_FONT_SIZE = 16 export const HIDDEN_STYLE = { opacity: 0 diff --git a/packages/webpack-plugin/lib/template-compiler/compiler.js b/packages/webpack-plugin/lib/template-compiler/compiler.js index 7fbd9b0db4..dd14f01dd1 100644 --- a/packages/webpack-plugin/lib/template-compiler/compiler.js +++ b/packages/webpack-plugin/lib/template-compiler/compiler.js @@ -2304,7 +2304,7 @@ function processText (el, options, meta) { } // RN中裸文字需被Text包裹 -// 为了批量修改Text默认属性,如allowFontScaling,使用mpx-simple-text进行包裹 +// 为了批量修改Text默认属性,如allowFontScaling,使用mpx-inline-text进行包裹 function processWrapTextReact (el, options, meta) { const parent = el.parent const parentTag = parent.tag From b5a4b839c6e9d458c29b9e6298aa78abff04351d Mon Sep 17 00:00:00 2001 From: yandadaFreedom Date: Fri, 14 Nov 2025 15:31:45 +0800 Subject: [PATCH 04/14] =?UTF-8?q?feat:=20text=E6=94=AF=E6=8C=81=E5=B0=BE?= =?UTF-8?q?=E9=83=A8=E8=BF=BD=E5=8A=A0=E7=A9=BA=E6=A0=BC=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/react/mpx-inline-text.tsx | 18 +++++++------ .../components/react/mpx-simple-text.tsx | 10 +++---- .../lib/runtime/components/react/mpx-text.tsx | 12 ++++----- .../lib/template-compiler/compiler.js | 27 +++++-------------- 4 files changed, 28 insertions(+), 39 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-inline-text.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-inline-text.tsx index 39d962602c..24a6664a9a 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-inline-text.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-inline-text.tsx @@ -1,12 +1,12 @@ import { Text, TextProps, TextStyle } from 'react-native' import { JSX, createElement, ReactNode } from 'react' -import { extendObject } from './utils' +import { extendObject, omit } from './utils' interface _TextProps extends TextProps { style?: TextStyle children?: ReactNode - 'text-align-vertical'?: boolean + 'enable-android-align-center'?: boolean 'enable-add-space'?: boolean 'space-font-size'?: number } @@ -14,27 +14,29 @@ interface _TextProps extends TextProps { const InlineText = (props: _TextProps): JSX.Element => { const { allowFontScaling = false, - 'text-align-vertical': textAlignVertical, + 'enable-android-align-center': enableAndroidAlignCenter, 'enable-add-space': enableAddSpace, 'space-font-size': spaceFontSize } = props - const extendStyle = textAlignVertical ? { includeFontPadding: false, textAlignVertical: 'center' } : null + const extendStyle = enableAndroidAlignCenter ? { includeFontPadding: false, textAlignVertical: 'center' } : null - let children = props.children + const inlineTextProps = omit(props, ['enable-android-align-center', 'enable-add-space', 'space-font-size']) + + let children = inlineTextProps.children // 如果启用了 enable-add-space,在末尾追加一个空格节点 if (enableAddSpace) { const spaceNode = createElement(Text, { style: spaceFontSize ? { fontSize: spaceFontSize } : undefined }, ' ') - children = createElement(Text, null, children, spaceNode) + children = Array.isArray(children) ? children.concat(spaceNode) : [children, spaceNode] } - return createElement(Text, extendObject({}, props, { + return createElement(Text, extendObject({}, inlineTextProps, { allowFontScaling, children, - style: extendStyle ? extendObject({}, props.style, extendStyle) : props.style + style: extendStyle ? extendObject({}, inlineTextProps.style, extendStyle) : inlineTextProps.style })) } diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-simple-text.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-simple-text.tsx index cbd58d552c..a24ed5df8e 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-simple-text.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-simple-text.tsx @@ -6,7 +6,7 @@ import { extendObject } from './utils' interface _TextProps extends TextProps { style?: TextStyle children?: ReactNode - 'text-align-vertical'?: boolean + 'enable-android-align-center'?: boolean 'enable-add-space'?: boolean 'space-font-size'?: number } @@ -14,12 +14,12 @@ interface _TextProps extends TextProps { const SimpleText = (props: _TextProps): JSX.Element => { const { allowFontScaling = false, - 'text-align-vertical': textAlignVertical, + 'enable-android-align-center': enableAndroidAlignCenter, 'enable-add-space': enableAddSpace, 'space-font-size': spaceFontSize } = props - const extendStyle = textAlignVertical ? { includeFontPadding: false, textAlignVertical: 'center' } : null + const extendStyle = enableAndroidAlignCenter ? { includeFontPadding: false, textAlignVertical: 'center' } : null const innerProps = useInnerProps( extendObject( @@ -30,7 +30,7 @@ const SimpleText = (props: _TextProps): JSX.Element => { style: extendStyle ? extendObject({}, props.style, extendStyle) : props.style } ), - ['text-align-vertical', 'enable-add-space', 'space-font-size'] + ['enable-android-align-center', 'enable-add-space', 'space-font-size'] ) let children = props.children @@ -40,7 +40,7 @@ const SimpleText = (props: _TextProps): JSX.Element => { const spaceNode = createElement(Text, { style: spaceFontSize ? { fontSize: spaceFontSize } : undefined }, ' ') - children = createElement(Text, null, children, spaceNode) + children = Array.isArray(children) ? children.concat(spaceNode) : [children, spaceNode] } return createElement(Text, innerProps, children) diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx index f9acec8b92..de7484c4bf 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx @@ -41,14 +41,14 @@ interface _TextProps extends TextProps { style?: TextStyle children?: ReactNode selectable?: boolean + decode?: boolean 'user-select'?: boolean 'enable-var'?: boolean 'external-var-context'?: Record 'parent-font-size'?: number 'parent-width'?: number 'parent-height'?: number - 'text-align-vertical'?: boolean - decode?: boolean + 'enable-android-align-center'?: boolean 'enable-add-space'?: boolean 'space-font-size'?: number } @@ -60,7 +60,7 @@ const _Text = forwardRef, _TextProps>((props, ref): selectable, 'enable-var': enableVar, 'external-var-context': externalVarContext, - 'text-align-vertical': textAlignVertical, + 'enable-android-align-center': enableAndroidAlignCenter, 'user-select': userSelect, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, @@ -70,7 +70,7 @@ const _Text = forwardRef, _TextProps>((props, ref): 'space-font-size': spaceFontSize } = props - const extendStyle = textAlignVertical ? { includeFontPadding: false, textAlignVertical: 'center' } : null + const extendStyle = enableAndroidAlignCenter ? { includeFontPadding: false, textAlignVertical: 'center' } : null const { normalStyle, @@ -104,7 +104,7 @@ const _Text = forwardRef, _TextProps>((props, ref): [ 'user-select', 'decode', - 'text-align-vertical', + 'enable-android-align-center', 'enable-add-space', 'space-font-size' ] @@ -117,7 +117,7 @@ const _Text = forwardRef, _TextProps>((props, ref): const spaceNode = createElement(Text, { style: spaceFontSize ? { fontSize: spaceFontSize } : undefined }, ' ') - children = createElement(Text, null, children, spaceNode) + children = Array.isArray(children) ? children.concat(spaceNode) : [children, spaceNode] } let finalComponent:JSX.Element = createElement(Text, innerProps, wrapChildren( diff --git a/packages/webpack-plugin/lib/template-compiler/compiler.js b/packages/webpack-plugin/lib/template-compiler/compiler.js index dd14f01dd1..0f00ede25c 100644 --- a/packages/webpack-plugin/lib/template-compiler/compiler.js +++ b/packages/webpack-plugin/lib/template-compiler/compiler.js @@ -2940,22 +2940,21 @@ function processMaxLines (el) { const parsed = parseMustacheWithContext(maxLinesAttr.val) - if (isReact(mode)) { - // iOS/Android 环境:转换为 numberOfLines - addAttrs(el, [{ name: 'numberOfLines', value: maxLinesAttr.val }]) - } else if (isWeb(mode)) { - // Web 环境 - - // 构建多行截断样式对象 - const linesStyleObj = `{ + const linesStyleObj = `{ display: (${parsed.result}) <= 1 ? 'inline-block' : '-webkit-box', maxWidth: '100%', overflow: 'hidden', + whiteSpace: (${parsed.result}) <= 1 ? 'nowrap' : '', textOverflow: (${parsed.result}) <= 1 ? 'ellipsis' : '', WebkitBoxOrient: 'vertical', WebkitLineClamp: ${parsed.result} }` + if (isReact(mode)) { + // iOS/Android 环境:转换为 numberOfLines + addAttrs(el, [{ name: 'numberOfLines', value: maxLinesAttr.val }]) + } else if (isWeb(mode)) { + // Web 环境 // 查找已有的 style 或 wx:style const existingStyles = [] el.attrsList.forEach(attr => { @@ -2975,7 +2974,6 @@ function processMaxLines (el) { value: `[${existingStyles.join(', ')}] | transRpxStyle` }]) } else { - // 没有现有样式,直接添加 :style addAttrs(el, [{ name: ':style', value: `[${linesStyleObj}] | transRpxStyle` @@ -2985,16 +2983,6 @@ function processMaxLines (el) { // 小程序环境:保留 max-lines,添加 wx:style addAttrs(el, [{ name: 'max-lines', value: maxLinesAttr.val }, { name: 'overflow', value: 'ellipsis' }]) - const linesStyleObj = `{ - display: (${parsed.result}) <= 1 ? 'inline-block' : '-webkit-box', - maxWidth: '100%', - overflow: 'hidden', - textOverflow: (${parsed.result}) <= 1 ? 'ellipsis' : '', - WebkitBoxOrient: 'vertical', - WebkitLineClamp: ${parsed.result} -}` - - // 循环获取所有的 style 或 wx:style const styleExpressions = [] // 获取所有 wx:style @@ -3013,7 +3001,6 @@ function processMaxLines (el) { value: `{{[${styleArray}]}}` }]) } else { - // 没有现有样式,直接添加 addAttrs(el, [{ name: 'wx:style', value: `{{${linesStyleObj}}}` From f2163af0e3bddb44ea11dad8ce3fed399df74934 Mon Sep 17 00:00:00 2001 From: yandadaFreedom Date: Fri, 14 Nov 2025 15:42:57 +0800 Subject: [PATCH 05/14] =?UTF-8?q?feat:=E5=AE=89=E5=8D=93text=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=96=87=E6=9C=AC=E5=B1=85=E4=B8=AD=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webpack-plugin/lib/runtime/components/react/mpx-text.tsx | 2 +- packages/webpack-plugin/lib/runtime/components/react/utils.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx index de7484c4bf..e984fd727c 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx @@ -58,6 +58,7 @@ const _Text = forwardRef, _TextProps>((props, ref): style = {}, allowFontScaling = false, selectable, + decode, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'enable-android-align-center': enableAndroidAlignCenter, @@ -65,7 +66,6 @@ const _Text = forwardRef, _TextProps>((props, ref): 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, - decode, 'enable-add-space': enableAddSpace, 'space-font-size': spaceFontSize } = props diff --git a/packages/webpack-plugin/lib/runtime/components/react/utils.tsx b/packages/webpack-plugin/lib/runtime/components/react/utils.tsx index 23679efeb4..4ea2dc67af 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/utils.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/utils.tsx @@ -14,7 +14,7 @@ export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/ export const URL_REGEX = /^\s*url\(["']?(.*?)["']?\)\s*$/ export const SVG_REGEXP = /https?:\/\/.*\.(?:svg)/i export const BACKGROUND_REGEX = /^background(Image|Size|Repeat|Position)$/ -export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines|allowFontScaling|text-align-vertical|enable-add-space|space-font-size/ +export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines|allowFontScaling|enable-android-align-center|enable-add-space|space-font-size/ export const DEFAULT_FONT_SIZE = 16 export const HIDDEN_STYLE = { opacity: 0 From 5e061ea711a2954e35d40d2e2497963ae72aa450 Mon Sep 17 00:00:00 2001 From: yandadaFreedom Date: Fri, 14 Nov 2025 15:48:43 +0800 Subject: [PATCH 06/14] =?UTF-8?q?feat:=20text=E6=94=AF=E6=8C=81=E5=A4=9A?= =?UTF-8?q?=E8=A1=8C=E6=89=93=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/webpack-plugin/lib/template-compiler/compiler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webpack-plugin/lib/template-compiler/compiler.js b/packages/webpack-plugin/lib/template-compiler/compiler.js index 0f00ede25c..321d018430 100644 --- a/packages/webpack-plugin/lib/template-compiler/compiler.js +++ b/packages/webpack-plugin/lib/template-compiler/compiler.js @@ -2935,7 +2935,7 @@ function processMpxTagName (el) { // 处理 max-lines 跨平台属性 function processMaxLines (el) { - const maxLinesAttr = getAndRemoveAttr(el, 'max-lines') + const maxLinesAttr = getAndRemoveAttr(el, 'enable-max-lines') if (!maxLinesAttr.val) return const parsed = parseMustacheWithContext(maxLinesAttr.val) @@ -2980,7 +2980,7 @@ function processMaxLines (el) { }]) } } else { - // 小程序环境:保留 max-lines,添加 wx:style + // 小程序环境 addAttrs(el, [{ name: 'max-lines', value: maxLinesAttr.val }, { name: 'overflow', value: 'ellipsis' }]) const styleExpressions = [] From 60eb565c499fc89b9d8459530b8b59923225ea92 Mon Sep 17 00:00:00 2001 From: yandadaFreedom Date: Tue, 25 Nov 2025 20:26:51 +0800 Subject: [PATCH 07/14] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96text=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/react/mpx-inline-text.tsx | 41 ++-------- .../components/react/mpx-simple-text.tsx | 12 +-- .../lib/runtime/components/react/mpx-text.tsx | 10 +-- .../lib/runtime/components/react/utils.tsx | 11 ++- .../lib/template-compiler/compiler.js | 79 ++++--------------- 5 files changed, 36 insertions(+), 117 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-inline-text.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-inline-text.tsx index 24a6664a9a..2f7fc48ad3 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-inline-text.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-inline-text.tsx @@ -1,42 +1,15 @@ -import { Text, TextProps, TextStyle } from 'react-native' -import { JSX, createElement, ReactNode } from 'react' +import { Text, TextProps } from 'react-native' +import { JSX, createElement } from 'react' -import { extendObject, omit } from './utils' +import { extendObject } from './utils' -interface _TextProps extends TextProps { - style?: TextStyle - children?: ReactNode - 'enable-android-align-center'?: boolean - 'enable-add-space'?: boolean - 'space-font-size'?: number -} - -const InlineText = (props: _TextProps): JSX.Element => { +const InlineText = (props: TextProps): JSX.Element => { const { - allowFontScaling = false, - 'enable-android-align-center': enableAndroidAlignCenter, - 'enable-add-space': enableAddSpace, - 'space-font-size': spaceFontSize + allowFontScaling = false } = props - const extendStyle = enableAndroidAlignCenter ? { includeFontPadding: false, textAlignVertical: 'center' } : null - - const inlineTextProps = omit(props, ['enable-android-align-center', 'enable-add-space', 'space-font-size']) - - let children = inlineTextProps.children - - // 如果启用了 enable-add-space,在末尾追加一个空格节点 - if (enableAddSpace) { - const spaceNode = createElement(Text, { - style: spaceFontSize ? { fontSize: spaceFontSize } : undefined - }, ' ') - children = Array.isArray(children) ? children.concat(spaceNode) : [children, spaceNode] - } - - return createElement(Text, extendObject({}, inlineTextProps, { - allowFontScaling, - children, - style: extendStyle ? extendObject({}, inlineTextProps.style, extendStyle) : inlineTextProps.style + return createElement(Text, extendObject({}, props, { + allowFontScaling })) } diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-simple-text.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-simple-text.tsx index a24ed5df8e..6924efab91 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-simple-text.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-simple-text.tsx @@ -1,7 +1,7 @@ import { Text, TextProps, TextStyle } from 'react-native' import { JSX, createElement, ReactNode } from 'react' import useInnerProps from './getInnerListeners' -import { extendObject } from './utils' +import { extendObject, useAddSpace } from './utils' interface _TextProps extends TextProps { style?: TextStyle @@ -33,15 +33,7 @@ const SimpleText = (props: _TextProps): JSX.Element => { ['enable-android-align-center', 'enable-add-space', 'space-font-size'] ) - let children = props.children - - // 如果启用了 enable-add-space,在末尾追加一个空格节点 - if (enableAddSpace) { - const spaceNode = createElement(Text, { - style: spaceFontSize ? { fontSize: spaceFontSize } : undefined - }, ' ') - children = Array.isArray(children) ? children.concat(spaceNode) : [children, spaceNode] - } + const children = useAddSpace(props.children, { enableAddSpace, spaceFontSize }) return createElement(Text, innerProps, children) } diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx index e984fd727c..422e0587aa 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx @@ -9,7 +9,7 @@ import { useRef, forwardRef, ReactNode, JSX, createElement, Children } from 'rea import Portal from './mpx-portal' import useInnerProps from './getInnerListeners' import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数 -import { useTransformStyle, wrapChildren, extendObject } from './utils' +import { useTransformStyle, wrapChildren, extendObject, useAddSpace } from './utils' const decodeMap = { '<': '<', @@ -112,13 +112,7 @@ const _Text = forwardRef, _TextProps>((props, ref): let children = decode ? getDecodedChildren(props.children) : props.children - // 如果启用了 enable-add-space,在末尾追加一个空格节点,规避小米手机文字被截断问题 - if (enableAddSpace) { - const spaceNode = createElement(Text, { - style: spaceFontSize ? { fontSize: spaceFontSize } : undefined - }, ' ') - children = Array.isArray(children) ? children.concat(spaceNode) : [children, spaceNode] - } + children = useAddSpace(children, { enableAddSpace, spaceFontSize }) let finalComponent:JSX.Element = createElement(Text, innerProps, wrapChildren( extendObject({}, props, { diff --git a/packages/webpack-plugin/lib/runtime/components/react/utils.tsx b/packages/webpack-plugin/lib/runtime/components/react/utils.tsx index 4ea2dc67af..b6a990a0fc 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/utils.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/utils.tsx @@ -1,5 +1,5 @@ import { useEffect, useCallback, useMemo, useRef, ReactNode, ReactElement, isValidElement, useContext, useState, Dispatch, SetStateAction, Children, cloneElement, createElement, MutableRefObject } from 'react' -import { LayoutChangeEvent, TextStyle, ImageProps, Image } from 'react-native' +import { LayoutChangeEvent, TextStyle, ImageProps, Image, Text } from 'react-native' import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn } from '@mpxjs/utils' import { VarContext, ScrollViewContext, RouteContext } from './context' import { ExpressionParser, parseFunc, ReplaceSource } from './parser' @@ -14,7 +14,7 @@ export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/ export const URL_REGEX = /^\s*url\(["']?(.*?)["']?\)\s*$/ export const SVG_REGEXP = /https?:\/\/.*\.(?:svg)/i export const BACKGROUND_REGEX = /^background(Image|Size|Repeat|Position)$/ -export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines|allowFontScaling|enable-android-align-center|enable-add-space|space-font-size/ +export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines|allowFontScaling/ export const DEFAULT_FONT_SIZE = 16 export const HIDDEN_STYLE = { opacity: 0 @@ -828,3 +828,10 @@ export function useRunOnJSCallback (callbackMapRef: MutableRefObject { - if (attr.name === 'style' || attr.name === 'wx:style') { - const styleParsed = parseMustacheWithContext(attr.value) - existingStyles.push(styleParsed.result) - } - }) - - if (existingStyles.length > 0) { - // 有现有样式,删除原有的 style/wx:style,添加合并后的 :style - getAndRemoveAttr(el, 'style') - getAndRemoveAttr(el, 'wx:style') - existingStyles.push(linesStyleObj) - addAttrs(el, [{ - name: ':style', - value: `[${existingStyles.join(', ')}] | transRpxStyle` - }]) - } else { - addAttrs(el, [{ - name: ':style', - value: `[${linesStyleObj}] | transRpxStyle` - }]) - } } else { - // 小程序环境 - addAttrs(el, [{ name: 'max-lines', value: maxLinesAttr.val }, { name: 'overflow', value: 'ellipsis' }]) - - const styleExpressions = [] - - // 获取所有 wx:style - let wxStyleAttr - while ((wxStyleAttr = getAndRemoveAttr(el, 'wx:style')).val) { - const parsed = parseMustacheWithContext(wxStyleAttr.val) - styleExpressions.push(parsed.result) - } - - if (styleExpressions.length > 0) { - // 有现有样式,使用数组形式合并 - // wx:style="{{[style1, style2, linesStyle]}}" - const styleArray = [...styleExpressions, linesStyleObj].join(', ') - addAttrs(el, [{ - name: 'wx:style', - value: `{{[${styleArray}]}}` - }]) - } else { - addAttrs(el, [{ - name: 'wx:style', - value: `{{${linesStyleObj}}}` - }]) + if (isMiniProgram()) { + addAttrs(el, [{ name: 'max-lines', value: maxLinesAttr.val }, { name: 'overflow', value: 'ellipsis' }]) } + addAttrs(el, [{ + name: 'style', + value: `{{${mergedStyleStr}}}` + }]) } } @@ -3019,7 +2972,7 @@ function processElement (el, root, options, meta) { processMpxTagName(el) // 处理 max-lines 跨平台属性(在平台规则处理之前) - processMaxLines(el) + processTextMaxLines(el) if (runtimeCompile && options.dynamicTemplateRuleRunner) { options.dynamicTemplateRuleRunner(el, options, config[mode]) From c70c331cb4f8b5269568f6e274869fdb18d385a6 Mon Sep 17 00:00:00 2001 From: yandadaFreedom Date: Tue, 25 Nov 2025 20:28:56 +0800 Subject: [PATCH 08/14] =?UTF-8?q?chore:=20=E4=BF=AE=E6=94=B9text=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E8=BD=AC=E6=8D=A2=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/platform/template/wx/component-config/text.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/text.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/text.js index da39e2870e..90a750405a 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/text.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/text.js @@ -48,7 +48,7 @@ module.exports = function ({ print }) { qa: qaPropLog }, { - test: /^(space|decode)$/, + test: /^(space)$/, ios: iosPropLog, android: androidPropLog, harmony: harmonyPropLog From 0b2830c09a9727187537b5a09b913ec38a7fb076 Mon Sep 17 00:00:00 2001 From: yandadaFreedom Date: Tue, 25 Nov 2025 20:35:02 +0800 Subject: [PATCH 09/14] fix: lint error --- packages/webpack-plugin/lib/template-compiler/compiler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webpack-plugin/lib/template-compiler/compiler.js b/packages/webpack-plugin/lib/template-compiler/compiler.js index 71136ddf1d..b2576e8ea4 100644 --- a/packages/webpack-plugin/lib/template-compiler/compiler.js +++ b/packages/webpack-plugin/lib/template-compiler/compiler.js @@ -2941,7 +2941,7 @@ function processTextMaxLines (el) { const parsed = parseMustacheWithContext(maxLinesAttr.val) - const singleLineStyleStr = `"display:inline-block;max-width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;"` + const singleLineStyleStr = '"display:inline-block;max-width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;"' const multiLineStyleStr = `"display:-webkit-box;max-width:100%;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:" + (${parsed.result}) + ";"` const linesStyleStr = `((${parsed.result}) <= 1 ? ${singleLineStyleStr} : ${multiLineStyleStr})` const { val: styleAttrVal } = getAndRemoveAttr(el, 'style') From 2093f573647309e6bfb82000d9fe33cd6ee94fb9 Mon Sep 17 00:00:00 2001 From: yandadaFreedom Date: Thu, 27 Nov 2025 12:10:40 +0800 Subject: [PATCH 10/14] fix: useAddSpace key warning --- .../webpack-plugin/lib/runtime/components/react/utils.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/utils.tsx b/packages/webpack-plugin/lib/runtime/components/react/utils.tsx index b6a990a0fc..7a498f553b 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/utils.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/utils.tsx @@ -831,7 +831,11 @@ export function useRunOnJSCallback (callbackMapRef: MutableRefObject Date: Thu, 27 Nov 2025 14:07:46 +0800 Subject: [PATCH 11/14] fix: useAddSpace key warning --- .../webpack-plugin/lib/runtime/components/react/utils.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/utils.tsx b/packages/webpack-plugin/lib/runtime/components/react/utils.tsx index 7a498f553b..4d2d9d3186 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/utils.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/utils.tsx @@ -833,8 +833,8 @@ export function useAddSpace (children: ReactNode, { enableAddSpace, spaceFontSiz if (!enableAddSpace) return children const spaceNode = createElement(Text, spaceFontSize - ? { key: '__mpx_space__', style: { fontSize: spaceFontSize } } - : { key: '__mpx_space__' }, + ? { key: '__mpx_text_space__', style: { fontSize: spaceFontSize } } + : { key: '__mpx_text_space__' }, ' ' ) return Array.isArray(children) ? children.concat(spaceNode) : [children, spaceNode] From 5e43c8a0a74b5da4a52619970d2cfaf5bef78b66 Mon Sep 17 00:00:00 2001 From: yandadaFreedom Date: Thu, 27 Nov 2025 16:15:53 +0800 Subject: [PATCH 12/14] =?UTF-8?q?docs:=20=E8=A1=A5=E5=85=85text=E6=96=B0?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs-vitepress/guide/rn/component.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs-vitepress/guide/rn/component.md b/docs-vitepress/guide/rn/component.md index 5874aa38b4..c1460ad622 100644 --- a/docs-vitepress/guide/rn/component.md +++ b/docs-vitepress/guide/rn/component.md @@ -79,12 +79,17 @@ | ----------------------- | ------- | ------------- | ---------------------------------------------------------- | | user-select | boolean | `false` | 文本是否可选。 | | is-simple | - | - | RN环境特有标记,设置后将使用简单版本的 text 组件渲染,该组件不包含 css var、calc、ref 等拓展功能,但性能更优,请根据实际情况设置 | +| enable-max-lines | number | - | 跨平台属性,开启后 web/小程序/rn 环境均生效。用于限制文本最大行数, 文本溢出仅支持尾部打点模式| +| enable-android-align-center | boolean | `false` | RN环境特有属性,开启后 Text 组件样式将默认增加 includeFontPadding: false 与 textAlignVertical: 'center' 配置 | +| enable-add-space | boolean | `false` | RN环境特有属性,开启后将在文本尾部补一个空格字符,用于规避小米 HyperOS2 系统下 RN Text 组件出现“吞字”问题 | +| space-font-size | number | - | RN环境特有属性,用于设置空格大小,与 `enable-add-space` 配合使用 | > [!tip] 注意 > - 未包裹 text 标签的文本,会自动包裹 text 标签。 > - text 组件开启 enable-offset 后,offsetLeft、offsetWidth 获取时机仅为组件首次渲染阶段 +> - enable-add-space、enable-android-align-center、space-font-size 仅 text 组件支持,使用 view 组件直接包裹文本的场景不支持 ### scroll-view 可滚动视图区域。 From 7e5bcd54898eee17ac5b88e6e99789c06863e675 Mon Sep 17 00:00:00 2001 From: yandadaFreedom Date: Thu, 27 Nov 2025 16:19:51 +0800 Subject: [PATCH 13/14] fix: lint error --- .../webpack-plugin/lib/runtime/components/react/utils.tsx | 8 ++++---- packages/webpack-plugin/lib/template-compiler/compiler.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/utils.tsx b/packages/webpack-plugin/lib/runtime/components/react/utils.tsx index 4d2d9d3186..2939e9936d 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/utils.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/utils.tsx @@ -831,10 +831,10 @@ export function useRunOnJSCallback (callbackMapRef: MutableRefObject Date: Thu, 27 Nov 2025 16:23:34 +0800 Subject: [PATCH 14/14] chore: del comment --- packages/webpack-plugin/lib/template-compiler/compiler.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/webpack-plugin/lib/template-compiler/compiler.js b/packages/webpack-plugin/lib/template-compiler/compiler.js index 1203687a76..86ccc8de38 100644 --- a/packages/webpack-plugin/lib/template-compiler/compiler.js +++ b/packages/webpack-plugin/lib/template-compiler/compiler.js @@ -2933,7 +2933,6 @@ function processMpxTagName (el) { } } -// 处理 max-lines 跨平台属性 function processTextMaxLines (el) { if (el.tag !== 'text') return const maxLinesAttr = getAndRemoveAttr(el, 'enable-max-lines')