From 2e48ffe2ad7a1805bce3a1739de336d1b5bca426 Mon Sep 17 00:00:00 2001 From: maxli Date: Tue, 9 Jan 2024 16:40:39 +0800 Subject: [PATCH] fix(android): add shouldNotifyNonBatchingChange for render node --- .../viewpager/HippyViewPagerController.java | 10 +++++- .../com/tencent/renderer/node/RenderNode.java | 14 ++++++++ .../renderer/node/ViewPagerRenderNode.java | 34 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 renderer/native/android/src/main/java/com/tencent/renderer/node/ViewPagerRenderNode.java diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/viewpager/HippyViewPagerController.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/viewpager/HippyViewPagerController.java index 06493a63a8e..e8e0eefdf84 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/viewpager/HippyViewPagerController.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/viewpager/HippyViewPagerController.java @@ -21,6 +21,7 @@ import com.tencent.mtt.hippy.common.HippyArray; import com.tencent.mtt.hippy.dom.node.NodeProps; import com.tencent.mtt.hippy.modules.Promise; +import com.tencent.mtt.hippy.uimanager.ControllerManager; import com.tencent.mtt.hippy.uimanager.HippyViewController; import com.tencent.mtt.hippy.utils.LogUtils; import com.tencent.mtt.hippy.utils.PixelUtil; @@ -32,7 +33,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.tencent.mtt.hippy.views.hippypager.HippyPager; +import com.tencent.renderer.node.RenderNode; +import com.tencent.renderer.node.ViewPagerRenderNode; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -69,6 +71,12 @@ protected View createViewImpl(@NonNull Context context, @Nullable Map props, + @NonNull String className, @NonNull ControllerManager controllerManager, boolean isLazy) { + return new ViewPagerRenderNode(rootId, id, props, className, controllerManager, isLazy); + } + protected HippyViewPager buildViewPager(@NonNull Context context, boolean isVertical) { HippyViewPager viewPager = new HippyViewPager(context, isVertical); viewPager.setPageChangeListener(new ViewPagerPageChangeListener(viewPager)); diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/node/RenderNode.java b/renderer/native/android/src/main/java/com/tencent/renderer/node/RenderNode.java index fb136787b72..a0cfaf0daa9 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/node/RenderNode.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/node/RenderNode.java @@ -501,6 +501,11 @@ public void mountHostViewRecursive() { for (RenderNode renderNode : mChildren) { renderNode.mountHostViewRecursive(); } + // Due to the delayed loading of list view items and their child elements, non first screen elements + // may need to manually call batch complete when created, such as nested view pagers within list view items + if (shouldNotifyNonBatchingChange()) { + batchComplete(); + } } public boolean shouldSticky() { @@ -737,12 +742,21 @@ public int compare(RenderNode n1, RenderNode n2) { } } + public boolean isBatching() { + RenderManager renderManager = mControllerManager.getRenderManager(); + return renderManager != null && renderManager.isBatching(); + } + public void batchStart() { if (!isDeleted() && !isLazyLoad()) { mControllerManager.onBatchStart(mRootId, mId, mClassName); } } + protected boolean shouldNotifyNonBatchingChange() { + return false; + } + public void batchComplete() { if (!isDeleted() && !isLazyLoad()) { mControllerManager.onBatchComplete(mRootId, mId, mClassName); diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/node/ViewPagerRenderNode.java b/renderer/native/android/src/main/java/com/tencent/renderer/node/ViewPagerRenderNode.java new file mode 100644 index 00000000000..c7f82c0ef11 --- /dev/null +++ b/renderer/native/android/src/main/java/com/tencent/renderer/node/ViewPagerRenderNode.java @@ -0,0 +1,34 @@ +/* Tencent is pleased to support the open source community by making Hippy available. + * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.tencent.renderer.node; + +import androidx.annotation.Nullable; +import com.tencent.mtt.hippy.uimanager.ControllerManager; +import java.util.Map; + +public class ViewPagerRenderNode extends RenderNode { + + public ViewPagerRenderNode(int rootId, int id, @Nullable Map props, + String className, ControllerManager componentManager, boolean isLazyLoad) { + super(rootId, id, props, className, componentManager, isLazyLoad); + } + + @Override + protected boolean shouldNotifyNonBatchingChange() { + return !isBatching(); + } +}