-
Notifications
You must be signed in to change notification settings - Fork 390
支持 transition-duration delay easing等动态设置 #2457
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
Open
wenwenhua
wants to merge
19
commits into
master
Choose a base branch
from
fix-transform-order
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.
+50
−16
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
11305ed
支持动态变更transition-duration等
wenwenhua 73e315b
Merge branch 'fix-transform-order' of github.com:didi/mpx into fix-tr…
wenwenhua 2f6f741
Merge branch 'master' into fix-transform-order
wenwenhua 07c8e80
diff transition
wenwenhua 756bc69
add duration delay 更新
wenwenhua 0a90878
注释
wenwenhua ef8112e
Merge branch 'master' into fix-transform-order
wenwenhua 428a2a7
fix eslint
wenwenhua 38afa53
del transitionProperty
wenwenhua 601d9e4
Merge branch 'master' into fix-transform-order
wenwenhua 924de07
Merge branch 'master' into fix-transform-order
wenwenhua aeb09a7
cr update
wenwenhua 014530e
eslint fix
wenwenhua 942d866
Merge branch 'master' into fix-transform-order
wenwenhua f185fa8
cr update
wenwenhua 88babc4
cr update
wenwenhua 428131a
fix .page 选择器不能生效问题
wenwenhua 00a88d2
merge master
wenwenhua 3180c45
update md
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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -144,7 +144,7 @@ function parseTransitionStyle (originalStyle: ExtendedViewStyle) { | |
| const transitionMap = transitionData.reduce((acc, cur) => { | ||
| // hasOwn(transitionSupportedProperty, dash2hump(val)) || val === Transform | ||
| const { property = '', duration = 0, delay = 0, easing = Easing.inOut(Easing.ease) } = cur | ||
| if ((hasOwn(transitionSupportedProperty, dash2hump(property)) || property === 'transform') && duration > 0) { | ||
| if ((hasOwn(transitionSupportedProperty, dash2hump(property)) || property === 'transform') && duration >= 0) { | ||
| acc[property] = { | ||
| duration, | ||
| delay, | ||
|
|
@@ -157,17 +157,51 @@ function parseTransitionStyle (originalStyle: ExtendedViewStyle) { | |
| return transitionMap | ||
| } | ||
|
|
||
| const transitionKeys = ['transition', 'transitionDuration', 'transitionTimingFunction', 'transitionDelay', 'transitionProperty'] as const | ||
|
|
||
| function getTransitionPropertyKeys (map: TransitionMap): string { | ||
| return Object.keys(map).sort().join(',') | ||
| } | ||
|
|
||
| export default function useTransitionHooks<T, P> (props: AnimationHooksPropsType) { | ||
| // console.log(`useTransitionHooks, props=`, props) | ||
| const { style: originalStyle = {}, transitionend } = props | ||
| // style变更标识(首次render不执行),初始值为0,首次渲染后为1 | ||
| const animationDeps = useRef(0) | ||
| // 记录上次style map | ||
| // const lastStyleRef = useRef({} as {[propName: keyof ExtendedViewStyle]: number|string}) | ||
| // ** 从 style 中获取动画数据 | ||
| // transition 时序属性动态更新追踪 | ||
| const lastTransitionStyleRef = useRef<Record<string, any>>( | ||
| transitionKeys.reduce((acc, key) => { acc[key] = originalStyle[key]; return acc }, {} as Record<string, any>) | ||
| ) | ||
| const prevTransitionMapRef = useRef<TransitionMap | null>(null) | ||
| // ** 从 style 中获取动画数据(支持动态更新 transitionDuration/transitionDelay/transitionTimingFunction) | ||
| const transitionMap = useMemo(() => { | ||
| return parseTransitionStyle(originalStyle) | ||
| }, []) | ||
| const prevStyle = lastTransitionStyleRef.current | ||
| // 检测 transition 时序属性是否变化并更新 | ||
| let hasChanged = false | ||
| transitionKeys.forEach(key => { | ||
| if (prevStyle[key] !== originalStyle[key]) { | ||
| hasChanged = true | ||
| prevStyle[key] = originalStyle[key] | ||
| } | ||
| }) | ||
| // 时序属性未变化且非首次计算,跳过重新解析 | ||
| if (!hasChanged && prevTransitionMapRef.current) { | ||
| return prevTransitionMapRef.current | ||
| } | ||
| const newTransitionMap = parseTransitionStyle(originalStyle) | ||
|
Collaborator
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. 这堆逻辑到底在干嘛?为啥需要这么复杂? |
||
| if (!prevTransitionMapRef.current) { | ||
| // 首次计算 | ||
| prevTransitionMapRef.current = newTransitionMap | ||
| return newTransitionMap | ||
| } | ||
| // 检测 transitionProperty 是否变化,变化时直接返回上一次的 transitionMap | ||
| if (getTransitionPropertyKeys(newTransitionMap) !== getTransitionPropertyKeys(prevTransitionMapRef.current)) { | ||
| error('[Mpx runtime error]: dynamic setting transitionProperty is not supported') | ||
| return prevTransitionMapRef.current | ||
| } | ||
| prevTransitionMapRef.current = newTransitionMap | ||
| return newTransitionMap | ||
| }, [originalStyle]) | ||
| // ** style prop sharedValue interpolateOutput: SharedValue<InterpolateOutput> | ||
| const { shareValMap, animatedKeys, animatedStyleKeys } = useMemo(() => { | ||
| // 记录需要执行动画的 propName | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.