Skip to content

Commit

Permalink
* [android] fix bug sticky not show
Browse files Browse the repository at this point in the history
  • Loading branch information
miomin committed Jul 14, 2016
1 parent 92a92dc commit dc3ca4d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,11 @@
*/
package com.taobao.weex.ui.component;

import android.view.ViewGroup;

import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.common.Component;
import com.taobao.weex.common.WXDomPropConstant;
import com.taobao.weex.dom.WXDomObject;
import com.taobao.weex.ui.component.list.WXCell;
import com.taobao.weex.ui.view.WXFrameLayout;

/**
* The same as sticky cell
Expand All @@ -229,19 +226,4 @@ public WXHeader(WXSDKInstance instance, WXDomObject node, WXVContainer parent, b
lazy(false);
setSticky(WXDomPropConstant.WX_POSITION_STICKY);
}

@Override
protected void initView() {
if(mContext!=null) {
mHost = new WXFrameLayout(mContext);
((ViewGroup)mHost).addView(new WXFrameLayout(mContext));
}
}

@Override
public ViewGroup getRealView() {
if (mHost == null)
return null;
return (ViewGroup) ((ViewGroup)mHost).getChildAt(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,13 @@
*/
package com.taobao.weex.ui.component.list;

import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.dom.WXDomObject;
import com.taobao.weex.dom.flex.CSSLayout;
import com.taobao.weex.ui.component.WXVContainer;
import com.taobao.weex.ui.view.WXFrameLayout;

Expand All @@ -217,6 +220,9 @@
public class WXCell extends WXVContainer {

public int lastLocationY = -1;
private ViewGroup realView;
private View tempStickyView;
private View headView;

@Deprecated
public WXCell(WXSDKInstance instance, WXDomObject dom, WXVContainer parent, String instanceId, boolean isLazy) {
Expand All @@ -235,21 +241,42 @@ protected void initView() {
if(mContext!=null) {
if (mDomObj != null && mDomObj.isSticky()) {
mHost = new WXFrameLayout(mContext);
((ViewGroup) mHost).addView(new WXFrameLayout(mContext));
realView = new WXFrameLayout(mContext);
((ViewGroup) mHost).addView(realView);
} else {
super.initView();
realView = (ViewGroup) mHost;
}
}
}

@Override
public ViewGroup getRealView() {
if (mHost == null)
return null;
if (mDomObj != null && mDomObj.isSticky()) {
return (ViewGroup) ((ViewGroup) mHost).getChildAt(0);
} else {
return super.getRealView();
}
return realView;
}

public void removeSticky() {
headView = getView().getChildAt(0);
int[] location = new int[2];
int[] parentLocation = new int[2];
getView().getLocationOnScreen(location);
getParentScroller().getView().getLocationOnScreen(parentLocation);
int headerViewOffsetX = location[0] - parentLocation[0];
int headerViewOffsetY = getParent().getView().getTop();
getView().removeView(headView);
realView = (ViewGroup) headView;
tempStickyView= new FrameLayout(mContext);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams((int) getDomObject().csslayout.dimensions[CSSLayout.DIMENSION_WIDTH],
(int) getDomObject().csslayout.dimensions[CSSLayout.DIMENSION_HEIGHT]);
getView().addView(tempStickyView, lp);
headView.setTranslationX(headerViewOffsetX);
headView.setTranslationY(headerViewOffsetY);
}

public void recoverySticky() {
getView().removeView(tempStickyView);
getView().addView(headView);
headView.setTranslationX(0);
headView.setTranslationY(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.taobao.weex.dom.flex.CSSLayout;
import com.taobao.weex.ui.component.WXComponent;
import com.taobao.weex.ui.component.list.WXCell;
import com.taobao.weex.ui.view.listview.WXRecyclerView;
Expand All @@ -223,7 +222,6 @@ public class BounceRecyclerView extends BaseBounceView<WXRecyclerView> {

private RecyclerViewBaseAdapter adapter = null;
private Stack<View> headerViewStack = new Stack<>();
private Stack<View> tempViewStack = new Stack<>();
private Stack<WXCell> headComponentStack = new Stack<>();

public BounceRecyclerView(Context context, int orientation) {
Expand Down Expand Up @@ -270,6 +268,8 @@ public void onLoadmoreComplete() {
* @param component
*/
public void notifyStickyShow(WXCell component) {
if (component == null)
return;
if (!headComponentStack.isEmpty()) {
WXCell oldCom = headComponentStack.pop();
if (!oldCom.getRef().equals(component.getRef())) {
Expand All @@ -290,7 +290,9 @@ public void notifyStickyShow(WXCell component) {
* @param component
*/
public void notifyStickyRemove(WXCell component) {
if (!headComponentStack.isEmpty() && !headerViewStack.isEmpty() && !tempViewStack.isEmpty()) {
if (component == null)
return;
if (!headComponentStack.isEmpty() && !headerViewStack.isEmpty()) {
removeSticky(component);
}
}
Expand All @@ -302,22 +304,11 @@ private void showSticky() {
WXCell headComponent = headComponentStack.pop();
headComponentStack.push(headComponent);
FrameLayout headerView = (FrameLayout) headComponent.getView().getChildAt(0);
if (headerView == null)
return;
headerViewStack.push(headerView);
int[] location = new int[2];
int[] parentLocation = new int[2];
headComponent.getView().getLocationOnScreen(location);
headComponent.getParentScroller().getView().getLocationOnScreen(parentLocation);
int headerViewOffsetX = location[0] - parentLocation[0];
int headerViewOffsetY = getTop();
headComponent.getView().removeView(headerView);
FrameLayout tempView = new FrameLayout(getContext());
tempViewStack.push(tempView);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams((int) headComponent.getDomObject().csslayout.dimensions[CSSLayout.DIMENSION_WIDTH],
(int) headComponent.getDomObject().csslayout.dimensions[CSSLayout.DIMENSION_HEIGHT]);
headComponent.getView().addView(tempView, lp);
headComponent.removeSticky();
((ViewGroup) getParent()).addView(headerView);
headerView.setTranslationX(headerViewOffsetX);
headerView.setTranslationY(headerViewOffsetY);
}

/**
Expand All @@ -330,29 +321,21 @@ private void removeSticky(WXComponent component) {
headComponentStack.push(headComponent);
return;
}
View tempView = tempViewStack.pop();
View headerView = headerViewStack.pop();
headComponent.getView().removeView(tempView);
((ViewGroup) getParent()).removeView(headerView);
headComponent.getView().addView(headerView);
headerView.setTranslationX(0);
headerView.setTranslationY(0);
headComponent.recoverySticky();
}

/**
* Clear All Sticky of stack
*/
public void clearSticky() {
int size = headComponentStack.size();
while (size > 0 && tempViewStack.size() == size && headerViewStack.size() == size) {
while (size > 0 && headerViewStack.size() == size) {
WXCell headComponent = headComponentStack.pop();
View tempView = tempViewStack.pop();
View headerView = headerViewStack.pop();
headComponent.getView().removeView(tempView);
((ViewGroup) getParent()).removeView(headerView);
headComponent.getView().addView(headerView);
headerView.setTranslationX(0);
headerView.setTranslationY(0);
headComponent.recoverySticky();
}
}
}

0 comments on commit dc3ca4d

Please sign in to comment.