Skip to content

Commit

Permalink
fix(android): different sticky item position crash (#3930)
Browse files Browse the repository at this point in the history
Co-authored-by: maxli <maxli@tencent.com>
Co-authored-by: OpenHippy <124017524+open-hippy@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 4, 2024
1 parent 11a0ee5 commit 0f71972
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
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

0 comments on commit 0f71972

Please sign in to comment.