Skip to content

Commit

Permalink
fix(android): elements page screencast at first msg
Browse files Browse the repository at this point in the history
  • Loading branch information
lavnFan authored and zoomchan-cxj committed Apr 27, 2022
1 parent 06a1d35 commit f9059d1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,11 @@ String getGlobalConfigs() {

globalParams.pushMap("Platform", platformParams);

HippyMap debugParams = new HippyMap();
debugParams.pushString("debugClientId", mContext.getDevSupportManager().getDebugInstanceId());
globalParams.pushMap("Debug", debugParams);
if (mContext.getDevSupportManager().isSupportDev()) {
HippyMap debugParams = new HippyMap();
debugParams.pushString("debugClientId", mContext.getDevSupportManager().getDebugInstanceId());
globalParams.pushMap("Debug", debugParams);
}

HippyMap tkd = new HippyMap();
tkd.pushString("url", (pageUrl == null) ? "" : pageUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class PageDomain extends InspectorDomain implements Handler.Callback, Pag
private static final int MSG_SCREEN_CAST_ACK = 0x02;

private static final long FRAME_CALLBACK_INTERVAL = 1000L;
private static final long DELAY_FOR_FRAME_UPDATE = 100L;
private static final long DELAY_FOR_FRAME_UPDATE = 200L;

public static final String BUNDLE_KEY_PARAM = "params";

Expand Down Expand Up @@ -169,10 +169,12 @@ public void onFrameUpdate() {
}
if (context != null && mHandlerThread != null && mLastSessionId != -1) {
Handler hander = mHandlerThread.getHandler();
if (hander.hasMessages(MSG_SCREEN_CAST_ACK)) {
return;
}
Message msg = hander.obtainMessage(MSG_SCREEN_CAST_ACK);
msg.obj = context;
msg.arg1 = mLastSessionId;
hander.removeMessages(MSG_SCREEN_CAST_ACK);
hander.sendMessageDelayed(msg, DELAY_FOR_FRAME_UPDATE);
mIsFrameUpdate = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class PageModel {
private int maxHeight;
private Bitmap screenBitmap;
private WeakReference<FrameUpdateListener> mFrameUpdateListenerRef;
private ViewTreeObserver.OnDrawListener mOnDrawListener;

public JSONObject startScreenCast(HippyEngineContext context, final JSONObject paramsObj) {
isFramingScreenCast = true;
Expand Down Expand Up @@ -61,6 +62,19 @@ private void listenFrameUpdate(final HippyEngineContext context) {
LogUtils.e(TAG, "listenFrameUpdate error none hippyRootView");
return;
}
if (mOnDrawListener == null) {
mOnDrawListener = new ViewTreeObserver.OnDrawListener() {
@Override
public void onDraw() {
if (mFrameUpdateListenerRef != null) {
FrameUpdateListener listener = mFrameUpdateListenerRef.get();
if (listener != null) {
listener.onFrameUpdate();
}
}
}
};
}
try {
hippyRootView.getViewTreeObserver().removeOnDrawListener(mOnDrawListener);
hippyRootView.getViewTreeObserver().addOnDrawListener(mOnDrawListener);
Expand All @@ -70,19 +84,6 @@ private void listenFrameUpdate(final HippyEngineContext context) {
}
}

private final ViewTreeObserver.OnDrawListener mOnDrawListener = new ViewTreeObserver.OnDrawListener() {
@Override
public void onDraw() {
LogUtils.d(TAG, "HippyRootView, onDraw");
if (mFrameUpdateListenerRef != null) {
FrameUpdateListener listener = mFrameUpdateListenerRef.get();
if (listener != null) {
listener.onFrameUpdate();
}
}
}
};

public void setFrameUpdateListener(FrameUpdateListener listener) {
if (listener != null) {
mFrameUpdateListenerRef = new WeakReference<>(listener);
Expand All @@ -100,7 +101,9 @@ public void stopScreenCast(HippyEngineContext context) {
LogUtils.e(TAG, "stopScreenCast error none hippyRootView");
return;
}
hippyRootView.getViewTreeObserver().removeOnDrawListener(mOnDrawListener);
if (mOnDrawListener != null) {
hippyRootView.getViewTreeObserver().removeOnDrawListener(mOnDrawListener);
}
}
}

Expand Down

0 comments on commit f9059d1

Please sign in to comment.