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): do scrollTo after scroll range reduce #3770

Merged
merged 2 commits into from
Mar 7, 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 @@ -103,10 +103,16 @@ void addNullUINodeIfNeeded(RenderNode renderNode) {

public void updateLayout(int id, int x, int y, int w, int h) {
LogUtils.d("RenderManager", "updateLayout ID " + id);
RenderNode uiNode = mNodes.get(id);
uiNode.updateLayout(x, y, w, h);

addUpdateNodeIfNeeded(uiNode);
RenderNode node = mNodes.get(id);
if (node != null) {
node.updateLayout(x, y, w, h);
addUpdateNodeIfNeeded(node);
if (node.getParent() instanceof ScrollViewRenderNode) {
// ScrollView doesn't receive updateLayout when its content changes,
// so we specifically call addUpdateNodeIfNeeded()
addUpdateNodeIfNeeded(node.getParent());
}
}
}

public void updateNode(int id, HippyMap map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class HippyHorizontalScrollView extends HorizontalScrollView implements H
protected int mScrollEventThrottle = 10;
private long mLastScrollEventTimeStamp = -1;
private boolean mHasUnsentScrollEvent;

private int mScrollRange = 0;
protected int mScrollMinOffset = 0;
private int startScrollX = 0;
private int mLastX = 0;
Expand Down Expand Up @@ -484,7 +484,15 @@ public void setInitialContentOffset(int offset) {

@Override
public void scrollToInitContentOffset() {
int scrollRange = mScrollRange;
View firstChild = getChildAt(0);
if (firstChild != null) {
mScrollRange = firstChild.getWidth();
}
if (hasCompleteFirstBatch) {
if (mScrollRange < scrollRange) {
scrollTo(getScrollX(), getScrollY());
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
/* 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.mtt.hippy.views.scroll;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import com.tencent.mtt.hippy.HippyRootView;
import com.tencent.mtt.hippy.annotation.HippyController;
import com.tencent.mtt.hippy.annotation.HippyControllerProps;
import com.tencent.mtt.hippy.common.HippyArray;
import com.tencent.mtt.hippy.common.HippyMap;
import com.tencent.mtt.hippy.dom.node.NodeProps;
import com.tencent.mtt.hippy.uimanager.ControllerManager;
import com.tencent.mtt.hippy.uimanager.HippyGroupController;
import com.tencent.mtt.hippy.uimanager.ListItemRenderNode;
import com.tencent.mtt.hippy.uimanager.RenderNode;
import com.tencent.mtt.hippy.uimanager.ScrollViewRenderNode;
import com.tencent.mtt.hippy.utils.PixelUtil;
import com.tencent.mtt.hippy.views.list.HippyListView;
import com.tencent.mtt.hippy.views.view.HippyViewGroup;
Expand All @@ -26,6 +47,11 @@ public class HippyScrollViewController<T extends ViewGroup & HippyScrollView> ex

public static final String CLASS_NAME = "ScrollView";

@Override
public RenderNode createRenderNode(int id, HippyMap props, String className,
HippyRootView hippyRootView, ControllerManager controllerManager, boolean lazy) {
return new ScrollViewRenderNode(id, props, className, hippyRootView, controllerManager, lazy);
}

@Override
protected View createViewImpl(Context context, HippyMap iniProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class HippyVerticalScrollView extends NestedScrollView implements HippyVi
private boolean mHasUnsentScrollEvent;

protected int mScrollMinOffset = 0;
private int mScrollRange = 0;
private int startScrollY = 0;
private int mLastY = 0;
private int initialContentOffset = 0;
Expand Down Expand Up @@ -352,7 +353,15 @@ public void setInitialContentOffset(int offset) {

@Override
public void scrollToInitContentOffset() {
int scrollRange = mScrollRange;
View firstChild = getChildAt(0);
if (firstChild != null) {
mScrollRange = firstChild.getHeight();
}
if (hasCompleteFirstBatch) {
if (mScrollRange < scrollRange) {
scrollTo(getScrollX(), getScrollY());
}
return;
}

Expand Down
Loading