Skip to content

Commit

Permalink
fix style更新 动画hooks没同步问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wenwenhua committed Dec 4, 2024
1 parent 7dfd0d1 commit 7928037
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -789,10 +789,13 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
throw new Error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.')
}
const finalStyle = enableAnimation
? useAnimationHooks({
animation,
style: viewStyle
})
? [
viewStyle,
useAnimationHooks({
animation,
style: viewStyle
})
]
: viewStyle

const innerProps = useInnerProps(props, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,31 @@ const InitialValue: ExtendedViewStyle = Object.assign({
const TransformOrigin = 'transformOrigin'
// transform
const isTransform = (key: string) => Object.keys(TransformInitial).includes(key)
// 多value解析
const parseValues = (str: string, char = ' ') => {
let stack = 0
let temp = ''
const result = []
for (let i = 0; i < str.length; i++) {
if (str[i] === '(') {
stack++
} else if (str[i] === ')') {
stack--
}
// 非括号内 或者 非分隔字符且非空
if (stack !== 0 || (str[i] !== char && str[i] !== ' ')) {
temp += str[i]
}
if ((stack === 0 && str[i] === char) || i === str.length - 1) {
result.push(temp)
temp = ''
}
}
return result
}
// parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
const parseTransform = (transformStr: string) => {
const values = transformStr.trim().split(/\s+/)
const values = parseValues(transformStr)
const transform: {[propName: string]: string|number|number[]}[] = []
values.forEach(item => {
const match = item.match(/([/\w]+)\(([^)]+)\)/)
Expand All @@ -109,7 +131,7 @@ const parseTransform = (transformStr: string) => {
break
case 'matrix':
case 'matrix3d':
transform.push({ [key]: val.split(',').map(val => +val) })
transform.push({ [key]: parseValues(val, ',').map(val => +val) })
break
case 'translate':
case 'scale':
Expand All @@ -120,8 +142,8 @@ const parseTransform = (transformStr: string) => {
{
// 2 个以上的值处理
key = key.replace('3d', '')
const vals = val.split(',', key === 'rotate' ? 4 : 3)
// scale(.5) === scaleX(.5) scaleY(.5) 这里处理一下
const vals = parseValues(val, ',').splice(0, key === 'rotate' ? 4 : 3)
// scale(.5) === scaleX(.5) scaleY(.5)
if (vals.length === 1 && key === 'scale') {
vals.push(vals[0])
}
Expand Down

0 comments on commit 7928037

Please sign in to comment.