Skip to content

Commit

Permalink
feat(ohos): c api - fix image tintColor & screenSize
Browse files Browse the repository at this point in the history
  • Loading branch information
tandyyan committed Jun 13, 2024
1 parent 1227e91 commit f8f05b1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,14 @@ ImageNode &ImageNode::SetTintColor(uint32_t sharedColor) {
return *this;
}
cssTintColor_.clear();
int32_t red = (sharedColor >> 16) & 0xff;
int32_t green = (sharedColor >> 8) & 0xff;
int32_t blue = sharedColor & 0xff;
int32_t alpha = (sharedColor >> 24) &0xff;
uint32_t colorValue = sharedColor;
if (colorValue >> 24 == 0) {
colorValue |= ((uint32_t)0xff << 24);
}
int32_t alpha = colorValue & 0xff;
int32_t red = (colorValue >> 8) & 0xff;
int32_t green = (colorValue >> 16) & 0xff;
int32_t blue = (colorValue >> 24) &0xff;
cssTintColor_.push_back(red);
cssTintColor_.push_back(green);
cssTintColor_.push_back(blue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export struct HippyRoot {
hippyEngine: HippyEngine | null = null
pagerName: string = ""
pagerData: HippyRecord = {}
initViewSize: HRSize = HRConvertUtil.screenSize()
initViewSize: HRSize = HRConvertUtil.getScreenSize()
onRenderException: ((exception: HippyException) => void) | null = null
private readonly ROOT_VIEW_ID_INCREMENT = 10
private static sRootIdCounter = 0
Expand Down
26 changes: 16 additions & 10 deletions framework/ohos/src/main/ets/renderer_native/utils/HRConvertUtil.ets
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import { HRValueUtils } from './HRValueUtils'
import { LogUtils } from '../../support/utils/LogUtils'

export class HRConvertUtil {
private static screenSize: HRSize = new HRSize(0, 0);

static toBorderStyle(cssString: string): BorderStyle | undefined {
if (cssString == 'solid') {
return BorderStyle.Solid
Expand Down Expand Up @@ -265,17 +267,21 @@ export class HRConvertUtil {
return HRConvertUtil.toColorWithNumber(rgbValue + opacityValue)
}

public static screenSize(): HRSize {
let width = 0
let height = 0

try {
const displayRes = display.getDefaultDisplaySync()
width = displayRes.width
height = displayRes.height
} catch (e) {
public static getScreenSize(): HRSize {
if (HRConvertUtil.screenSize.width > 0 && HRConvertUtil.screenSize.height > 0) {
return HRConvertUtil.screenSize;
} else {
let width = 0
let height = 0
try {
const displayRes = display.getDefaultDisplaySync()
width = displayRes.width
height = displayRes.height
} catch (e) {
}
HRConvertUtil.screenSize = new HRSize(px2vp(width) , px2vp(height));
return HRConvertUtil.screenSize
}
return new HRSize(px2vp(width) , px2vp(height))
}

public static statusBarHeight(avoidArea: window.AvoidArea | null) {
Expand Down

0 comments on commit f8f05b1

Please sign in to comment.