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): different sticky item position crash #3930

Merged
merged 2 commits into from
Jun 26, 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 @@ -252,7 +252,7 @@ public int getItemViewType(int position) {
return 0;
}
if (node.shouldSticky()) {
return STICK_ITEM_VIEW_TYPE_BASE - position;
return STICK_ITEM_VIEW_TYPE_BASE - node.getItemViewType();
}
return node.getItemViewType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
public class StickyHeaderHelper extends OnScrollListener implements
ViewTreeObserver.OnGlobalLayoutListener {

private static final String TAG = "StickyHeaderHelper";
private static final int INVALID_POSITION = -1;
private final com.tencent.mtt.hippy.views.hippylist.recyclerview.helper.skikcy.IHeaderAttachListener headerAttachListener;
private RecyclerViewBase recyclerView;
Expand Down Expand Up @@ -75,8 +76,12 @@ public void setOrientation(int orientation) {
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
int newStickyPosition = getStickyItemPosition();
if (currentStickPos != newStickyPosition) {
detachSticky();
attachSticky(newStickyPosition);
try {
detachSticky();
attachSticky(newStickyPosition);
} catch (Exception e) {
LogUtils.e(TAG, "sticky handle error: " + e.getMessage());
}
}
offsetSticky();
}
Expand All @@ -93,7 +98,7 @@ public void setUpdateStickyViewWhenLayout(boolean bindStickyHolderWhenLayout) {
* 如果当前stickHolder和新的stickyHolder 不一样,那么把当前的stickyHolder删除掉,并还原HeaderView的Translation
*/
public void detachSticky() {
if (headerOrgViewHolder != null) {
if (headerOrgViewHolder != null && this.currentHeaderView != null) {
removeViewFromParent(this.currentHeaderView);
currentHeaderView.setTranslationY(0);
currentHeaderView.setTranslationX(0);
Expand Down
Loading