Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-huxiyang committed Nov 11, 2024
1 parent 8987e52 commit bbe11b4
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 54 deletions.
3 changes: 1 addition & 2 deletions src/packages/image/demos/taro/demo1.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from 'react'
import { Image } from '@nutui/nutui-react-taro'
import pxTransform from '@/utils/px-transform'

const Demo1 = () => {
const src =
'https://storage.360buyimg.com/imgtools/e067cd5b69-07c864c0-dd02-11ed-8b2c-d7f58b17086a.png'
return (
<>
<Image src={src} height={pxTransform(200)} />
<Image src={src} height={200} />
</>
)
}
Expand Down
18 changes: 9 additions & 9 deletions src/packages/image/demos/taro/demo2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ const Demo2 = () => {
<Image
src={src}
mode="aspectFit"
width={pxTransform(80)}
height={pxTransform(80)}
radius={pxTransform(40)}
width={80}
height={80}
radius={40}
/>
</View>
<View style={{ width: pxTransform(98) }}>
<Image
src={src}
mode="scaleToFill"
width={pxTransform(80)}
height={pxTransform(80)}
radius={pxTransform(40)}
width={80}
height={80}
radius={40}
/>
</View>
<View style={{ width: pxTransform(98) }}>
<Image
src={src}
mode="scaleToFill"
width={pxTransform(80)}
height={pxTransform(80)}
radius={pxTransform(10)}
width={80}
height={80}
radius={10}
/>
</View>
</View>
Expand Down
6 changes: 3 additions & 3 deletions src/packages/image/demos/taro/demo3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const Demo3 = () => {
<>
<View style={{ display: 'flex', flexWrap: 'wrap' }}>
<View style={{ width: pxTransform(98) }}>
<Image width={pxTransform(80)} height={pxTransform(80)} />
<Image width={80} height={80} />
<View style={imageText}>默认</View>
</View>
<View style={{ width: pxTransform(98) }}>
<Image
width={pxTransform(80)}
height={pxTransform(80)}
width={80}
height={80}
loading={<Loading className="nut-icon-loading" />}
/>
<View style={imageText}>自定义</View>
Expand Down
13 changes: 2 additions & 11 deletions src/packages/image/demos/taro/demo4.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,11 @@ const Demo4 = () => {
<>
<View style={{ display: 'flex', flexWrap: 'wrap' }}>
<View style={{ width: pxTransform(98) }}>
<Image
src="https://x"
width={pxTransform(80)}
height={pxTransform(80)}
/>
<Image src="https://x" width={80} height={80} />
<View style={imageText}>默认</View>
</View>
<View style={{ width: pxTransform(98) }}>
<Image
src="https://x"
width={pxTransform(80)}
height={pxTransform(80)}
error={<Failure />}
/>
<Image src="https://x" width={80} height={80} error={<Failure />} />
<View style={imageText}>自定义</View>
</View>
</View>
Expand Down
4 changes: 2 additions & 2 deletions src/packages/image/demos/taro/demo5.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const Demo5 = () => {
<>
<Image
src="http://m.360buyimg.com/babel/s181x181_jfs/t1/210178/19/10205/31538/619bbcd9E5071aed5/8e1b7eb632aeed49.png"
width={pxTransform(30)}
height={pxTransform(30)}
width={30}
height={30}
/>
<View
style={{
Expand Down
7 changes: 1 addition & 6 deletions src/packages/image/demos/taro/demo6.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ const Demo6 = () => {
}}
key={mode}
>
<Image
src={src}
mode={mode as any}
width={pxTransform(80)}
height={pxTransform(80)}
/>
<Image src={src} mode={mode as any} width={80} height={80} />
</View>
)
})}
Expand Down
7 changes: 1 addition & 6 deletions src/packages/image/demos/taro/demo7.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ const Demo7 = () => {
}}
key={mode}
>
<Image
src={src}
mode={mode as any}
width={pxTransform(80)}
height={pxTransform(80)}
/>
<Image src={src} mode={mode as any} width={80} height={80} />
</View>
)
})}
Expand Down
19 changes: 4 additions & 15 deletions src/packages/image/image.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { Image as ImageIcon, ImageError } from '@nutui/icons-react-taro'
import classNames from 'classnames'
import { BaseEventOrig } from '@tarojs/components/types/common'
import pxTransform from '@/utils/px-transform'

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

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

// 图片加载
Expand All @@ -68,21 +69,9 @@ export const Image: FunctionComponent<Partial<ImageProps>> = (props) => {

const containerStyle = {
// eslint-disable-next-line no-nested-ternary
height: height
? Taro.getEnv() === 'RN'
? height
: pxCheck(height)
: Taro.getEnv() === 'WEB'
? ''
: '100%',
height: height ? pxCheck(height) : Taro.getEnv() === 'WEB' ? '' : '100%',
// eslint-disable-next-line no-nested-ternary
width: width
? Taro.getEnv() === 'RN'
? width
: pxCheck(width)
: Taro.getEnv() === 'WEB'
? ''
: '100%',
width: width ? pxCheck(width) : Taro.getEnv() === 'WEB' ? '' : '100%',
overflow: radius !== undefined && radius !== null ? 'hidden' : '',
borderRadius:
// eslint-disable-next-line no-nested-ternary
Expand Down

0 comments on commit bbe11b4

Please sign in to comment.