Skip to content
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

[Uploader]: 修复图片加载中或者未加载出来样式问题 #814

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions packages/core/src/image/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function useImageShape(shape?: ImageShape, round?: boolean) {
}

export interface ImageProps extends ViewProps {
wrapperClassName?: string
src?: string
alt?: string
width?: string | number
Expand All @@ -63,6 +64,7 @@ export interface ImageProps extends ViewProps {
export default function Image(props: ImageProps) {
const {
className,
wrapperClassName,
src,
alt,
width: widthProp,
Expand All @@ -86,12 +88,23 @@ export default function Image(props: ImageProps) {
const isLoadedRef = useRef(false)

const [viewStyle, imgStyle] = useMemo(() => {
const width = widthProp ? typeof widthProp === "number" ? pxTransform(widthProp) : widthProp : undefined
const height = heightProp ? typeof heightProp === "number" ? pxTransform(heightProp) : heightProp : undefined
const width = widthProp
? typeof widthProp === "number"
? pxTransform(widthProp)
: widthProp
: undefined
const height = heightProp
? typeof heightProp === "number"
? pxTransform(heightProp)
: heightProp
: undefined
const imgStyle = mergeStyle(styleProp, {})
imgStyle.width = width || imgStyle.width
imgStyle.height = height || imgStyle.height
return [{ width: imgStyle.width || "100%", height: imgStyle.height || "100%", position: "relative" }, imgStyle] as const
return [
{ width: imgStyle.width || "100%", height: imgStyle.height || "100%", position: "relative" },
imgStyle,
] as const
}, [styleProp, widthProp, heightProp])

const handleLoad = useMemoizedFn(() => {
Expand All @@ -115,10 +128,10 @@ export default function Image(props: ImageProps) {
} else {
setLoading(true)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [src])
return (
<View style={viewStyle}>
<View style={viewStyle} className={wrapperClassName}>
{!failed && src && (
<TaroImage
ref={taroImageRef}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/uploader/uploader-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function UploaderImage(props: UploaderImageProps) {
if (isImageFile({ type, url })) {
return (
<Image
wrapperClassName={prefixClassname("uploader__preview-image-wrapper")}
className={prefixClassname("uploader__preview-image")}
src={url}
mode={mode}
Expand Down
14 changes: 10 additions & 4 deletions packages/core/src/uploader/uploader.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
background: $uploader-upload-background-color;
}

&-icon {
.#{$component-prefix}uploader__upload-icon {
font-size: $uploader-upload-icon-font-size;
color: $uploader-upload-icon-color;
}
Expand All @@ -58,8 +58,14 @@

&-image {
display: block;
width: $uploader-preview-image-width;
height: $uploader-preview-image-height;
width: 100%;
height: 100%;
}

&-image-wrapper {
display: block;
width: $uploader-preview-image-width !important;
height: $uploader-preview-image-height !important;
overflow: hidden;
}

Expand All @@ -72,7 +78,7 @@
background: $uploader-remove-background-color;
border-radius: $uploader-remove-border-radius;

&-icon {
.#{$component-prefix}uploader__preview-remove-icon {
position: absolute;
top: -2px * $hd;
right: -2px * $hd;
Expand Down