Skip to content

Commit

Permalink
fix(android): onGlobalLayout use root view size (#3982)
Browse files Browse the repository at this point in the history
Co-authored-by: maxli <maxli@tencent.com>
  • Loading branch information
siguangli and siguangli2018 committed Aug 6, 2024
1 parent 221358d commit e390c33
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,14 +117,19 @@ protected void onDetachedFromWindow() {

private GlobalLayoutListener getGlobalLayoutListener() {
if (mGlobalLayoutListener == null) {
mGlobalLayoutListener = new GlobalLayoutListener();
mGlobalLayoutListener = new GlobalLayoutListener(this);
}
return mGlobalLayoutListener;
}

private class GlobalLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener {

private int mOrientation = ORIENTATION_UNDEFINED;
private final WeakReference<View> mRootViewRef;

GlobalLayoutListener(View rootView) {
mRootViewRef = new WeakReference<>(rootView);
}

@Override
public void onGlobalLayout() {
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit e390c33

Please sign in to comment.