Skip to content
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

animation api #1551

Open
wants to merge 71 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
1e82c21
feat: init animation api
wenwenhua Jul 16, 2024
b1863ad
fix style=[] & export Animation
wenwenhua Jul 17, 2024
b1469ca
mark 主流程跑通
wenwenhua Jul 18, 2024
0318072
eslint fix
wenwenhua Jul 18, 2024
59efe2c
fix animation变化后动画不延续问题
wenwenhua Jul 19, 2024
baf9ad2
支持rpx
wenwenhua Jul 19, 2024
067046c
add props
wenwenhua Jul 19, 2024
4385c96
feat: add 不支持api的提示
wenwenhua Jul 23, 2024
5c54805
add backgroundColor
wenwenhua Jul 23, 2024
d710134
feat: 对齐微信animation结构 & add rotate
wenwenhua Jul 23, 2024
9d24223
Merge branch 'master' into feat-animation-api-240716
wenwenhua Aug 9, 2024
e72d917
feat: eslint
wenwenhua Aug 9, 2024
8ccd71a
Merge branch 'master' into feat-animation-api-240716
wenwenhua Aug 15, 2024
25a6281
add id
wenwenhua Aug 16, 2024
2b148ca
Merge branch 'master' into feat-animation-api-240716
wenwenhua Aug 16, 2024
ec7a617
add useNativeDriver
wenwenhua Aug 16, 2024
eeb69ba
Merge branch 'master' into feat-animation-api-240716
wenwenhua Aug 19, 2024
c32b37c
Merge branch 'master' into feat-animation-api-240716
wenwenhua Aug 26, 2024
519f912
Merge branch 'master' into feat-animation-api-240716
wenwenhua Aug 27, 2024
19cf2d0
cr update
wenwenhua Aug 27, 2024
d4b62d7
ts fix
wenwenhua Aug 27, 2024
7ba8e8a
Merge branch 'master' into feat-animation-api-240716
wenwenhua Aug 28, 2024
a5e2b5b
update cr
wenwenhua Aug 28, 2024
c45ec2e
merge master
wenwenhua Sep 12, 2024
852b271
Merge branch 'master' into feat-animation-api-240716
wenwenhua Sep 20, 2024
6804be3
merge master
wenwenhua Sep 25, 2024
a90b6e6
解决合入master后新增的问题
wenwenhua Sep 25, 2024
a78f9c9
merge master
wenwenhua Sep 27, 2024
b26b8ad
merge master
wenwenhua Sep 27, 2024
9d4f6b3
update: reanimated 重构动画api
wenwenhua Sep 27, 2024
91c81d9
del log
wenwenhua Sep 27, 2024
1cb41c8
添加动画库依赖&新增代码注释&删除一下log
wenwenhua Sep 27, 2024
2c7931e
merge master
wenwenhua Oct 8, 2024
126fd6d
Merge branch 'master' into feat-animation-api-240716
wenwenhua Oct 8, 2024
a716264
Merge branch 'master' into feat-animation-api-240716
wenwenhua Oct 16, 2024
e080adb
merge master
wenwenhua Oct 21, 2024
e60d277
Merge branch 'master' into feat-animation-api-240716
hiyuki Oct 22, 2024
0bd5fee
merge master
wenwenhua Oct 22, 2024
490e5c9
Merge branch 'master' into feat-animation-api-240716
wenwenhua Oct 28, 2024
b6d35d9
Merge branch 'master' into feat-animation-api-240716
wenwenhua Oct 29, 2024
775e449
fix error
wenwenhua Oct 29, 2024
0b64c8a
del log 999000
wenwenhua Oct 29, 2024
0999334
cr调整
wenwenhua Oct 30, 2024
4f74a27
Merge branch 'master' into feat-animation-api-240716
wenwenhua Oct 30, 2024
d012171
fix 一些小问题: 多次animation变化 &
wenwenhua Oct 30, 2024
8e3f18f
fix eslint
wenwenhua Oct 30, 2024
f9aecd2
fix ts error
wenwenhua Oct 31, 2024
7221d44
Merge branch 'master' into feat-animation-api-240716
wenwenhua Oct 31, 2024
9a46a2b
cr 第二次调整
wenwenhua Oct 31, 2024
d4e9446
cr 第二次调整
wenwenhua Oct 31, 2024
2146b60
Merge branch 'master' into feat-animation-api-240716
wenwenhua Oct 31, 2024
ff87a81
cr 第二次调整
wenwenhua Oct 31, 2024
d8b2f41
fix eslint error
wenwenhua Nov 1, 2024
de0d3e2
fix _formatTransformOrigin
wenwenhua Nov 2, 2024
e52e7fc
fix _formatTransformOrigin
wenwenhua Nov 4, 2024
5da0ded
Merge branch 'master' into feat-animation-api-240716
wenwenhua Nov 4, 2024
426e227
needSetCallback=true
wenwenhua Nov 4, 2024
75e8cdf
del objectSpread
wenwenhua Nov 4, 2024
3a42a17
fix ts error
wenwenhua Nov 4, 2024
047070d
Merge branch 'master' into feat-animation-api-240716
wenwenhua Nov 4, 2024
da67d62
支持 border width 复合写法
wenwenhua Nov 4, 2024
8b07541
fix ts error
wenwenhua Nov 4, 2024
92d1ea9
fix ts error
wenwenhua Nov 4, 2024
a6cf520
fix ts error
wenwenhua Nov 4, 2024
3deb5b4
fix ts error
wenwenhua Nov 4, 2024
d10bc3c
fix ts error
wenwenhua Nov 4, 2024
3038eab
fix ts error mpx-webview
wenwenhua Nov 4, 2024
9486a07
fix ts error
wenwenhua Nov 4, 2024
4f00f5a
rename formatCompositeVal
wenwenhua Nov 4, 2024
efbbbf2
add border color
wenwenhua Nov 4, 2024
58f0670
fix eslitn
wenwenhua Nov 4, 2024
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
281 changes: 281 additions & 0 deletions packages/api-proxy/src/platform/api/animation/animation.react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
class Animation {
constructor (
{
duration = 400,
delay = 0,
timingFunction = 'linear',
transformOrigin = '50% 50% 0'
} = {}
) {
// 默认值
this._setDefault(duration, delay, timingFunction, transformOrigin)
this.id = 0
}

_transformUnit (...args) {
Copy link
Collaborator

@hiyuki hiyuki Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rpx/vh/vw走global.__formatValue()

return args.map(each => {
return global.__formatValue(each)
})
}

_formatTransformOrigin (transformOrigin) {
const transformOriginArr = transformOrigin.trim().split(/\s+/, 3).map(item => global.__formatValue(item))
switch (transformOriginArr.length) {
case 0:
transformOriginArr.push('50%', '50%', 0)
break
case 1:
transformOriginArr.push('50%', 0)
break
case 2:
transformOriginArr.push(0)
break
}
return transformOriginArr
}

// 设置默认值
_setDefault (duration, delay, timingFunction, transformOrigin) {
this.DEFAULT = { duration, delay, timingFunction, transformOrigin }
}

// 属性组合
rules = new Map()
// transform 对象
transform = new Map()
// 组合动画
steps = []

matrix (a, b, c, d, tx, ty) { // Todo
console.error('React Native 不支持 matrix 动画')
// this.transform.set('matrix', [a, b, c, d, tx, ty])
return this
}

matrix3d (a1, b1, c1, d1,
a2, b2, c2, d2,
a3, b3, c3, d3,
a4, b4, c4, d4
) {
console.error('React Native 不支持 matrix3d 动画')
// this.transform.set('matrix3d', [ // Todo
// a1, b1, c1, d1,
// a2, b2, c2, d2,
// a3, b3, c3, d3,
// a4, b4, c4, d4
// ])
return this
}

rotate (angle) { // 旋转变换
this.transform.set('rotate', `${angle}deg`)
return this
}

rotate3d (x, y, z, angle) {
if (typeof y !== 'number') {
this.transform.set('rotate3d', x)
} else {
// this.transform.set('rotate3d', [x, y, z, angle])
this.rotateX(x)
this.rotateY(y)
this.rotateZ(z)
this.rotate(angle)
}
return this
}

rotateX (angle) {
this.transform.set('rotateX', `${angle}deg`)
return this
}

rotateY (angle) {
this.transform.set('rotateY', `${angle}deg`)
return this
}

rotateZ (angle) {
this.transform.set('rotateZ', `${angle}deg`)
return this
}

scale (x, y) {
const scaleY = (typeof y !== 'undefined' && y !== null) ? y : x
this.scaleX(x)
this.scaleY(scaleY)
// this.transform.set('scale', [x, scaleY])
return this
}

scaleX (scale) {
this.transform.set('scaleX', scale)
return this
}

scaleY (scale) {
this.transform.set('scaleY', scale)
return this
}

scaleZ (scale) { // Todo Invariant Violation: Invalid transform scaleZ: {"scaleZ":0}
console.error('React Native 不支持 transform scaleZ')
// this.transform.set('scaleZ', scale)
return this
}

scale3d (x, y, z) { // Todo Invariant Violation: Invalid transform scaleZ: {"scaleZ":0}
console.error('React Native 不支持 transform scaleZ,故不支持 scale3d')
// this.scaleX(x)
// this.scaleY(y)
// this.scaleZ(z)
return this
}

skew (x, y) {
// this.transform.set('skew', [x, y])
this.skewX(x)
this.skewY(y)
return this
}

skewX (angle) {
this.transform.set('skewX', `${angle}deg`)
return this
}

skewY (angle) {
this.transform.set('skewY', `${angle}deg`)
return this
}

translate (x, y) {
[x, y] = this._transformUnit(x, y)
// this.transform.set('translate', [x, y])
this.translateX(x)
this.translateY(y)
return this
}

translateX (translate) {
[translate] = this._transformUnit(translate)
this.transform.set('translateX', translate)
return this
}

translateY (translate) {
[translate] = this._transformUnit(translate)
this.transform.set('translateY', translate)
return this
}

translateZ (translate) { // Todo Invariant Violation: Invalid transform translateZ: {"translateZ":0}
console.error('React Native 不支持 transform translateZ')
// [translate] = this._transformUnit(translate)
// this.transform.set('translateZ', translate)
return this
}

translate3d (x, y, z) { // Todo Invariant Violation: Invalid transform translateZ: {"translateZ":0}
console.error('React Native 不支持 transform translateZ,故无法支持 translate3d')
// [x, y, z] = this._transformUnit(x, y, z)
// // this.transform.set('translate3d', [x, y, z])
// this.translateX(x)
// this.translateY(y)
// this.translateZ(z)
return this
}

opacity (value) {
this.rules.set('opacity', value)
return this
}

backgroundColor (value) {
this.rules.set('backgroundColor', value)
return this
}

width (value) {
[value] = this._transformUnit(value)
this.rules.set('width', value)
return this
}

height (value) {
[value] = this._transformUnit(value)
this.rules.set('height', value)
return this
}

top (value) {
[value] = this._transformUnit(value)
this.rules.set('top', value)
return this
}

right (value) {
[value] = this._transformUnit(value)
this.rules.set('right', value)
return this
}

bottom (value) {
[value] = this._transformUnit(value)
this.rules.set('bottom', value)
return this
}

left (value) {
[value] = this._transformUnit(value)
this.rules.set('left', value)
return this
}

// 关键帧载入
step (arg = {}) {
const { DEFAULT } = this
let {
duration = DEFAULT.duration,
delay = DEFAULT.delay,
timingFunction = DEFAULT.timingFunction,
transformOrigin = DEFAULT.transformOrigin
Copy link
Collaborator

@hiyuki hiyuki Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里需要确认是不是每次transformOrigin都会置为默认值, 如果每个step都有默认值的话,后面那个地方每个step必然要设置transformOrigin,就不用判断那个是否need了

} = arg
if (typeof transformOrigin !== 'string') {
console.error('Value of transformOrigin only support string type, please check again')
transformOrigin = DEFAULT.transformOrigin
}
this.steps.push({
animatedOption: {
duration,
delay,
timingFunction,
transformOrigin: this._formatTransformOrigin(transformOrigin)
},
rules: this.rules,
transform: this.transform
})
// 清空 rules 和 transform
this.rules = new Map()
this.transform = new Map()
return this
}

// 数据
createAnimationData () {
const steps = this.steps
this.steps = []
return steps
}

// 动画数据产出
export () {
this.id++
return {
id: this.id,
actions: this.createAnimationData()
}
}
}

