Skip to content

Commit

Permalink
fix: adjusting tablet phone styles (#14946)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqingchen committed Dec 8, 2023
1 parent 300e88f commit 484b5a3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
4 changes: 4 additions & 0 deletions packages/taro-runtime-rn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
"dependencies": {
"@tarojs/components-rn": "workspace:*",
"@tarojs/router-rn": "workspace:*",
"react-native-device-info": "~10.3.0",
"react-native-root-siblings": "^4.1.1"
},
"devDependencies": {
"@types/react-native": "^0.69.8"
},
"peerDependencies": {
"react-native-device-info": "~10.3.0"
}
}
8 changes: 7 additions & 1 deletion packages/taro-runtime-rn/src/compute.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Dimensions } from 'react-native'
import DeviceInfo from 'react-native-device-info'

import { isFunction } from './utils'

Expand All @@ -12,9 +13,14 @@ const defaultRadio = {
828: 1.81 / 2
}

let uiWidthPx = 375

if (DeviceInfo.isTablet()) {
uiWidthPx = 750
}

export function pxTransform (size: number): number {
const deviceWidthDp = Dimensions.get('window').width
const uiWidthPx = 375
const config: AppConfig = globalAny.__taroAppConfig?.appConfig || {}
const deviceRatio = config.deviceRatio || defaultRadio
const designWidth = (((input = 0) => isFunction(config.designWidth)
Expand Down
9 changes: 4 additions & 5 deletions packages/taro-runtime-rn/src/scale2dp.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Dimensions, Platform } from 'react-native'
import { Dimensions } from 'react-native'
import DeviceInfo from 'react-native-device-info'

// 一般app 只有竖屏模式,所以可以只获取一次 width
const deviceWidthDp = Dimensions.get('window').width
const deviceHeightDp = Dimensions.get('window').height
let uiWidthPx = 375

if (Platform.OS === 'ios') {
if (Platform.isPad) {
uiWidthPx = 750
}
if (DeviceInfo.isTablet()) {
uiWidthPx = 750
}

export function scalePx2dp (uiElementPx) {
Expand Down
13 changes: 11 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 484b5a3

Please sign in to comment.