use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.
the class WXRecyclerTemplateList method createChildViewAt.
/**
* all child is template, none need onCreate child except loading and refresh.
*/
@Override
public void createChildViewAt(int index) {
int indexToCreate = index;
if (indexToCreate < 0) {
indexToCreate = childCount() - 1;
if (indexToCreate < 0) {
return;
}
}
final WXComponent child = getChild(indexToCreate);
if (child instanceof WXBaseRefresh) {
child.createView();
setRefreshOrLoading(child);
}
}
use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.
the class WXRecyclerTemplateList method notifyAppearStateChange.
/**
* first fire appear event.
*/
@Override
public void notifyAppearStateChange(int firstVisible, int lastVisible, int directionX, int directionY) {
if (mAppearHelpers == null || mAppearHelpers.size() <= 0) {
return;
}
String direction = directionY > 0 ? Constants.Value.DIRECTION_UP : directionY < 0 ? Constants.Value.DIRECTION_DOWN : null;
if (getOrientation() == Constants.Orientation.HORIZONTAL && directionX != 0) {
direction = directionX > 0 ? Constants.Value.DIRECTION_LEFT : Constants.Value.DIRECTION_RIGHT;
}
RecyclerView recyclerView = getHostView().getInnerView();
for (int position = firstVisible; position <= lastVisible; position++) {
int type = getItemViewType(position);
List<AppearanceHelper> helpers = mAppearHelpers.get(type);
if (helpers == null) {
continue;
}
for (AppearanceHelper helper : helpers) {
if (!helper.isWatch()) {
continue;
}
TemplateViewHolder itemHolder = (TemplateViewHolder) recyclerView.findViewHolderForAdapterPosition(position);
if (itemHolder == null || itemHolder.getComponent() == null) {
break;
}
List<WXComponent> childListeners = findChildListByRef(itemHolder.getComponent(), helper.getAwareChild().getRef());
if (childListeners == null || childListeners.size() == 0) {
break;
}
Map<String, Map<Integer, List<Object>>> disAppearList = mDisAppearWatchList.get(position);
if (disAppearList == null) {
disAppearList = new ArrayMap<>();
mDisAppearWatchList.put(position, disAppearList);
}
Map<Integer, List<Object>> componentDisAppearList = disAppearList.get(helper.getAwareChild().getRef());
if (componentDisAppearList == null) {
componentDisAppearList = new ArrayMap<>();
disAppearList.put(helper.getAwareChild().getRef(), componentDisAppearList);
}
for (int m = 0; m < childListeners.size(); m++) {
WXComponent childLisener = childListeners.get(m);
if (childLisener.getHostView() == null) {
continue;
}
boolean appear = helper.isViewVisible(childLisener.getHostView());
int key = childLisener.getHostView().hashCode();
if (appear) {
if (!componentDisAppearList.containsKey(key)) {
childLisener.notifyAppearStateChange(Constants.Event.APPEAR, direction);
List<Object> eventArgs = null;
if (childLisener.getDomObject().getEvents() != null && childLisener.getDomObject().getEvents().getEventBindingArgsValues() != null && childLisener.getDomObject().getEvents().getEventBindingArgsValues().get(Constants.Event.DISAPPEAR) != null) {
eventArgs = childLisener.getDomObject().getEvents().getEventBindingArgsValues().get(Constants.Event.DISAPPEAR);
}
componentDisAppearList.put(key, eventArgs);
}
} else {
if (componentDisAppearList.containsKey(key)) {
childLisener.notifyAppearStateChange(Constants.Event.DISAPPEAR, direction);
componentDisAppearList.remove(key);
}
}
}
}
}
// handle disappear event, out of position
int count = getItemCount();
for (int position = 0; position < count; position++) {
if (position >= firstVisible && position <= lastVisible) {
position = lastVisible + 1;
continue;
}
Map<String, Map<Integer, List<Object>>> map = mDisAppearWatchList.get(position);
if (map == null) {
continue;
}
WXCell template = mTemplateSources.get(getTemplateKey(position));
if (template == null) {
return;
}
Set<Map.Entry<String, Map<Integer, List<Object>>>> cellWatcherEntries = map.entrySet();
for (Map.Entry<String, Map<Integer, List<Object>>> cellWatcherEntry : cellWatcherEntries) {
String ref = cellWatcherEntry.getKey();
WXComponent component = findChildByRef(template, ref);
if (component == null) {
continue;
}
Map<Integer, List<Object>> eventWatchers = cellWatcherEntry.getValue();
if (eventWatchers == null || eventWatchers.size() == 0) {
continue;
}
WXEvent events = component.getDomObject().getEvents();
Set<Map.Entry<Integer, List<Object>>> eventWatcherEntries = eventWatchers.entrySet();
for (Map.Entry<Integer, List<Object>> eventWatcherEntry : eventWatcherEntries) {
events.putEventBindingArgsValue(Constants.Event.DISAPPEAR, eventWatcherEntry.getValue());
component.notifyAppearStateChange(Constants.Event.DISAPPEAR, direction);
}
eventWatchers.clear();
}
mDisAppearWatchList.remove(position);
}
}
use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.
the class WXRecyclerTemplateList method findChildListByRef.
/**
* find child list, has same ref
*/
public List<WXComponent> findChildListByRef(WXComponent component, String ref) {
WXComponent child = findChildByRef(component, ref);
if (child == null) {
return null;
}
List<WXComponent> componentList = new ArrayList<>();
WXVContainer container = child.getParent();
if (container != null && (!(container instanceof WXRecyclerTemplateList))) {
for (int i = 0; i < container.getChildCount(); i++) {
WXComponent element = container.getChild(i);
if (ref.equals(element.getRef())) {
componentList.add(element);
}
}
} else {
componentList.add(child);
}
return componentList;
}
use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.
the class WXRecyclerTemplateList method unbindStickStyle.
@Override
public void unbindStickStyle(WXComponent component) {
WXComponent template = findParentType(component, WXCell.class);
if (template == null || cellDataManager.listData == null || mStickyHelper == null) {
return;
}
if (mStickyHelper.getStickyTypes().contains(template.getRef())) {
mStickyHelper.getStickyTypes().remove(template.getRef());
notifyUpdateList();
}
}
use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.
the class WXScrollView method procSticky.
private View procSticky(Map<String, Map<String, WXComponent>> mStickyMap) {
if (mStickyMap == null) {
return null;
}
Map<String, WXComponent> stickyMap = mStickyMap.get(mWAScroller.getRef());
if (stickyMap == null) {
return null;
}
Iterator<Entry<String, WXComponent>> iterator = stickyMap.entrySet().iterator();
Entry<String, WXComponent> entry = null;
WXComponent stickyData;
while (iterator.hasNext()) {
entry = iterator.next();
stickyData = entry.getValue();
getLocationOnScreen(stickyScrollerP);
stickyData.getHostView().getLocationOnScreen(stickyViewP);
int parentH = 0;
if (stickyData.getParent() != null && stickyData.getParent().getRealView() != null) {
parentH = stickyData.getParent().getRealView().getHeight();
}
int stickyViewH = stickyData.getHostView().getHeight();
int stickyShowPos = stickyScrollerP[1];
int stickyStartHidePos = -parentH + stickyScrollerP[1] + stickyViewH;
if (stickyViewP[1] <= stickyShowPos && stickyViewP[1] >= (stickyStartHidePos - stickyViewH)) {
mStickyOffset = stickyViewP[1] - stickyStartHidePos;
stickyData.setStickyOffset(stickyViewP[1] - stickyScrollerP[1]);
return stickyData.getHostView();
} else {
stickyData.setStickyOffset(0);
}
}
return null;
}
Aggregations