Skip to content

Commit

Permalink
fix(*): fix hover style.
Browse files Browse the repository at this point in the history
  • Loading branch information
shangqunfeng committed Dec 24, 2024
1 parent 9e58437 commit 698f805
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
36 changes: 15 additions & 21 deletions packages/webpack-plugin/lib/runtime/components/react/mpx-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ function wrapImage (imageStyle?: ExtendedViewStyle, innerStyle?: Record<string,

interface WrapChildrenConfig {
hasVarDec: boolean
enableBackground: boolean
enableBackground?: boolean
textStyle?: TextStyle
backgroundStyle?: ExtendedViewStyle
varContext?: Record<string, any>
Expand All @@ -653,6 +653,11 @@ interface WrapChildrenConfig {
}

function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, textStyle, backgroundStyle, varContext, textProps, innerStyle, enableFastImage }: WrapChildrenConfig) {
enableBackground = enableBackground || !!backgroundStyle
const enableBackgroundRef = useRef(enableBackground)
if (enableBackgroundRef.current !== enableBackground) {
error('[Mpx runtime error]: background use should be stable in the component lifecycle, or you can set [enable-background] with true.')
}
const children = wrapChildren(props, {
hasVarDec,
varContext,
Expand Down Expand Up @@ -715,12 +720,6 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r

const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)

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

const nodeRef = useRef(null)
useNodesRef<View, _ViewProps>(props, ref, nodeRef, {
style: normalStyle
Expand All @@ -734,22 +733,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 @@ -763,7 +757,7 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r

const childNode = wrapWithChildren(props, {
hasVarDec,
enableBackground: enableBackgroundRef.current,
enableBackground,
textStyle,
backgroundStyle,
varContext: varContextRef.current,
Expand All @@ -773,7 +767,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 @@ -166,8 +167,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

0 comments on commit 698f805

Please sign in to comment.