Skip to content

Commit

Permalink
fix(*): hover style.
Browse files Browse the repository at this point in the history
  • Loading branch information
shangqunfeng committed Dec 24, 2024
1 parent 4d2928c commit 3d599d0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
21 changes: 8 additions & 13 deletions packages/webpack-plugin/lib/runtime/components/react/mpx-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -734,22 +734,17 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r

const viewStyle = extendObject({}, innerStyle, layoutStyle)

enableAnimation = enableAnimation || !!animation
const enableAnimationRef = useRef(enableAnimation)
if (enableAnimationRef.current !== enableAnimation) {
error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.')
}
const finalStyle = enableAnimationRef.current
? [viewStyle, useAnimationHooks({
animation,
style: viewStyle
})]
: viewStyle
const { enableStyleAnimation, animationStyle } = useAnimationHooks({
enableAnimation,
animation,
style: viewStyle
})

const innerProps = useInnerProps(
props,
extendObject({
ref: nodeRef,
style: finalStyle
style: enableStyleAnimation ? [viewStyle, animationStyle] : viewStyle
},
layoutProps
), [
Expand All @@ -773,7 +768,7 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
})

const BaseComponent = enableAnimation
? createElement(Animated.View, extendObject({}, innerProps, { style: finalStyle }), childNode)
? createElement(Animated.View, innerProps, childNode)
: createElement(View, innerProps, childNode)

return enableHoverStyle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
WithTimingConfig,
AnimationCallback
} from 'react-native-reanimated'
import { error } from '@mpxjs/utils'
import { ExtendedViewStyle } from './types/common'
import type { _ViewProps } from './mpx-view'

Expand Down Expand Up @@ -188,8 +189,17 @@ const formatStyle = (style: ExtendedViewStyle): ExtendedViewStyle => {
})
}

export default function useAnimationHooks<T, P> (props: _ViewProps) {
const { style = {}, animation } = props
export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAnimation?: boolean }) {
const { style = {}, animation, enableAnimation } = props

const enableStyleAnimation = enableAnimation || !!animation
const enableAnimationRef = useRef(enableStyleAnimation)
if (enableAnimationRef.current !== enableStyleAnimation) {
error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.')
}

if (!enableStyleAnimation) return { enableStyleAnimation }

const originalStyle = formatStyle(style)
// id 标识
const id = animation?.id || -1
Expand Down Expand Up @@ -358,7 +368,7 @@ export default function useAnimationHooks<T, P> (props: _ViewProps) {
}, {} as { [propName: string]: string | number })
}
// ** 生成动画样式
return useAnimatedStyle(() => {
const animationStyle = useAnimatedStyle(() => {
// console.info(`useAnimatedStyle styles=`, originalStyle)
return animatedStyleKeys.value.reduce((styles, key) => {
// console.info('getAnimationStyles', key, shareValMap[key].value)
Expand All @@ -376,4 +386,9 @@ export default function useAnimationHooks<T, P> (props: _ViewProps) {
return styles
}, {} as ExtendedViewStyle)
})

return {
animationStyle,
enableStyleAnimation
}
}

0 comments on commit 3d599d0

Please sign in to comment.