Skip to content

Commit

Permalink
feat(Utils): support Horizontal Screen (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZengBeauty authored Aug 10, 2021
1 parent 6cb9c65 commit 333292b
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions packages/tuya-panel-utils/src/ratio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ const getDimension = () => {
*/
export default {
get hRatio(): number {
const { width: actualWidth } = getDimension();
const { width: actualWidth, height: actualHeight } = getDimension();
if (actualWidth > actualHeight) {
return actualWidth / baseHeight;
}
return actualWidth / baseWidth;
},
get vRatio(): number {
const { height: actualHeight } = getDimension();
const { width: actualWidth, height: actualHeight } = getDimension();
if (actualWidth > actualHeight) {
return actualHeight / baseWidth;
}
return actualHeight / baseHeight;
},
get ratio(): number {
Expand Down Expand Up @@ -84,13 +90,23 @@ export default {
return getDimension().height - (isIos ? (isIphoneX ? 88 : 64) : 56 + statusHeight);
},
convertX: (number: number): number => {
const { width: actualWidth } = getDimension();
const hRatio = actualWidth / baseWidth;
const { width: actualWidth, height: actualHeight } = getDimension();
let hRatio = 0;
if (actualWidth > actualHeight) {
hRatio = actualWidth / baseHeight;
} else {
hRatio = actualWidth / baseWidth;
}
return number * hRatio;
},
convertY: (number: number): number => {
const { height: actualHeight } = getDimension();
const vRatio = actualHeight / baseHeight;
const { width: actualWidth, height: actualHeight } = getDimension();
let vRatio = 0;
if (actualWidth > actualHeight) {
vRatio = actualHeight / baseWidth;
} else {
vRatio = actualHeight / baseHeight;
}
return number * vRatio;
},
convert: (number: number): number => {
Expand Down

0 comments on commit 333292b

Please sign in to comment.