-
Notifications
You must be signed in to change notification settings - Fork 391
feat: text 拓展能力支持 #2324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: text 拓展能力支持 #2324
Changes from all commits
f726572
4c087bf
c35f6a3
b5a4b83
f2163af
5e061ea
970d8d5
60eb565
c70c331
0b2830c
2093f57
e13d452
5e43c8a
7e5bcd5
a6b71d9
ed595f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ const { isNonPhrasingTag } = require('../utils/dom-tag-config') | |
| const setBaseWxml = require('../runtime-render/base-wxml') | ||
| const { parseExp } = require('./parse-exps') | ||
| const shallowStringify = require('../utils/shallow-stringify') | ||
| const { isReact, isWeb, isNoMode } = require('../utils/env') | ||
| const { isReact, isWeb, isNoMode, isMiniProgram } = require('../utils/env') | ||
| const { capitalToHyphen } = require('../utils/string') | ||
|
|
||
| const no = function () { | ||
|
|
@@ -2303,7 +2303,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 | ||
|
|
@@ -2932,6 +2932,34 @@ function processMpxTagName (el) { | |
| } | ||
| } | ||
|
|
||
| function processTextMaxLines (el) { | ||
| if (el.tag !== 'text') return | ||
| const maxLinesAttr = getAndRemoveAttr(el, 'enable-max-lines') | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. processTextMaxLines,只处理Text节点 |
||
| if (!maxLinesAttr.val) return | ||
|
|
||
| const parsed = parseMustacheWithContext(maxLinesAttr.val) | ||
|
|
||
| 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') | ||
| const styleVal = styleAttrVal ? parseMustacheWithContext(styleAttrVal).result : '' | ||
| const mergedStyleStr = styleVal ? `${linesStyleStr} + ';' + (${styleVal})` : linesStyleStr | ||
|
|
||
| if (isReact(mode)) { | ||
| // iOS/Android 环境:转换为 numberOfLines | ||
| addAttrs(el, [{ name: 'numberOfLines', value: maxLinesAttr.val }]) | ||
| } else { | ||
| if (isMiniProgram()) { | ||
| addAttrs(el, [{ name: 'max-lines', value: maxLinesAttr.val }, { name: 'overflow', value: 'ellipsis' }]) | ||
| } | ||
| addAttrs(el, [{ | ||
| name: 'style', | ||
| value: `{{${mergedStyleStr}}}` | ||
| }]) | ||
| } | ||
| } | ||
|
|
||
| function processElement (el, root, options, meta) { | ||
| processAtMode(el) | ||
| // 如果已经标记了这个元素要被清除,直接return跳过后续处理步骤 | ||
|
|
@@ -2941,6 +2969,9 @@ function processElement (el, root, options, meta) { | |
|
|
||
| processMpxTagName(el) | ||
|
|
||
| // 处理 enable-max-lines 跨平台属性(在平台规则处理之前) | ||
| processTextMaxLines(el) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 放在平台规则处理之后,支持overflow属性,同时平台规则处理可以校验overfolow属性
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 继续放在平台转换之前,函数名统一改为preProcessXXX |
||
|
|
||
| if (runtimeCompile && options.dynamicTemplateRuleRunner) { | ||
| options.dynamicTemplateRuleRunner(el, options, config[mode]) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个不是个hook不应该叫use