diff --git a/framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java b/framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java index 927a40945db..80618c83ed5 100644 --- a/framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java +++ b/framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java @@ -231,6 +231,22 @@ public void onFirstViewAdded() { } } + @Override + public void onSizeChanged(int rootId, int w, int h, int ow, int oh) { + if (mEngineContext != null) { + HippyModuleManager manager = mEngineContext.getModuleManager(); + if (manager != null) { + HippyMap hippyMap = new HippyMap(); + hippyMap.pushDouble("width", PixelUtil.px2dp(w)); + hippyMap.pushDouble("height", PixelUtil.px2dp(h)); + hippyMap.pushDouble("oldWidth", PixelUtil.px2dp(ow)); + hippyMap.pushDouble("oldHeight", PixelUtil.px2dp(oh)); + manager.getJavaScriptModule(EventDispatcher.class) + .receiveNativeEvent("onSizeChanged", hippyMap); + } + } + } + @Override public void updateDimension(int width, int height, boolean shouldUseScreenDisplay, boolean systemUiVisibilityChanged) { 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 6d3190ad8cf..172900ead5a 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 @@ -23,6 +23,7 @@ import android.view.ViewTreeObserver; import android.widget.FrameLayout; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.tencent.mtt.hippy.dom.node.NodeProps; @@ -84,14 +85,12 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { } @Override - protected void onSizeChanged(int w, int h, int oldw, int oldh) { - super.onSizeChanged(w, h, oldw, oldh); - if (w != oldw || h != oldh) { - getGlobalLayoutListener().checkUpdateDimension(w, h, false, false); - NativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(getContext()); - if (nativeRenderer != null) { - nativeRenderer.onSizeChanged(getId(), w, h); - } + protected void onSizeChanged(int w, int h, int ow, int oh) { + super.onSizeChanged(w, h, ow, oh); + NativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(getContext()); + if ((w != ow || h != oh) && nativeRenderer != null) { + nativeRenderer.updateDimension(w, h, false, false); + nativeRenderer.onSizeChanged(getId(), w, h, ow, oh); } } @@ -156,14 +155,9 @@ private void sendOrientationChangeEvent(int orientation) { private void checkUpdateDimension(boolean shouldUseScreenDisplay, boolean systemUiVisibilityChanged) { - checkUpdateDimension(-1, -1, shouldUseScreenDisplay, systemUiVisibilityChanged); - } - - private void checkUpdateDimension(int width, int height, boolean shouldUseScreenDisplay, - boolean systemUiVisibilityChanged) { NativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(getContext()); if (nativeRenderer != null) { - nativeRenderer.updateDimension(width, height, shouldUseScreenDisplay, + nativeRenderer.updateDimension(-1, -1, shouldUseScreenDisplay, systemUiVisibilityChanged); } } diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/FrameworkProxy.java b/renderer/native/android/src/main/java/com/tencent/renderer/FrameworkProxy.java index 70e082fc61d..c9557957d04 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/FrameworkProxy.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/FrameworkProxy.java @@ -51,4 +51,6 @@ public interface FrameworkProxy { void updateDimension(int width, int height, boolean shouldUseScreenDisplay, boolean systemUiVisibilityChanged); + + void onSizeChanged(int rootId, int w, int h, int ow, int oh); } diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRender.java b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRender.java index 28362919b3a..b0671b18669 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRender.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRender.java @@ -93,7 +93,7 @@ VirtualNode createVirtualNode(int rootId, int id, int pid, int index, @NonNull S void onFirstViewAdded(); - void onSizeChanged(int rootId, int width, int height); + void onSizeChanged(int rootId, int width, int height, int oldWidth, int oldHeight); void onSizeChanged(int rootId, int nodeId, int width, int height, boolean isSync); diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java index d8dc78ec43a..8d598e96c88 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java @@ -351,11 +351,18 @@ public void onRuntimeInitialized(final int rootId) { }); } - @Override - public void onSizeChanged(int rootId, int w, int h) { + private void onSizeChanged(int rootId, int w, int h) { mRenderProvider.onSizeChanged(rootId, w, h); } + @Override + public void onSizeChanged(int rootId, int w, int h, int ow, int oh) { + if (mFrameworkProxy != null) { + mFrameworkProxy.onSizeChanged(rootId, w, h, ow, oh); + } + onSizeChanged(rootId, w, h); + } + @Override public void onSizeChanged(int rootId, int nodeId, int width, int height, boolean isSync) { mRenderProvider.onSizeChanged(rootId, nodeId, width, height, isSync);