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): issues of ScrollEvent #3362

Merged
merged 4 commits into from
Jul 10, 2023
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 @@ -158,20 +158,33 @@ public void setListData() {
}

/**
* 内容偏移,返回recyclerView顶部被滑出去的内容 1、找到顶部第一个View前面的逻辑内容高度 2、加上第一个View被遮住的区域
* Vertical offset of the content, might be different than the
* {@link #computeVerticalScrollOffset()} if pullHeader exist.
*/
public int getContentOffsetY() {
return computeVerticalScrollOffset();
if (HippyListUtils.isVerticalLayout(this)) {
int offset = computeVerticalScrollOffset();
if (listAdapter.headerRefreshHelper != null) {
offset -= listAdapter.headerRefreshHelper.getVisibleSize();
}
return offset;
}
return 0;
}

/**
* 内容偏移,返回recyclerView被滑出去的内容 1、找到顶部第一个View前面的逻辑内容宽度 2、加上第一个View被遮住的区域
* Horizontal offset of the content, might be different than the
* {@link #computeHorizontalScrollOffset()} if pullHeader exist.
*/
public int getContentOffsetX() {
int firstChildPosition = getFirstChildPosition();
int totalWidthBeforePosition = getTotalWithBefore(firstChildPosition);
int firstChildOffset = listAdapter.getItemWidth(firstChildPosition) - getVisibleWidth(getChildAt(0));
return totalWidthBeforePosition + firstChildOffset;
if (HippyListUtils.isHorizontalLayout(this)) {
int offset = computeHorizontalScrollOffset();
if (listAdapter.headerRefreshHelper != null) {
offset -= listAdapter.headerRefreshHelper.getVisibleSize();
}
return offset;
}
return 0;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public void setScrollEventThrottle(int scrollEventThrottle) {

public final HippyMap generateScrollEvent() {
HippyMap contentOffset = new HippyMap();
contentOffset.pushDouble("x", PixelUtil.px2dp(0));
contentOffset.pushDouble("x", PixelUtil.px2dp(hippyRecyclerView.getContentOffsetX()));
contentOffset.pushDouble("y", PixelUtil.px2dp(hippyRecyclerView.getContentOffsetY()));
HippyMap event = new HippyMap();
event.pushMap("contentOffset", contentOffset);
Expand Down Expand Up @@ -390,13 +390,14 @@ public void onViewDetachedFromWindow(View v) {
public void onOverPullStateChanged(int oldState, int newState, int offset) {
LogUtils.d("QBRecyclerViewEventHelper", "oldState:" + oldState + ",newState:" + newState);
if (oldState == HippyOverPullHelper.OVER_PULL_NONE && (isOverPulling(newState)
|| newState == HippyOverPullHelper.OVER_PULL_NORMAL)) {
|| newState == HippyOverPullHelper.OVER_PULL_NORMAL) && scrollBeginDragEventEnable) {
getOnScrollDragStartedEvent().send(getParentView(), generateScrollEvent());
}
if (isOverPulling(oldState) && isOverPulling(newState)) {
if (isOverPulling(oldState) && isOverPulling(newState) && onScrollEventEnable) {
sendOnScrollEvent();
}
if (newState == HippyOverPullHelper.OVER_PULL_SETTLING && oldState != HippyOverPullHelper.OVER_PULL_SETTLING) {
if (newState == HippyOverPullHelper.OVER_PULL_SETTLING &&
oldState != HippyOverPullHelper.OVER_PULL_SETTLING && scrollEndDragEventEnable) {
getOnScrollDragEndedEvent().send(getParentView(), generateScrollEvent());
}
}
Expand Down