Skip to content

Commit ffd80b1

Browse files
committed
fix: 修复 pxTransform 问题
1 parent a455447 commit ffd80b1

File tree

9 files changed

+33
-29
lines changed

9 files changed

+33
-29
lines changed

src/common/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,13 @@ function handleTouchScroll(flag: any): void {
216216

217217
function pxTransform(size: number): string {
218218
if (!size) return ''
219-
return Taro.pxTransform(size)
219+
const designWidth = 750
220+
const deviceRatio = {
221+
640: 2.34 / 2,
222+
750: 1,
223+
828: 1.81 / 2
224+
}
225+
return `${size / deviceRatio[designWidth]}rpx`
220226
}
221227

222228
function objectToString(style: object | string): string {

src/components/divider/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import PropTypes, { InferProps } from 'prop-types'
33
import React from 'react'
44
import { AtDividerProps } from 'types/divider'
55
import { View } from '@tarojs/components'
6-
import Taro from '@tarojs/taro'
7-
import { mergeStyle } from '../../common/utils'
6+
import { mergeStyle, pxTransform } from '../../common/utils'
87

98
export default class AtDivider extends React.Component<AtDividerProps> {
109
public static defaultProps: AtDividerProps
@@ -22,12 +21,12 @@ export default class AtDivider extends React.Component<AtDividerProps> {
2221
} = this.props
2322

2423
const rootStyle = {
25-
height: height ? `${Taro.pxTransform(Number(height))}` : ''
24+
height: height ? `${pxTransform(Number(height))}` : ''
2625
}
2726

2827
const fontStyle = {
2928
color: fontColor,
30-
'font-size': fontSize ? `${Taro.pxTransform(Number(fontSize))}` : ''
29+
'font-size': fontSize ? `${pxTransform(Number(fontSize))}` : ''
3130
}
3231

3332
const lineStyle: React.CSSProperties = {

src/components/icon/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import PropTypes, { InferProps } from 'prop-types'
33
import React from 'react'
44
import { AtIconProps } from 'types/icon'
55
import { Text } from '@tarojs/components'
6-
import Taro from '@tarojs/taro'
7-
import { mergeStyle } from '../../common/utils'
6+
import { mergeStyle, pxTransform } from '../../common/utils'
87

98
export default class AtIcon extends React.Component<AtIconProps> {
109
public static defaultProps: AtIconProps
@@ -25,7 +24,7 @@ export default class AtIcon extends React.Component<AtIconProps> {
2524
} = this.props
2625

2726
const rootStyle = {
28-
fontSize: `${Taro.pxTransform(parseInt(String(size)) * 2)}`,
27+
fontSize: `${pxTransform(parseInt(String(size)) * 2)}`,
2928
color
3029
}
3130

src/components/indexes/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import { AtIndexesProps, AtIndexesState, Item } from 'types/indexes'
66
import { ScrollView, View } from '@tarojs/components'
77
import { CommonEvent, ITouchEvent } from '@tarojs/components/types/common'
88
import Taro from '@tarojs/taro'
9-
import { delayQuerySelector, isTest, uuid } from '../../common/utils'
9+
import {
10+
delayQuerySelector,
11+
isTest,
12+
uuid,
13+
pxTransform
14+
} from '../../common/utils'
1015
import AtList from '../list/index'
1116
import AtListItem from '../list/item/index'
1217
import AtToast from '../toast/index'
@@ -176,7 +181,7 @@ export default class AtIndexes extends React.Component<
176181
isWEB
177182
} = this.state
178183

179-
const toastStyle = { minWidth: Taro.pxTransform(100) }
184+
const toastStyle = { minWidth: pxTransform(100) }
180185
const rootCls = classNames('at-indexes', className)
181186

182187
const menuList = list.map((dataList, i) => {

src/components/input-number/index.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import React from 'react'
55
import { AtInputNumberProps, InputError } from 'types/input-number'
66
import { Input, Text, View } from '@tarojs/components'
77
import { CommonEvent, ITouchEvent } from '@tarojs/components/types/common'
8-
import Taro from '@tarojs/taro'
9-
import { initTestEnv } from '../../common/utils'
8+
import { pxTransform } from '../../common/utils'
109

1110
// TODO: Check all types
1211

@@ -39,8 +38,6 @@ function parseValue(num: string): string {
3938
return _toString(num)
4039
}
4140

42-
initTestEnv()
43-
4441
type ExtendEvent = {
4542
target: {
4643
value: string | number
@@ -100,7 +97,7 @@ export default class AtInputNumber extends React.Component<AtInputNumberProps> {
10097

10198
this.handleError({
10299
type: 'OVER',
103-
errorValue: resultValue!
100+
errorValue: resultValue
104101
})
105102
}
106103

@@ -143,7 +140,7 @@ export default class AtInputNumber extends React.Component<AtInputNumberProps> {
143140
} = this.props
144141

145142
const inputStyle = {
146-
width: width ? `${Taro.pxTransform(width)}` : ''
143+
width: width ? `${pxTransform(width)}` : ''
147144
}
148145
const inputValue = Number(this.handleValue(value))
149146
const rootCls = classNames(

src/components/loading/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PropTypes, { InferProps } from 'prop-types'
22
import React from 'react'
33
import { View } from '@tarojs/components'
4-
import Taro from '@tarojs/taro'
4+
import { pxTransform } from '../../common/utils'
55

66
interface AtLoadingProps {
77
size?: string | number
@@ -16,8 +16,8 @@ export default class AtLoading extends React.Component<AtLoadingProps> {
1616
const { color, size } = this.props
1717
const loadingSize = typeof size === 'string' ? size : String(size)
1818
const sizeStyle = {
19-
width: size ? `${Taro.pxTransform(parseInt(loadingSize))}` : '',
20-
height: size ? `${Taro.pxTransform(parseInt(loadingSize))}` : ''
19+
width: size ? `${pxTransform(parseInt(loadingSize))}` : '',
20+
height: size ? `${pxTransform(parseInt(loadingSize))}` : ''
2121
}
2222
const colorStyle = {
2323
border: color ? `1px solid ${color}` : '',

src/components/nav-bar/index.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import React from 'react'
55
import { AtNavBarProps } from 'types/nav-bar'
66
import { Text, View } from '@tarojs/components'
77
import { ITouchEvent } from '@tarojs/components/types/common'
8-
import Taro from '@tarojs/taro'
9-
import { mergeStyle } from '../../common/utils'
8+
import { mergeStyle, pxTransform } from '../../common/utils'
109

1110
export default class AtNavBar extends React.Component<AtNavBarProps> {
1211
public static defaultProps: AtNavBarProps
@@ -104,7 +103,7 @@ export default class AtNavBar extends React.Component<AtNavBarProps> {
104103
style={mergeStyle(
105104
{
106105
color: leftIconInfo.color,
107-
fontSize: `${Taro.pxTransform(
106+
fontSize: `${pxTransform(
108107
parseInt(leftIconInfo.size.toString()) * 2
109108
)}`
110109
},
@@ -132,7 +131,7 @@ export default class AtNavBar extends React.Component<AtNavBarProps> {
132131
style={mergeStyle(
133132
{
134133
color: rightSecondIconInfo.color,
135-
fontSize: `${Taro.pxTransform(
134+
fontSize: `${pxTransform(
136135
parseInt(rightSecondIconInfo.size.toString()) * 2
137136
)}`
138137
},
@@ -155,7 +154,7 @@ export default class AtNavBar extends React.Component<AtNavBarProps> {
155154
style={mergeStyle(
156155
{
157156
color: rightFirstIconInfo.color,
158-
fontSize: `${Taro.pxTransform(
157+
fontSize: `${pxTransform(
159158
parseInt(rightFirstIconInfo.size.toString()) * 2
160159
)}`
161160
},

src/components/rate/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from 'react'
44
import { AtRateProps } from 'types/rate'
55
import { Text, View } from '@tarojs/components'
66
import { CommonEvent } from '@tarojs/components/types/common'
7-
import Taro from '@tarojs/taro'
7+
import { pxTransform } from '../../common/utils'
88

99
export default class AtRate extends React.Component<AtRateProps> {
1010
public static defaultProps: AtRateProps
@@ -25,7 +25,7 @@ export default class AtRate extends React.Component<AtRateProps> {
2525
} = this.props
2626

2727
const iconStyle = {
28-
marginRight: Taro.pxTransform(margin)
28+
marginRight: pxTransform(margin)
2929
}
3030
const starIconStyle = {
3131
fontSize: size ? `${size}px` : ''

src/components/textarea/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AtTextareaProps } from 'types/textarea'
55
import { Textarea, View } from '@tarojs/components'
66
import { CommonEvent } from '@tarojs/components/types/common'
77
import Taro from '@tarojs/taro'
8+
import { pxTransform } from '../../common/utils'
89

910
type ExtendEvent = {
1011
target: {
@@ -72,9 +73,7 @@ export default class AtTextarea extends React.Component<AtTextareaProps> {
7273

7374
const _maxLength = parseInt(maxLength.toString())
7475
const actualMaxLength = getMaxLength(_maxLength, textOverflowForbidden)
75-
const textareaStyle = height
76-
? `height:${Taro.pxTransform(Number(height))}`
77-
: ''
76+
const textareaStyle = height ? `height:${pxTransform(Number(height))}` : ''
7877
const rootCls = classNames(
7978
'at-textarea',
8079
`at-textarea--${ENV}`,

0 commit comments

Comments
 (0)