Skip to content

Commit

Permalink
support text allowFontScaling default false && support dataset text i…
Browse files Browse the repository at this point in the history
…nherit
  • Loading branch information
hiyuki committed Dec 9, 2024
1 parent b55f687 commit d057992
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export interface InputProps {
}

export interface PrivateInputProps {
allowFontScaling?: boolean
multiline?: boolean
'auto-height'?: boolean
bindlinechange?: (evt: NativeSyntheticEvent<TextInputContentSizeChangeEventData> | unknown) => void
Expand All @@ -128,6 +129,7 @@ const keyboardTypeMap: Record<Type, string> = {
const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps>((props: FinalInputProps, ref): JSX.Element => {
const {
style = {},
allowFontScaling = false,
type = 'text',
value,
password,
Expand Down Expand Up @@ -185,9 +187,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
{ padding: 0, backgroundColor: '#fff' },
style,
multiline && autoHeight
? {
height: Math.max((style as any)?.minHeight || 35, contentHeight)
}
? { height: Math.max((style as any)?.minHeight || 35, contentHeight) }
: {}
)

Expand Down Expand Up @@ -404,7 +404,8 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
extendObject(
{
ref: nodeRef,
style: extendObject({}, normalStyle, layoutStyle)
style: extendObject({}, normalStyle, layoutStyle),
allowFontScaling
},
layoutProps,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface _TextProps extends TextProps {
const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref): JSX.Element => {
const {
style = {},
allowFontScaling = false,
selectable,
'enable-var': enableVar,
'external-var-context': externalVarContext,
Expand Down Expand Up @@ -56,7 +57,8 @@ const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref):
const innerProps = useInnerProps(props, {
ref: nodeRef,
style: normalStyle,
selectable: !!selectable || !!userSelect
selectable: !!selectable || !!userSelect,
allowFontScaling
}, [
'user-select'
], {
Expand Down
10 changes: 1 addition & 9 deletions packages/webpack-plugin/lib/runtime/components/react/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,7 @@ export function isText (ele: ReactNode): ele is ReactElement {
if (isValidElement(ele)) {
const displayName = (ele.type as ExtendedFunctionComponent)?.displayName
const isCustomText = (ele.type as ExtendedFunctionComponent)?.isCustomText
return displayName === 'MpxText' || displayName === 'Text' || !!isCustomText
}
return false
}

export function isEmbedded (ele: ReactNode): ele is ReactElement {
if (isValidElement(ele)) {
const displayName = (ele.type as ExtendedFunctionComponent)?.displayName || ''
return ['mpx-checkbox', 'mpx-radio', 'mpx-switch'].includes(displayName)
return displayName === 'MpxText' || displayName === 'MpxSimpleText' || displayName === 'Text' || !!isCustomText
}
return false
}
Expand Down
35 changes: 25 additions & 10 deletions packages/webpack-plugin/lib/template-compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ function parse (template, options) {
stack.push(element)
} else {
element.unary = true
closeElement(element, meta, options)
closeElement(element, options, meta)
}
},

Expand All @@ -740,7 +740,7 @@ function parse (template, options) {
// pop stack
stack.pop()
currentParent = stack[stack.length - 1]
closeElement(element, meta, options)
closeElement(element, options, meta)
}
},

Expand All @@ -765,7 +765,7 @@ function parse (template, options) {
parent: currentParent
}
children.push(el)
runtimeCompile ? processTextDynamic(el) : processText(el)
runtimeCompile ? processTextDynamic(el) : processText(el, options, meta)
}
},
comment: function comment (text) {
Expand Down Expand Up @@ -2041,7 +2041,7 @@ function postProcessIfReact (el) {
}
}

function processText (el) {
function processText (el, options, meta) {
if (el.type !== 3 || el.isComment) {
return
}
Expand All @@ -2051,17 +2051,32 @@ function processText (el) {
}
el.text = parsed.val
if (isReact(mode)) {
processWrapTextReact(el)
processWrapTextReact(el, options, meta)
}
}

// RN中文字需被Text包裹
function processWrapTextReact (el) {
const parentTag = el.parent.tag
// RN中裸文字需被Text包裹
// 为了批量修改Text默认属性,如allowFontScaling,使用mpx-simple-text进行包裹
function processWrapTextReact (el, options, meta) {
const parent = el.parent
const parentTag = parent.tag
if (parentTag !== 'mpx-text' && parentTag !== 'Text' && parentTag !== 'wxs') {
const wrapper = createASTElement('Text')
const wrapper = createASTElement('mpx-simple-text')
wrapper.isBuiltIn = true
const dataSetAttrs = []
parent.attrsList.forEach(({ name, value }) => {
if (/^data-/.test(name)) {
dataSetAttrs.push({
name,
value
})
}
})
addAttrs(wrapper, dataSetAttrs)
replaceNode(el, wrapper, true)
addChild(wrapper, el)
processBuiltInComponents(wrapper, meta)
processAttrs(wrapper, options)
}
}

Expand Down Expand Up @@ -2667,7 +2682,7 @@ function processElement (el, root, options, meta) {
processAttrs(el, options)
}

function closeElement (el, meta, options) {
function closeElement (el, options, meta) {
postProcessAtMode(el)
postProcessWxs(el, meta)

Expand Down

0 comments on commit d057992

Please sign in to comment.