Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Utils): support Horizontal Screen #112

Merged
merged 1 commit into from
Aug 10, 2021
Merged
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
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