11import { useEffect , useCallback , useMemo , useRef , ReactNode , ReactElement , isValidElement , useContext , useState , Dispatch , SetStateAction , Children , cloneElement , createElement , MutableRefObject } from 'react'
22import { LayoutChangeEvent , TextStyle , ImageProps , Image } from 'react-native'
3- import { isObject , isFunction , isNumber , hasOwn , diffAndCloneA , error , warn } from '@mpxjs/utils'
3+ import { isObject , isFunction , isNumber , hasOwn , diffAndCloneA , error , warn , isEmptyObject } from '@mpxjs/utils'
44import { VarContext , ScrollViewContext , RouteContext } from './context'
55import { ExpressionParser , parseFunc , ReplaceSource } from './parser'
66import { initialWindowMetrics } from 'react-native-safe-area-context'
@@ -238,7 +238,7 @@ function transformVar (styleObj: Record<string, any>, varKeyPaths: Array<Array<s
238238 const resolved = resolveVar ( value , varContext )
239239 if ( resolved === undefined ) {
240240 delete target [ key ]
241- error ( `Can not resolve css var at ${ varKeyPath . join ( '.' ) } :${ value } .` )
241+ // error(`Can not resolve css var at ${varKeyPath.join('.')}:${value}.`)
242242 return
243243 }
244244 target [ key ] = resolved
@@ -390,6 +390,14 @@ function transformBoxShadow (styleObj: Record<string, any>) {
390390 } , '' )
391391}
392392
393+ function transformZIndex ( styleObj : Record < string , any > ) {
394+ if ( ! styleObj . zIndex || typeof styleObj . zIndex === 'number' ) return
395+ if ( styleObj . zIndex === 'auto' ) {
396+ error ( 'Property [z-index] does not supported [auto], please check again!' )
397+ styleObj . zIndex = 0
398+ }
399+ }
400+
393401interface TransformStyleConfig {
394402 enableVar ?: boolean
395403 externalVarContext ?: Record < string , any >
@@ -446,17 +454,20 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
446454 }
447455 }
448456
449- function calcVisitor ( { value, keyPath } : VisitorArg ) {
457+ function calcVisitor ( { key , value, keyPath } : VisitorArg ) {
450458 if ( calcUseRegExp . test ( value ) ) {
459+ // calc translate & border-radius 的百分比计算
460+ if ( hasOwn ( selfPercentRule , key ) && / % / . test ( value ) ) {
461+ hasSelfPercent = true
462+ percentKeyPaths . push ( keyPath . slice ( ) )
463+ }
451464 calcKeyPaths . push ( keyPath . slice ( ) )
452465 }
453466 }
454467
455468 function percentVisitor ( { key, value, keyPath } : VisitorArg ) {
456- if ( hasOwn ( selfPercentRule , key ) && PERCENT_REGEX . test ( value ) ) {
457- hasSelfPercent = true
458- percentKeyPaths . push ( keyPath . slice ( ) )
459- } else if ( ( key === 'fontSize' || key === 'lineHeight' ) && PERCENT_REGEX . test ( value ) ) {
469+ // fixme 去掉 translate & border-radius 的百分比计算
470+ if ( ( key === 'fontSize' || key === 'lineHeight' ) && PERCENT_REGEX . test ( value ) ) {
460471 percentKeyPaths . push ( keyPath . slice ( ) )
461472 }
462473 }
@@ -466,10 +477,10 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
466477 [ envVisitor , percentVisitor , calcVisitor ] . forEach ( visitor => visitor ( { target, key, value, keyPath } ) )
467478 }
468479 }
469-
480+ // transform 字符串格式转化数组格式(先转数组再处理css var)
481+ transformTransform ( styleObj )
470482 // traverse var & generate normalStyle
471483 traverseStyle ( styleObj , [ varVisitor ] )
472-
473484 hasVarDec = hasVarDec || ! ! externalVarContext
474485 enableVar = enableVar || hasVarDec || hasVarUse
475486 const enableVarRef = useRef ( enableVar )
@@ -533,10 +544,11 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
533544 transformStringify ( normalStyle )
534545 // transform rpx to px
535546 transformBoxShadow ( normalStyle )
536-
537- // transform 字符串格式转化数组格式
538- transformTransform ( normalStyle )
539-
547+ // transform z-index auto to 0
548+ transformZIndex ( normalStyle )
549+ if ( Array . isArray ( normalStyle . transform ) ) {
550+ normalStyle . transform = normalStyle . transform . filter ( item => ! isEmptyObject ( item ) )
551+ }
540552 return {
541553 hasVarDec,
542554 varContextRef,
0 commit comments