Skip to content

Commit

Permalink
fix(android): add shouldNotifyNonBatchingChange for render node
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 authored and hippy-actions[bot] committed Jan 9, 2024
1 parent c518dd1 commit 2e48ffe
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -69,6 +71,12 @@ protected View createViewImpl(@NonNull Context context, @Nullable Map<String, Ob
return buildViewPager(context, isVertical);
}

@Override
public RenderNode createRenderNode(int rootId, int id, @Nullable Map<String, Object> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Object> props,
String className, ControllerManager componentManager, boolean isLazyLoad) {
super(rootId, id, props, className, componentManager, isLazyLoad);
}

@Override
protected boolean shouldNotifyNonBatchingChange() {
return !isBatching();
}
}

0 comments on commit 2e48ffe

Please sign in to comment.