Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
c2ccaeb
merge feat-withTiming-callback
wenwenhua May 9, 2025
759dd66
动画hooks重新梳理文件结构
wenwenhua May 9, 2025
3a87bf9
动画hooks重新梳理文件结构
wenwenhua May 9, 2025
c903d59
动画hooks重新梳理文件结构
wenwenhua May 9, 2025
6646e8d
feat: merge master
wenwenhua May 23, 2025
13376a7
init
wenwenhua May 23, 2025
d04f5a4
feat: transition run 通
wenwenhua May 27, 2025
2bf8bf5
Merge branch 'master' into feat-transion-25.05.10
wenwenhua May 27, 2025
1001a70
add transition 优先级
wenwenhua May 27, 2025
67a2057
feat: add
wenwenhua May 27, 2025
b315059
feat: 调整优先级
wenwenhua May 29, 2025
9b0860e
feat: 简单整理代码
wenwenhua May 29, 2025
0b9e37a
feat: 整理下公共代码
wenwenhua May 30, 2025
c7da4a0
feat: merge transform
wenwenhua Jun 3, 2025
48ffccc
fix eslint
wenwenhua Jun 3, 2025
c0b262a
bugfix
wenwenhua Jun 3, 2025
9417eed
del log
wenwenhua Jun 3, 2025
3c14a17
fix transform rotateZ(45deg) translateY(10px) 到 transform translateY(…
wenwenhua Jun 4, 2025
ba1c027
feat: toVal值
wenwenhua Jun 4, 2025
db80137
fix 首次渲染执行动画+duration不同执行多次transitionend+transitionend编译不支持提示
wenwenhua Jun 4, 2025
ffae894
add md animation
wenwenhua Jun 4, 2025
498d6de
Merge branch 'master' into feat-transion-25.05.10
wenwenhua Jun 5, 2025
f1492cc
支持颜色渐变
wenwenhua Jun 9, 2025
2a337b0
颜色插值更新
wenwenhua Jun 10, 2025
5ca77a9
Merge branch 'master' into feat-transion-25.05.10
wenwenhua Jun 10, 2025
f01169c
feat: add color & % 动画
wenwenhua Jun 10, 2025
d2c1c2d
feat: add 值类型不一致的提示
wenwenhua Jun 10, 2025
c47d336
add 文档
wenwenhua Jun 10, 2025
4e44dd4
merge master
wenwenhua Jun 18, 2025
bdab697
merge master
wenwenhua Jun 18, 2025
b5e29e9
merge master
wenwenhua Jun 18, 2025
ab84155
Merge branch 'master' into feat-transion-25.05.10
wenwenhua Jun 18, 2025
7066079
merge master
wenwenhua Jul 21, 2025
15d379b
Merge branch 'master' into feat-transion-25.05.10
wenwenhua Jul 22, 2025
44433c6
merge master
wenwenhua Sep 8, 2025
730b427
整理钩子开关
wenwenhua Sep 9, 2025
51ba2d4
feat: cr
wenwenhua Sep 12, 2025
3b9a6f7
feat: add diff
wenwenhua Sep 12, 2025
b7b19ac
Merge branch 'master' into feat-transion-25.05.10
wenwenhua Sep 15, 2025
a93b15a
merge master & fix eslint
wenwenhua Sep 15, 2025
62fc0aa
fix animationType
wenwenhua Sep 16, 2025
58d0546
Merge branch 'master' into feat-transion-25.05.10
wenwenhua Oct 29, 2025
041e23f
Merge branch 'master' into feat-transion-25.05.10
wenwenhua Oct 29, 2025
624f565
fix 百分比转换异常
wenwenhua Oct 29, 2025
ff685c1
Merge branch 'master' into feat-transion-25.05.10
wenwenhua Nov 3, 2025
267a04f
cr fix
wenwenhua Nov 3, 2025
48102b1
add comment
wenwenhua Nov 4, 2025
91fe1be
fix cr
wenwenhua Nov 4, 2025
a4202bc
add md
wenwenhua Nov 4, 2025
e1a050d
fix cr
wenwenhua Nov 6, 2025
19b6b29
fix updateStyleVal
wenwenhua Nov 6, 2025
10616ab
update md
wenwenhua Nov 6, 2025
bc25072
Merge branch 'master' into feat-transion-25.05.10
wenwenhua Nov 6, 2025
68e6c08
fix getAnimatedStyleKeys
wenwenhua Nov 6, 2025
e06215d
fix animationDeps
wenwenhua Nov 6, 2025
fa57026
add animationDeps
wenwenhua Nov 10, 2025
f0c4b71
fix animationType init
wenwenhua Nov 11, 2025
0deee10
merge master
wenwenhua Nov 21, 2025
e352c92
Merge branch 'fix-style-cache' into feat-transion-25.05.10
wenwenhua Nov 21, 2025
5634fd7
add md
wenwenhua Nov 21, 2025
e605be3
Merge branch 'master' into feat-transion-25.05.10
wenwenhua Nov 28, 2025
1d6e68d
fix updateStyleVal
wenwenhua Nov 29, 2025
3b43ac0
Merge branch 'master' into feat-transion-25.05.10
wenwenhua Dec 4, 2025
94cfbde
updateStyleVal 更新
wenwenhua Dec 5, 2025
ab0adb8
transitionend 对齐 wx
wenwenhua Dec 5, 2025
1413d11
transition end 对齐 wx
wenwenhua Dec 6, 2025
7569741
transitionend 调整写法
wenwenhua Dec 8, 2025
045df92
transitionend 调整写法
wenwenhua Dec 8, 2025
be459c1
update animationType & getAnimatedStyleKeys
wenwenhua Dec 8, 2025
eaa4c22
fix
wenwenhua Dec 8, 2025
342cecd
首次更新 lastStyleRef
wenwenhua Dec 9, 2025
782bb91
cr 更新:动画执行
wenwenhua Dec 11, 2025
61d52c1
del log
wenwenhua Dec 11, 2025
ce49a4b
Merge branch 'master' into feat-transion-25.05.10
wenwenhua Dec 16, 2025
7de870e
优化循环次数
wenwenhua Dec 24, 2025
31f2c30
update md
wenwenhua Jan 5, 2026
7fd09a4
Merge branch 'master' into feat-transion-25.05.10
wenwenhua Jan 5, 2026
ca189f9
fix cr animatedKeysShareVal
wenwenhua Jan 6, 2026
15a977b
fix height 设置为transition property 且无起始值或者终值的情况
wenwenhua Jan 7, 2026
0d9869e
add md
wenwenhua Jan 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 108 additions & 1 deletion docs-vitepress/guide/rn/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
RN 样式属性和 Web/小程序中 CSS 样式属性是相交关系:

- **RN 独有属性**:`tintColor`、`writingDirection` 等,CSS 不支持
- **CSS 独有属性**:`clip-path`、`animation`、`transition` 等,RN 不支持
- **CSS 独有属性**:`clip-path`、`animation` 等,RN 不支持

因此,在跨平台开发时:
1. **优先使用交集属性**:尽量使用两边都支持的样式属性
Expand Down Expand Up @@ -1429,3 +1429,110 @@ object-fit: contain; /* 完整显示,保持比例 */
object-fit: cover; /* 覆盖填充,保持比例,可能裁剪 */
object-fit: scale-down; /* 缩小显示 */
```


## 跨端动画
基础组件 view 支持两种动画形式 createAnimation API 和 transition,
可以通过设置 animation 属于来使用 createAnimation API 动画,通过 class 或者 style 设置 css transition 来使用 transition 动画,
可以用过 prop enable-animation = api/transition 来指定使用 createAnimation API/transition 的动画形式,,enable-animation 设置 true 默认为 createAnimation API 形式,需要注意的是指定动画类型后,对应的动画参数也需要匹配设置,详细使用文档如下:

### createAnimation 动画API
创建一个动画实例 animation,调用实例的方法来描述动画,最后通过动画实例的 export 方法导出动画数据传递给组件的 animation 属性。
详情参考以下动画部分微信小程序文档,以下仅描述支持能力有差异部分:
#### [wx.createAnimation](https://developers.weixin.qq.com/miniprogram/dev/api/ui/animation/wx.createAnimation.html)
- 参数 timingFunction 不支持 step-start 和 step-end
#### [动画实例 animation](https://developers.weixin.qq.com/miniprogram/dev/api/ui/animation/Animation.html)
- translateZ() 不支持
- translate3d() 不支持
- rotate3d() 不支持
- rotateZ() 不支持
- scaleZ() 不支持
- scale3d() 不支持
- animation.matrix() 不支持
- animation.matrix3d() 不支持

### CSS transition
CSS transition 动画至少需要设置动画时长和动画属性,可通过单独属性 transition-property 和 transition-property 设置,也可以通过 transition 缩写设置
>重要提示:transition 支持设置百分比,如 ```marginTop: 1%;marginTop: 100%;```;要注意的是起始值和结束值需设置为同一类型,同为px或者同为百分比, 支持 ```marginTop: 10px;marginTop: 100px; ```,**不支持 ```marginTop: 10px; marginTop: 100%;```**

#### [transition](https://developer.mozilla.org/en-US/docs/Web/CSS/transition)
```css
/**** 支持 */
/* property name | duration */
transition: margin-right 4s;
/* property name | duration | delay */
transition: margin-right 4s 1s;
/* property name | duration | easing function */
transition: margin-right 4s ease-in-out;
/* property name | duration | easing function | delay */
transition: margin-right 4s ease-in-out 1s;

/* Apply to 2 properties */
transition: margin-right 4s, color 1s;
```
```css
/**** 需配合 transition-property 使用*/
/* transition 未定义 property 时需配合 transition-property 使用,否则仅设置duration、timingFunciton等参数实际动画不生效 */
transition: 200ms linear 50ms;
transition: 2s, 1s;
```
```css
/**** 不支持:property 不支持设置为 all */
transition: all 0.5s ease-out
```
#### [transition-property](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-property)
不支持设置为 all,不支持自定义
> 支持的 property 合集有:
> rotateX rotateY rotateZ scaleX scaleY skewX skewY translateX translateY opacity backgroundColor width height top right bottom left color borderColor borderBottomColor borderLeftColor borderRightColor borderTopColor borderTopLeftRadius borderTopRightRadius borderBottomLeftRadius borderBottomRightRadius borderRadius borderBottomWidth borderLeftWidth borderRightWidth borderTopWidth borderWidth margin marginBottom marginLeft marginRight marginTop maxHeight maxWidth minHeight minWidth padding paddingBottom paddingLeft paddingRight paddingTop
```css
/**** 支持 */
transition-property: height;
transition-property: height, color;
```
```css
/**** 不支持 */
transition-property: all;
/* <custom-ident> values */
transition-property: test_05;
transition-property: -specific;
transition-property: sliding-vertically;
transition-property: test1, animation4;
transition-property: all, -moz-specific, sliding;
transition-property: inherit;
transition-property: initial;
transition-property: revert;
transition-property: revert-layer;
transition-property: unset;
```
#### [transition-duration](https://developer.mozilla.org/zh-CN/docs/Web/CSS/transition-duration)
```css
/**** 支持 */
transition-duration: 6s;
transition-duration: 120ms;
transition-duration: 1s, 15s;
transition-duration: 10s, 30s, 230ms;
```
#### [transition-delay](https://developer.mozilla.org/zh-CN/docs/Web/CSS/transition-delay)
```css
/**** 支持 */
transition-delay: 3s;
transition-delay: 2s, 4ms;
```
#### [transition-behavior](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-behavior)
不支持
#### [transition-timing-function](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-timing-function)
仅支持 ease、ease-in、ease-out、ease-in-out、linear、cubic-bezier(),不支持 step-start、step-end、steps()

### CSS animation
暂不支持

### 动画监听事件
#### transitionend
- CSS transition 结束或 wx.createAnimation 结束一个阶段时触发
- 不属于冒泡事件,需要绑定在真正发生了动画的节点上才会生效
#### animationstart
暂不支持
#### animationiteration
暂不支持
#### animationend
暂不支持
4 changes: 3 additions & 1 deletion packages/webpack-plugin/lib/platform/style/wx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { parseValues } = require('../../../utils/string')

module.exports = function getSpec ({ warn, error }) {
// React Native 双端都不支持的 CSS property
const unsupportedPropExp = /^(white-space|text-overflow|animation|transition|font-variant-caps|font-variant-numeric|font-variant-east-asian|font-variant-alternates|font-variant-ligatures|background-position|caret-color)$/
const unsupportedPropExp = /^(white-space|text-overflow|animation|font-variant-caps|font-variant-numeric|font-variant-east-asian|font-variant-alternates|font-variant-ligatures|background-position|caret-color)$/
const unsupportedPropMode = {
// React Native ios 不支持的 CSS property
ios: /^(vertical-align)$/,
Expand Down Expand Up @@ -400,6 +400,8 @@ module.exports = function getSpec ({ warn, error }) {
// css var & 数组直接返回
if (Array.isArray(value) || cssVariableExp.test(value)) return { prop, value }
const values = parseValues(value)
// Todo transform 排序不一致时,transform动画会闪烁,故这里同样的排序输出 transform
values.sort()
const transform = []
values.forEach(item => {
const match = item.match(/([/\w]+)\((.+)\)/)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { error, collectDataset, hasOwn } from '@mpxjs/utils'
import { useRef } from 'react'
import useAnimationAPIHooks from './useAnimationAPIHooks'
import useTransitionHooks from './useTransitionHooks'
import type { AnimatableValue } from 'react-native-reanimated'
import type { MutableRefObject } from 'react'
import type { NativeSyntheticEvent } from 'react-native'
import type { _ViewProps } from '../mpx-view'

// 动画类型
export type AnimationType = 'api'|'animation'|'transition'|'none'

export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAnimation?: boolean | AnimationType, layoutRef: MutableRefObject<any>, transitionend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void }) {
const { style: originalStyle = {}, enableAnimation, animation, transitionend, layoutRef } = props
// 记录动画类型
let animationType = ''
if (hasOwn(originalStyle, 'animation') || (hasOwn(originalStyle, 'animationName') && hasOwn(originalStyle, 'animationDuration'))) {
// css animation 只做检测提示
animationType = 'animation'
}
if (!!animation || enableAnimation === true) {
animationType = 'api'
}
// 优先级 css transition > API
if (hasOwn(originalStyle, 'transition') || (hasOwn(originalStyle, 'transitionProperty') && hasOwn(originalStyle, 'transitionDuration'))) {
animationType = 'transition'
}
// 优先以 enableAnimation 定义类型为准
if (enableAnimation === 'api' || enableAnimation === 'transition' || enableAnimation === 'animation') {
animationType = enableAnimation
}
const animationTypeRef = useRef(animationType)
if (animationType! && animationTypeRef.current !== animationType) {
// 允许 API、CssTransition 到 none,不允许 API、CssTransition 互切,不允许 none 到 API、CssTransition
error('[Mpx runtime error]: The animation type should be stable in the component lifecycle, or you can set animation type with [enable-animation].')
}
if (animationType === 'animation') {
// 暂不支持 CssAnimation 提示
error('[Mpx runtime error]: CSS animation is not supported yet')
return { enableStyleAnimation: false }
}
if (!animationTypeRef.current) return { enableStyleAnimation: false }

const hooksProps = { style: originalStyle }
if (transitionend && typeof transitionend === 'function') {
function withTimingCallback (finished?: boolean, current?: AnimatableValue, duration?: number) {
const target = {
id: animation?.id || -1,
dataset: collectDataset(props),
offsetLeft: layoutRef?.current?.offsetLeft || 0,
offsetTop: layoutRef?.current?.offsetTop || 0
}
transitionend!({
type: 'transitionend',
// elapsedTime 对齐wx 单位s
detail: { elapsedTime: duration ? duration / 1000 : 0, finished, current },
target,
currentTarget: target,
timeStamp: Date.now()
})
}
Object.assign(hooksProps, { transitionend: withTimingCallback })
}
if (animationTypeRef.current === 'api') {
Object.assign(hooksProps, { animation })
}
return {
enableStyleAnimation: !!animationTypeRef.current,
animationStyle: animationTypeRef.current === 'api'
// eslint-disable-next-line react-hooks/rules-of-hooks
? useAnimationAPIHooks(hooksProps)
// eslint-disable-next-line react-hooks/rules-of-hooks
: useTransitionHooks(hooksProps)
}
}
Loading