Skip to content

Commit

Permalink
* [android] fix dynamic inserted header not sticky display
Browse files Browse the repository at this point in the history
  • Loading branch information
sospartan committed Dec 7, 2016
1 parent 8d11227 commit 83c0638
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@

public class WXCell extends WXVContainer<WXFrameLayout> {

public int lastLocationY = -1;
private int mLastLocationY = 0;
private ViewGroup mRealView;
private View mTempStickyView;
private View mHeadView;
Expand Down Expand Up @@ -266,6 +266,14 @@ protected WXFrameLayout initComponentHostView(@NonNull Context context) {
}
}

public int getLocationFromStart(){
return mLastLocationY;
}

public void setLocationFromStart(int l){
mLastLocationY = l;
}

@Override
public ViewGroup getRealView() {
return mRealView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,9 @@ public void onBeforeScroll(int dx, int dy) {

if (stickyComponent != null && stickyComponent.getDomObject() != null
&& stickyComponent instanceof WXCell) {
if (stickyComponent.getHostView() == null) {

WXCell cell = (WXCell) stickyComponent;
if (cell.getHostView() == null) {
return;
}

Expand All @@ -624,7 +626,7 @@ public void onBeforeScroll(int dx, int dy) {
boolean beforeFirstVisibleItem = false;
if((layoutManager = getHostView().getInnerView().getLayoutManager()) instanceof LinearLayoutManager){
int fVisible = ((LinearLayoutManager)layoutManager).findFirstVisibleItemPosition();
int pos = mChildren.indexOf(stickyComponent);
int pos = mChildren.indexOf(cell);

if( pos <= fVisible){
beforeFirstVisibleItem = true;
Expand All @@ -638,14 +640,14 @@ public void onBeforeScroll(int dx, int dy) {

int top = location[1] - parentLocation[1];

boolean showSticky = beforeFirstVisibleItem && ((WXCell) stickyComponent).lastLocationY >= 0 && top <= 0 && dy >= 0;
boolean removeSticky = ((WXCell) stickyComponent).lastLocationY <= 0 && top > 0 && dy <= 0;
boolean showSticky = beforeFirstVisibleItem && cell.getLocationFromStart() >= 0 && top <= 0 && dy >= 0;
boolean removeSticky = cell.getLocationFromStart() <= 0 && top > 0 && dy <= 0;
if (showSticky) {
bounceRecyclerView.notifyStickyShow((WXCell) stickyComponent);
bounceRecyclerView.notifyStickyShow(cell);
} else if (removeSticky) {
bounceRecyclerView.notifyStickyRemove((WXCell) stickyComponent);
bounceRecyclerView.notifyStickyRemove(cell);
}
((WXCell) stickyComponent).lastLocationY = top;
cell.setLocationFromStart(top);
}
}
}
Expand Down

0 comments on commit 83c0638

Please sign in to comment.