Skip to content

Commit

Permalink
fix(android): send onSizeChanged message to js
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 authored and siguangli committed Oct 26, 2023
1 parent 57628bf commit 0f51c5d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0f51c5d

Please sign in to comment.