export default Animation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './index.ios'
5 changes: 5 additions & 0 deletions packages/api-proxy/src/platform/api/animation/index.ios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Animation from './animation.react'

export const createAnimation = (option) => {
return new Animation(option)
}
63 changes: 17 additions & 46 deletions packages/webpack-plugin/lib/platform/style/wx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,16 @@ module.exports = function getSpec ({ warn, error }) {
flex: ['flexGrow', 'flexShrink', 'flexBasis'],
// flex-flow: <'flex-direction'> or flex-flow: <'flex-direction'> and <'flex-wrap'>
'flex-flow': ['flexDirection', 'flexWrap'],
'border-radius': ['borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius']
'border-radius': ['borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius'],
'border-width': ['borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth'],
'border-color': ['borderTopColor', 'borderRightColor', 'borderBottomColor', 'borderLeftColor'],
margin: ['marginTop', 'marginRight', 'marginBottom', 'marginLeft'],
padding: ['paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft']
}
const formatAbbreviation = ({ prop, value, selector }, { mode }) => {
const original = `${prop}:${value}`
const props = AbbreviationMap[prop]
const values = parseValues(value)
const values = Array.isArray(value) ? value : parseValues(value)
const cssMap = []
let idx = 0
let propsIdx = 0
Expand Down Expand Up @@ -255,32 +259,20 @@ module.exports = function getSpec ({ warn, error }) {
return cssMap
}

// margin padding
const formatMargins = ({ prop, value, selector }) => {
const values = parseValues(value)
// format
let suffix = []
const formatCompositeVal = ({ prop, value, selector }, { mode }) => {
const values = parseValues(value).splice(0, 4)
switch (values.length) {
// case 1:
case 1:
verifyValues({ prop, value, selector }, false)
return { prop, value }
case 2:
suffix = ['Vertical', 'Horizontal']
values.push(...values)
break
case 3:
suffix = ['Top', 'Horizontal', 'Bottom']
break
case 4:
suffix = ['Top', 'Right', 'Bottom', 'Left']
values.push(values[1])
break
}
return values.map((value, index) => {
const newProp = `${prop}${suffix[index] || ''}`
// validate
verifyValues({ prop: hump2dash(newProp), value, selector }, false)
return {
prop: newProp,
value: value
}
})
return formatAbbreviation({ prop, value: values, selector }, { mode })
}

// line-height
Expand Down Expand Up @@ -374,22 +366,6 @@ module.exports = function getSpec ({ warn, error }) {
return false
}

// border-radius 缩写转换
const getBorderRadius = ({ prop, value, selector }, { mode }) => {
const values = parseValues(value)
if (values.length === 1) {
verifyValues({ prop, value, selector }, false)
return { prop, value }
} else {
if (values.length === 2) {
values.push(...values)
} else if (values.length === 3) {
values.push(values[1])
}
return formatAbbreviation({ prop, value: values.join(' ') }, { mode })
}
}

// transform 转换
const formatTransform = ({ prop, value, selector }, { mode }) => {
if (Array.isArray(value)) return { prop, value }
Expand Down Expand Up @@ -566,15 +542,10 @@ module.exports = function getSpec ({ warn, error }) {
ios: checkBackgroundImage,
android: checkBackgroundImage
},
{
test: 'border-radius',
ios: getBorderRadius,
android: getBorderRadius
},
{ // margin padding 内外边距的处理
test: /^(margin|padding)$/,
ios: formatMargins,
android: formatMargins
test: /^(margin|padding|border-radius|border-width|border-color)$/,
ios: formatCompositeVal,
android: formatCompositeVal
},
{ // line-height 换算
test: 'line-height',
Expand Down
Loading
Loading