Skip to content

Commit 791ce00

Browse files
committed
fix(ohos): adapt for pad density change condition
1 parent a52d4a1 commit 791ce00

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

framework/ohos/src/main/cpp/impl/renderer/native/src/text_measure/text_measurer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,8 @@ OhMeasureResult TextMeasurer::EndMeasure(int width, int widthMode, int height, i
582582

583583
OH_Drawing_TypographyLayout(typography_, maxWidth);
584584

585-
// MATE 60, beta5, "新品" "商店" text cannot be fully displayed. So add 0.5.
586-
ret.width = ceil(OH_Drawing_TypographyGetLongestLine(typography_) + paddingWidthReduce + 0.5 * density);
585+
// MATE 60, beta5, "新品" "商店" text cannot be fully displayed. So add 0.5+.
586+
ret.width = ceil(OH_Drawing_TypographyGetLongestLine(typography_) + paddingWidthReduce + 0.9 * density);
587587
double drawResultHeight = OH_Drawing_TypographyGetHeight(typography_);
588588
ret.height = drawResultHeight;
589589
ret.isEllipsized = OH_Drawing_TypographyDidExceedMaxLines(typography_);

framework/ohos/src/main/ets/hippy_framework/HippyEngine.ets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* limitations under the License.
1919
*/
2020
import { HippyLibrary } from '../hippy_library/HippyLibrary';
21+
import { PixelUtil } from "../support/utils/PixelUtil";
2122
import { NativeRenderContext } from '../renderer_native/NativeRenderContext';
2223
import { NativeRenderProvider } from '../renderer_native/NativeRenderProvider';
2324
import { HippyAny, HippyMap } from '../support/common/HippyTypes';
@@ -93,6 +94,7 @@ export interface HippyEngine {
9394

9495
export function createHippyEngine(params: EngineInitParams): HippyEngine {
9596
params.check()
97+
PixelUtil.doInitDensity()
9698
LogUtils.enableDebugLog(params.enableLog)
9799
params.libHippy?.Setting_SetFlags(params.enableUpdateAnimLog);
98100
return new HippyEngineManagerImpl(params)

framework/ohos/src/main/ets/hippy_framework/HippyEngineManagerImpl.ets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ export class HippyEngineManagerImpl implements HippyEngine, FrameworkProxy, DevS
492492
}
493493

494494
onSizeChanged(rootId: number, w: number, h: number, ow: number, oh: number): void {
495+
// pad上切换悬浮窗时,size改变,density改变
496+
PixelUtil.updateDensity(this.libHippy)
495497
if (this.mEngineContext) {
496498
let manager = this.mEngineContext.getModuleManager();
497499
if (manager) {

framework/ohos/src/main/ets/support/utils/PixelUtil.ets

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,21 @@ export class PixelUtil {
7777
}
7878
}
7979

80+
// density要在业务加载hippy,触发调用该方法时再获取;
81+
// 不要在static时初始化,static在app启动就初始化,这时候业务可能还没加载hippy,
82+
// 在pad上悬浮窗后再加载hippy,会使用到错误的density。(pad上悬浮窗后density会变)
83+
public static doInitDensity(): void {
84+
if (!PixelUtil.densityInitted) {
85+
PixelUtil.density = vp2px(1.0) / 1.0
86+
PixelUtil.vp2pxValue = vp2px(1.0)
87+
PixelUtil.densityInitted = true;
88+
}
89+
}
90+
91+
private static densityInitted: boolean = false
8092
private static densityScale: number = 1.0
81-
private static density: number = vp2px(1.0) / 1.0
82-
private static vp2pxValue: number = vp2px(1.0)
93+
private static density: number = 1.0
94+
private static vp2pxValue: number = 1.0
8395
private static fontSizeScale: number = 1.0
8496
private static fontWeightScale: number = 1.0
8597
}

0 commit comments

Comments
 (0)