From cf0d3992b234f3f95295b1ff96813e88052eb962 Mon Sep 17 00:00:00 2001 From: maxli Date: Tue, 6 Aug 2024 11:51:31 +0800 Subject: [PATCH] fix(android): onGlobalLayout use root view size --- .../com/tencent/mtt/hippy/utils/TimeMonitor.java | 4 ++-- .../java/com/tencent/mtt/hippy/HippyRootView.java | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/TimeMonitor.java b/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/TimeMonitor.java index ab0a338b10a..fa3673120dc 100644 --- a/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/TimeMonitor.java +++ b/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/TimeMonitor.java @@ -157,9 +157,9 @@ void end() { void print() { if (mMonitorPoints != null) { - LogUtils.i(TAG, "group " + name + ", totalTime " + totalTime + "ms"); + LogUtils.e(TAG, "group " + name + ", totalTime " + totalTime + "ms"); for (MonitorPoint monitorPoint : mMonitorPoints) { - LogUtils.i(TAG, + LogUtils.e(TAG, monitorPoint.key + ": " + (monitorPoint.endTime - monitorPoint.startTime) + "ms"); } diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/HippyRootView.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/HippyRootView.java index 23a1cb21eff..585aa321c64 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/HippyRootView.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/HippyRootView.java @@ -34,6 +34,7 @@ import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.NativeRendererManager; +import java.lang.ref.WeakReference; import java.util.Map; import static android.content.res.Configuration.ORIENTATION_UNDEFINED; @@ -116,7 +117,7 @@ protected void onDetachedFromWindow() { private GlobalLayoutListener getGlobalLayoutListener() { if (mGlobalLayoutListener == null) { - mGlobalLayoutListener = new GlobalLayoutListener(); + mGlobalLayoutListener = new GlobalLayoutListener(this); } return mGlobalLayoutListener; } @@ -124,6 +125,11 @@ private GlobalLayoutListener getGlobalLayoutListener() { private class GlobalLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener { private int mOrientation = ORIENTATION_UNDEFINED; + private final WeakReference mRootViewRef; + + GlobalLayoutListener(View rootView) { + mRootViewRef = new WeakReference<>(rootView); + } @Override public void onGlobalLayout() { @@ -137,7 +143,10 @@ public void onGlobalLayout() { sendOrientationChangeEvent(mOrientation); NativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(context); if (nativeRenderer != null) { - nativeRenderer.updateDimension(-1, -1); + View rootView = mRootViewRef.get(); + int width = (rootView != null) ? rootView.getWidth() : -1; + int height = (rootView != null) ? rootView.getHeight() : -1; + nativeRenderer.updateDimension(width, height); } } }