-
Notifications
You must be signed in to change notification settings - Fork 376
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
wenwenhua
wants to merge
71
commits into
master
Choose a base branch
from
feat-animation-api-240716
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+594
−66
Open
animation api #1551
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 b1863ad
fix style=[] & export Animation
wenwenhua b1469ca
mark 主流程跑通
wenwenhua 0318072
eslint fix
wenwenhua 59efe2c
fix animation变化后动画不延续问题
wenwenhua baf9ad2
支持rpx
wenwenhua 067046c
add props
wenwenhua 4385c96
feat: add 不支持api的提示
wenwenhua 5c54805
add backgroundColor
wenwenhua d710134
feat: 对齐微信animation结构 & add rotate
wenwenhua 9d24223
Merge branch 'master' into feat-animation-api-240716
wenwenhua e72d917
feat: eslint
wenwenhua 8ccd71a
Merge branch 'master' into feat-animation-api-240716
wenwenhua 25a6281
add id
wenwenhua 2b148ca
Merge branch 'master' into feat-animation-api-240716
wenwenhua ec7a617
add useNativeDriver
wenwenhua eeb69ba
Merge branch 'master' into feat-animation-api-240716
wenwenhua c32b37c
Merge branch 'master' into feat-animation-api-240716
wenwenhua 519f912
Merge branch 'master' into feat-animation-api-240716
wenwenhua 19cf2d0
cr update
wenwenhua d4b62d7
ts fix
wenwenhua 7ba8e8a
Merge branch 'master' into feat-animation-api-240716
wenwenhua a5e2b5b
update cr
wenwenhua c45ec2e
merge master
wenwenhua 852b271
Merge branch 'master' into feat-animation-api-240716
wenwenhua 6804be3
merge master
wenwenhua a90b6e6
解决合入master后新增的问题
wenwenhua a78f9c9
merge master
wenwenhua b26b8ad
merge master
wenwenhua 9d4f6b3
update: reanimated 重构动画api
wenwenhua 91c81d9
del log
wenwenhua 1cb41c8
添加动画库依赖&新增代码注释&删除一下log
wenwenhua 2c7931e
merge master
wenwenhua 126fd6d
Merge branch 'master' into feat-animation-api-240716
wenwenhua a716264
Merge branch 'master' into feat-animation-api-240716
wenwenhua e080adb
merge master
wenwenhua e60d277
Merge branch 'master' into feat-animation-api-240716
hiyuki 0bd5fee
merge master
wenwenhua 490e5c9
Merge branch 'master' into feat-animation-api-240716
wenwenhua b6d35d9
Merge branch 'master' into feat-animation-api-240716
wenwenhua 775e449
fix error
wenwenhua 0b64c8a
del log 999000
wenwenhua 0999334
cr调整
wenwenhua 4f74a27
Merge branch 'master' into feat-animation-api-240716
wenwenhua d012171
fix 一些小问题: 多次animation变化 &
wenwenhua 8e3f18f
fix eslint
wenwenhua f9aecd2
fix ts error
wenwenhua 7221d44
Merge branch 'master' into feat-animation-api-240716
wenwenhua 9a46a2b
cr 第二次调整
wenwenhua d4e9446
cr 第二次调整
wenwenhua 2146b60
Merge branch 'master' into feat-animation-api-240716
wenwenhua ff87a81
cr 第二次调整
wenwenhua d8b2f41
fix eslint error
wenwenhua de0d3e2
fix _formatTransformOrigin
wenwenhua e52e7fc
fix _formatTransformOrigin
wenwenhua 5da0ded
Merge branch 'master' into feat-animation-api-240716
wenwenhua 426e227
needSetCallback=true
wenwenhua 75e8cdf
del objectSpread
wenwenhua 3a42a17
fix ts error
wenwenhua 047070d
Merge branch 'master' into feat-animation-api-240716
wenwenhua da67d62
支持 border width 复合写法
wenwenhua 8b07541
fix ts error
wenwenhua 92d1ea9
fix ts error
wenwenhua a6cf520
fix ts error
wenwenhua 3deb5b4
fix ts error
wenwenhua d10bc3c
fix ts error
wenwenhua 3038eab
fix ts error mpx-webview
wenwenhua 9486a07
fix ts error
wenwenhua 4f00f5a
rename formatCompositeVal
wenwenhua efbbbf2
add border color
wenwenhua 58f0670
fix eslitn
wenwenhua File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
281 changes: 281 additions & 0 deletions
281
packages/api-proxy/src/platform/api/animation/animation.react.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './index.ios' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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()