Skip to content

Commit

Permalink
fix(android): do scrollTo after scroll range reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 committed Mar 7, 2024
1 parent 48fd18b commit 9178427
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
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
@@ -0,0 +1,28 @@
/* 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.uimanager;

import com.tencent.mtt.hippy.HippyRootView;
import com.tencent.mtt.hippy.common.HippyMap;

public class ScrollViewRenderNode extends RenderNode {

public ScrollViewRenderNode(int mId, HippyMap mPropsToUpdate, String className,
HippyRootView mRootView, ControllerManager componentManager, boolean isLazyLoad) {
super(mId, mPropsToUpdate, className, mRootView, componentManager, isLazyLoad);
}
}
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
Expand Up @@ -4,12 +4,17 @@
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 +31,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

0 comments on commit 9178427

Please sign in to comment.