use of com.taobao.weex.ui.component.AppearanceHelper 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);
}
}
Aggregations