Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): onGlobalLayout use root view size #3982

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading