Skip to content

Commit

Permalink
feat: extend object
Browse files Browse the repository at this point in the history
  • Loading branch information
WX-DongXing committed Dec 9, 2024
1 parent 020463e commit 7a3cb8a
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions packages/webpack-plugin/lib/runtime/components/react/mpx-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { noop } from '@mpxjs/utils'
import { SvgCssUri } from 'react-native-svg/css'
import useInnerProps, { getCustomEvent } from './getInnerListeners'
import useNodesRef, { HandlerRef } from './useNodesRef'
import { SVG_REGEXP, useLayout, useTransformStyle, renderImage } from './utils'
import { SVG_REGEXP, useLayout, useTransformStyle, renderImage, extendObject } from './utils'

export type Mode =
| 'scaleToFill'
Expand Down Expand Up @@ -123,11 +123,12 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
height: DEFAULT_IMAGE_HEIGHT
}

const styleObj = {
...defaultStyle,
...style,
overflow: 'hidden'
}
const styleObj = extendObject(
{},
defaultStyle,
style,
{ overflow: 'hidden' }
)

const state = useRef<ImageState>({})

Expand Down Expand Up @@ -365,8 +366,8 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
: isHeightFixMode
? state.current.viewHeight
: state.current.viewWidth && state.current.viewHeight) {
setViewWidth(state.current.viewWidth)
setViewHeight(state.current.viewHeight)
state.current.viewWidth && setViewWidth(state.current.viewWidth)
state.current.viewHeight && setViewHeight(state.current.viewHeight)
setRatio(!width ? 0 : height / width)
setImageWidth(width)
setImageHeight(height)
Expand All @@ -379,17 +380,24 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re

const innerProps = useInnerProps(
props,
{
ref: nodeRef,
style: {
...normalStyle,
...layoutStyle,
...(isHeightFixMode && { width: fixedWidth }),
...(isWidthFixMode && { height: fixedHeight })
extendObject(
{
ref: nodeRef,
style: extendObject(
{},
normalStyle,
layoutStyle,
isHeightFixMode ? { width: fixedWidth } : {},
isWidthFixMode ? { height: fixedHeight } : {}
)
},
...layoutProps
},
[],
layoutProps
),
[
'src',
'mode',
'svg'
],
{
layoutRef
}
Expand All @@ -403,22 +411,24 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
uri={src}
onLayout={onSvgLoad}
onError={binderror && onSvgError}
style={{
transformOrigin: 'top left',
...modeStyle
}}
style={extendObject(
{ transformOrigin: 'top left' },
modeStyle
)}
/>
: loaded && renderImage({
source: { uri: src },
resizeMode: resizeMode,
onLoad: bindload && onImageLoad,
onError: binderror && onImageError,
style: {
transformOrigin: 'top left',
width: isCropMode ? imageWidth : '100%',
height: isCropMode ? imageHeight : '100%',
...(isCropMode && modeStyle)
}
style: extendObject(
{
transformOrigin: 'top left',
width: isCropMode ? imageWidth : '100%',
height: isCropMode ? imageHeight : '100%'
},
isCropMode ? modeStyle : {}
)
}, enableFastImage)
}
</View>
Expand Down

0 comments on commit 7a3cb8a

Please sign in to comment.