@react-native-ohos/react-native-unistyles
Version:
Level up your React Native StyleSheet
50 lines (40 loc) • 1.37 kB
text/typescript
/*
* Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
* Use of this source code is governed by a MIT license that can be
* found in the LICENSE file.
*/
import common from '@ohos.app.ability.common';
import { SafeAreaInsets } from '@rnoh/react-native-openharmony/ts';
export class UnistylesInsets {
insets :Insets;
constructor(context: common.UIAbilityContext,insets: SafeAreaInsets,scale:number) {
this.insets = new Insets(insets.top,insets.bottom,insets.left,insets.right);
this.density = scale;
}
private density: number;
get() {
return this.getCurrentInsets();
}
getCurrentInsets() {
let topInset = this.insets.top/this.density //状态栏
let bottomInset = this.insets.bottom/this.density//导航栏
let leftInset = this.insets.left/this.density//
let rightInset = this.insets.right/this.density//
return new Insets(topInset, bottomInset, leftInset, rightInset)
}
}
export class Insets{
top:number;
bottom:number;
left:number;
right:number;
constructor(topInset: number, bottomInset: number, leftInset: number, rightInset: number) {
this.top = topInset;
this.bottom = bottomInset;
this.left = leftInset;
this.right = rightInset;
}
isEqual(b:Insets){
return this.top == b.top && this.bottom == b.bottom && this.left == b.left && this.right == b.right;
}
}