Skip to content
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
1 change: 0 additions & 1 deletion packages/nutui-taro-demo-rn/scripts/taro/adapted.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ exports = module.exports = [
'configprovider',
'input',
'swipe',
'icon',
]
2 changes: 1 addition & 1 deletion src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@
"author": "swag~jun"
},
{
"version": "2.0.0",
"version": "3.0.0",
"name": "Swipe",
"type": "component",
"cName": "滑动手势",
Expand Down
13 changes: 10 additions & 3 deletions src/packages/image/image.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
import { Image as ImageIcon, ImageError } from '@nutui/icons-react-taro'
import classNames from 'classnames'
import { BaseEventOrig } from '@tarojs/components/types/common'
import { pxCheck } from '@/utils/px-check'
import { harmonyAndRn } from '@/utils/platform-taro'

export interface ImageProps extends Omit<TImageProps, 'style'> {
Expand Down Expand Up @@ -50,6 +49,10 @@ export const Image: FunctionComponent<Partial<ImageProps>> = (props) => {
const [innerLoading, setInnerLoading] = useState(true)
const [isError, setIsError] = useState(false)

const pxCheck = (value: string | number): string => {
return Number.isNaN(Number(value)) ? String(value) : `${value}px`
}

// 图片加载
const handleLoad = (e: BaseEventOrig<TImageProps.onLoadEventDetail>) => {
setIsError(false)
Expand Down Expand Up @@ -85,7 +88,11 @@ export const Image: FunctionComponent<Partial<ImageProps>> = (props) => {
overflow: radius !== undefined && radius !== null ? 'hidden' : '',
borderRadius:
// eslint-disable-next-line no-nested-ternary
radius != null ? (Taro.getEnv() === 'RN' ? radius : pxCheck(radius)) : '',
radius !== undefined && radius != null
? Taro.getEnv() === 'RN'
? radius
: pxCheck(radius)
: '',
}

const imgStyle: any = {
Expand Down Expand Up @@ -127,7 +134,7 @@ export const Image: FunctionComponent<Partial<ImageProps>> = (props) => {
<View className={classNames(classPrefix, className)} style={containerStyle}>
<TImage
{...rest}
className={`${classPrefix}-default ${className}-image`}
className={`${classPrefix}-default ${className ? `${className}-image` : ''}`}
style={imgStyle}
src={src}
onLoad={(e) => handleLoad(e)}
Expand Down
4 changes: 3 additions & 1 deletion src/packages/image/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import React, {
import { Image as ImageIcon, ImageError } from '@nutui/icons-react'
import classNames from 'classnames'
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
import { pxCheck } from '@/utils/px-check'

export interface ImageProps extends BasicComponent {
src: string
Expand Down Expand Up @@ -82,6 +81,9 @@ export const Image: FunctionComponent<
const [isError, setIsError] = useState(false)
const [complete, setComplete] = useState(false)
const imgRef = useRef<HTMLImageElement>(null)
const pxCheck = (value: string | number): string => {
return Number.isNaN(Number(value)) ? String(value) : `${value}px`
}

useEffect(() => {
if (imgRef.current && imgRef.current.complete && !lazy) {
Expand Down