Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): add shouldNotifyNonBatchingChange for render node #3708

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading