use of com.taobao.weex.common.OnWXScrollListener in project weex-example by KalicyZhou.
the class BasicListComponent method initComponentHostView.
@Override
protected T initComponentHostView(@NonNull Context context) {
T bounceRecyclerView = generateListView(context, getOrientation());
String transforms = (String) getDomObject().getAttrs().get(TRANSFORM);
if (transforms != null) {
bounceRecyclerView.getInnerView().addItemDecoration(parseTransforms(transforms));
}
RecyclerViewBaseAdapter recyclerViewBaseAdapter = new RecyclerViewBaseAdapter<>(this);
recyclerViewBaseAdapter.setHasStableIds(true);
bounceRecyclerView.setRecyclerViewBaseAdapter(recyclerViewBaseAdapter);
bounceRecyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
bounceRecyclerView.getInnerView().clearOnScrollListeners();
bounceRecyclerView.getInnerView().addOnScrollListener(mViewOnScrollListener);
bounceRecyclerView.getInnerView().addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
for (ListBaseViewHolder holder : recycleViewList) {
if (holder != null && holder.getComponent() != null && !holder.getComponent().isUsing()) {
recycleImage(holder.getView());
}
}
recycleViewList.clear();
}
List<OnWXScrollListener> listeners = getInstance().getWXScrollListeners();
if (listeners != null && listeners.size() > 0) {
for (OnWXScrollListener listener : listeners) {
if (listener != null) {
View topView = recyclerView.getChildAt(0);
if (topView != null) {
int y = topView.getTop();
listener.onScrollStateChanged(recyclerView, 0, y, newState);
}
}
}
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
List<OnWXScrollListener> listeners = getInstance().getWXScrollListeners();
if (listeners != null && listeners.size() > 0) {
for (OnWXScrollListener listener : listeners) {
if (listener != null) {
listener.onScrolled(recyclerView, dx, dy);
}
}
}
}
});
bounceRecyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
T view;
if ((view = getHostView()) == null)
return;
mViewOnScrollListener.onScrolled(view.getInnerView(), 0, 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
});
return bounceRecyclerView;
}
use of com.taobao.weex.common.OnWXScrollListener in project weex-example by KalicyZhou.
the class WXScroller method initComponentHostView.
@Override
protected ViewGroup initComponentHostView(@NonNull Context context) {
String scroll;
if (getDomObject() == null || getDomObject().getAttrs().isEmpty()) {
scroll = "vertical";
} else {
scroll = getDomObject().getAttrs().getScrollDirection();
}
ViewGroup host;
if (("horizontal").equals(scroll)) {
mOrientation = Constants.Orientation.HORIZONTAL;
WXHorizontalScrollView scrollView = new WXHorizontalScrollView(context);
mRealView = new FrameLayout(context);
scrollView.setScrollViewListener(new WXHorizontalScrollView.ScrollViewListener() {
@Override
public void onScrollChanged(WXHorizontalScrollView scrollView, int x, int y, int oldx, int oldy) {
procAppear(x, y, oldx, oldy);
}
});
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
scrollView.addView(mRealView, layoutParams);
scrollView.setHorizontalScrollBarEnabled(false);
host = scrollView;
} else {
mOrientation = Constants.Orientation.VERTICAL;
BounceScrollerView scrollerView = new BounceScrollerView(context, mOrientation, this);
mRealView = new FrameLayout(context);
WXScrollView innerView = scrollerView.getInnerView();
innerView.addScrollViewListener(this);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
innerView.addView(mRealView, layoutParams);
innerView.setVerticalScrollBarEnabled(true);
innerView.addScrollViewListener(new WXScrollViewListener() {
@Override
public void onScrollChanged(WXScrollView scrollView, int x, int y, int oldx, int oldy) {
}
@Override
public void onScrollToBottom(WXScrollView scrollView, int x, int y) {
}
@Override
public void onScrollStopped(WXScrollView scrollView, int x, int y) {
List<OnWXScrollListener> listeners = getInstance().getWXScrollListeners();
if (listeners != null && listeners.size() > 0) {
for (OnWXScrollListener listener : listeners) {
if (listener != null) {
listener.onScrollStateChanged(scrollView, x, y, OnWXScrollListener.IDLE);
}
}
}
}
@Override
public void onScroll(WXScrollView scrollView, int x, int y) {
List<OnWXScrollListener> listeners = getInstance().getWXScrollListeners();
if (listeners != null && listeners.size() > 0) {
for (OnWXScrollListener listener : listeners) {
if (listener != null) {
listener.onScrolled(scrollView, x, y);
}
}
}
}
});
host = scrollerView;
}
host.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
procAppear(0, 0, 0, 0);
View view;
if ((view = getHostView()) == null) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
});
return host;
}
Aggregations