Skip to content

Commit

Permalink
fix(android): correct move node impl with different pid
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 authored and siguangli committed May 13, 2024
1 parent 3ce42a2 commit e501e93
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,13 @@ void NativeRenderManager::MoveRenderNode(std::weak_ptr<RootNode> root_node,
auto len = nodes.size();
footstone::value::HippyValue::HippyValueArrayType dom_node_array;
dom_node_array.resize(len);
uint32_t pid;
for (uint32_t i = 0; i < len; i++) {
const auto& render_info = nodes[i]->GetRenderInfo();
footstone::value::HippyValue::HippyValueObjectType dom_node;
dom_node[kId] = footstone::value::HippyValue(render_info.id);
dom_node[kPid] = footstone::value::HippyValue(render_info.pid);
dom_node[kIndex] = footstone::value::HippyValue(render_info.index);
dom_node_array[i] = dom_node;
pid = render_info.pid;
}
serializer_->WriteValue(HippyValue(dom_node_array));
std::pair<uint8_t*, size_t> buffer_pair = serializer_->Release();
Expand All @@ -286,12 +284,12 @@ void NativeRenderManager::MoveRenderNode(std::weak_ptr<RootNode> root_node,
FOOTSTONE_LOG(ERROR) << "CallNativeMethod j_class error";
return;
}
jmethodID j_method_id = j_env->GetMethodID(j_class, "moveNode", "(II[B)V");
jmethodID j_method_id = j_env->GetMethodID(j_class, "moveNode", "(I[B)V");
if (!j_method_id) {
FOOTSTONE_LOG(ERROR) << "moveNode" << " j_method_id error";
return;
}
j_env->CallVoidMethod(j_object, j_method_id, root->GetId(), pid, j_buffer);
j_env->CallVoidMethod(j_object, j_method_id, root->GetId(), j_buffer);
JNIEnvironment::ClearJEnvException(j_env);
j_env->DeleteLocalRef(j_buffer);
j_env->DeleteLocalRef(j_class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface NativeRenderDelegate extends RenderExceptionHandler, RenderLogH

void moveNode(int rootId, int[] ids, int newPid, int oldPid, int insertIndex) throws NativeRenderException;

void moveNode(int rootId, int pid, @NonNull List<Object> list) throws NativeRenderException;
void moveNode(int rootId, @NonNull List<Object> list) throws NativeRenderException;

void updateLayout(int rootId, @NonNull List<Object> list) throws NativeRenderException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,16 @@ public void moveNode(int rootId, int[] ids, int newPid, int oldPid, int insertIn
* Adjust the order of child nodes under the same parent node </>
*
* @param rootId the root node id
* @param pid the parent node id
* @param buffer the byte array serialize by native (C++)
*/
@CalledByNative
@SuppressWarnings("unused")
public void moveNode(int rootId, int pid, byte[] buffer) {
public void moveNode(int rootId, byte[] buffer) {
NativeRenderDelegate renderDelegate = mRenderDelegateRef.get();
if (renderDelegate != null) {
try {
final List<Object> list = bytesToArgument(ByteBuffer.wrap(buffer));
renderDelegate.moveNode(rootId, pid, list);
renderDelegate.moveNode(rootId, list);
} catch (NativeRenderException e) {
renderDelegate.handleRenderException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,16 +656,39 @@ public void moveNode(final int rootId, final int[] ids, final int newPid, final
}

@Override
public void moveNode(final int rootId, final int pid, @NonNull final List<Object> list) {
public void moveNode(final int rootId, @NonNull final List<Object> list) {
if (LogUtils.isDebugMode()) {
LogUtils.d(TAG, "moveNode: pid " + pid + ", node list " + list + "\n ");
LogUtils.d(TAG, "moveNode: node list " + list + "\n ");
}
VirtualNode parent = mVirtualNodeManager.getVirtualNode(rootId, pid);
if (parent == null) {
addUITask(() -> mRenderManager.moveNode(rootId, pid, list));
} else {
mVirtualNodeManager.moveNode(rootId, parent, list);
addUITask(() -> mRenderManager.onMoveVirtualNode(rootId, pid, list));
final Map<Integer, List<Object>> nodeMap = new HashMap<>();
for (int i = 0; i < list.size(); i++) {
final Map<String, Object> moveNodeInfo = ArrayUtils.getMapValue(list, i);
if (moveNodeInfo == null) {
continue;
}
final Integer pid = MapUtils.getIntValue(moveNodeInfo, NODE_PID, INVALID_NODE_ID);
if (pid == INVALID_NODE_ID) {
continue;
}
List<Object> nodeList = nodeMap.get(pid);
if (nodeList == null) {
nodeList = new ArrayList<>();
nodeList.add(moveNodeInfo);
nodeMap.put(pid, nodeList);
} else {
nodeList.add(moveNodeInfo);
}
}
for (Entry<Integer, List<Object>> entry : nodeMap.entrySet()) {
final Integer pid = entry.getKey();
final List<Object> value = entry.getValue();
VirtualNode parent = mVirtualNodeManager.getVirtualNode(rootId, pid);
if (parent == null) {
addUITask(() -> mRenderManager.moveNode(rootId, pid, value));
} else {
mVirtualNodeManager.moveNode(rootId, parent, value);
addUITask(() -> mRenderManager.onMoveVirtualNode(rootId, pid, value));
}
}
}

Expand Down Expand Up @@ -738,8 +761,8 @@ public void updateEventListener(final int rootId, @NonNull List<Object> eventLis
TAG + ": updateEventListener: invalid negative id=" + nodeId);
}
if (LogUtils.isDebugMode()) {
LogUtils.d(TAG,
"updateEventListener: id " + nodeId + ", eventProps " + eventProps + "\n ");
// LogUtils.d(TAG,
// "updateEventListener: id " + nodeId + ", eventProps " + eventProps + "\n ");
}
mVirtualNodeManager.updateEventListener(rootId, nodeId, eventProps);
taskList.add(() -> mRenderManager.updateEventListener(rootId, nodeId, eventProps));
Expand Down

0 comments on commit e501e93

Please sign in to comment.