Skip to content

Commit

Permalink
fix(android): add thread check before argumentToBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 authored and hippy-actions[bot] committed Jan 22, 2024
1 parent 7bf7ac7 commit b3f3de0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.tencent.renderer;

import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

Expand All @@ -24,6 +25,7 @@
import com.tencent.mtt.hippy.serialization.nio.writer.SafeHeapWriter;
import com.tencent.mtt.hippy.serialization.string.InternalizedStringTable;
import com.tencent.mtt.hippy.utils.PixelUtil;
import com.tencent.mtt.hippy.utils.UIThreadUtils;
import com.tencent.renderer.annotation.CalledByNative;
import com.tencent.renderer.serialization.Deserializer;
import com.tencent.renderer.serialization.Serializer;
Expand Down Expand Up @@ -351,7 +353,18 @@ public void onSizeChanged(int rootId, int nodeId, int width, int height, boolean
* @param nodeId the dom node id
* @param params parameters to be return to js
*/
public void doPromiseCallBack(int result, long callbackId, @NonNull String functionName,
public void doPromiseCallBack(final int result, final long callbackId, @NonNull final String functionName,
final int rootId, final int nodeId, @Nullable final Object params) {
if (UIThreadUtils.isOnUiThread()) {
doPromiseCallBackImpl(result, callbackId, functionName, rootId, nodeId, params);
} else {
UIThreadUtils.runOnUiThread(
() -> doPromiseCallBackImpl(result, callbackId, functionName, rootId, nodeId, params));
}
}

@MainThread
private void doPromiseCallBackImpl(int result, long callbackId, @NonNull String functionName,
int rootId, int nodeId, @Nullable Object params) {
byte[] bytes = null;
int offset = 0;
Expand All @@ -375,7 +388,17 @@ public void doPromiseCallBack(int result, long callbackId, @NonNull String funct
length);
}

public void dispatchEvent(int rootId, int nodeId, @NonNull String eventName,
public void dispatchEvent(final int rootId, final int nodeId, @NonNull final String eventName,
@Nullable final Object params, final boolean useCapture, final boolean useBubble) {
if (UIThreadUtils.isOnUiThread()) {
dispatchEventImpl(rootId, nodeId, eventName, params, useCapture, useBubble);
} else {
UIThreadUtils.runOnUiThread(
() -> dispatchEventImpl(rootId, nodeId, eventName, params, useCapture, useBubble));
}
}

private void dispatchEventImpl(int rootId, int nodeId, @NonNull String eventName,
@Nullable Object params, boolean useCapture, boolean useBubble) {
byte[] bytes = null;
int offset = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,18 @@ public TextImageSpan(Drawable drawable, String source, @NonNull ImageVirtualNode
}

public void setUrl(@Nullable final String url) {
if (!TextUtils.isEmpty(url)) {
if (TextUtils.isEmpty(url)) {
return;
}
if (UIThreadUtils.isOnUiThread()) {
loadImageWithUrl(url);
} else {
UIThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
loadImageWithUrl(url);
}
});
}
}

Expand Down

0 comments on commit b3f3de0

Please sign in to comment.