use of com.taobao.weex.ui.component.list.WXCell in project incubator-weex by apache.
the class WXRecyclerTemplateList method onBindViewHolder.
@Override
public void onBindViewHolder(final TemplateViewHolder templateViewHolder, int position) {
if (templateViewHolder == null) {
return;
}
WXCell component = templateViewHolder.getTemplate();
if (component == null) {
return;
}
long start = System.currentTimeMillis();
templateViewHolder.setHolderPosition(position);
Object data = cellDataManager.listData.get(position);
CellRenderState cellRenderState = cellDataManager.getRenderState(position);
if (component.getRenderData() == data && (cellRenderState == null || !cellRenderState.isDirty())) {
if (WXEnvironment.isOpenDebugLog() && ENABLE_TRACE_LOG) {
WXLogUtils.d(TAG, position + " position " + getTemplateKey(position) + " onBindViewHolder none data update ");
}
// none update just return
return;
} else {
List<WXComponent> updates = doRenderTemplate(component, position);
Statements.doInitCompontent(updates);
component.setRenderData(data);
Layouts.doLayoutAsync(templateViewHolder, true);
if (WXEnvironment.isOpenDebugLog() && ENABLE_TRACE_LOG) {
WXLogUtils.d(TAG, position + " position " + getTemplateKey(position) + " onBindViewHolder used " + (System.currentTimeMillis() - start));
}
}
}
use of com.taobao.weex.ui.component.list.WXCell 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.list.WXCell in project incubator-weex by apache.
the class WXRecyclerTemplateList method onCreateViewHolder.
@Override
public TemplateViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
String template = mTemplateViewTypes.keyAt(viewType);
WXCell source = mTemplateSources.get(template);
if (source == null) {
FrameLayout view = new FrameLayout(getContext());
view.setLayoutParams(new FrameLayout.LayoutParams(0, 0));
return new TemplateViewHolder(view, viewType);
}
WXCell component = getCellTemplateFromCache(template);
boolean cacheHit = true;
if (component == null) {
cacheHit = false;
if (!source.isSourceUsed()) {
source.setSourceUsed(true);
renderTemplateCellWithData(source);
component = source;
if (WXEnvironment.isOpenDebugLog() && ENABLE_TRACE_LOG) {
WXLogUtils.d(TAG, template + " onCreateViewHolder source");
}
}
}
if (component == null) {
long start = System.currentTimeMillis();
component = (WXCell) copyComponentFromSourceCell(source);
if (WXEnvironment.isOpenDebugLog() && ENABLE_TRACE_LOG) {
WXLogUtils.d(TAG, template + " onCreateViewHolder copy used " + (System.currentTimeMillis() - start));
}
}
if (component.isLazy()) {
doCreateCellViewBindData(component, template, false);
if (WXEnvironment.isOpenDebugLog() && ENABLE_TRACE_LOG) {
WXLogUtils.d(TAG, template + " onCreateViewHolder cache hit " + cacheHit + " view not idle init");
}
} else {
if (WXEnvironment.isOpenDebugLog() && ENABLE_TRACE_LOG) {
WXLogUtils.d(TAG, template + " onCreateViewHolder cache hit " + cacheHit + " view idle init");
}
}
TemplateViewHolder templateViewHolder = new TemplateViewHolder(component, viewType);
return templateViewHolder;
}
use of com.taobao.weex.ui.component.list.WXCell in project incubator-weex by apache.
the class WXRecyclerTemplateList method scrollTo.
@Override
public void scrollTo(WXComponent component, Map<String, Object> options) {
float offsetFloat = 0;
boolean smooth = true;
int position = -1;
int typeIndex = -1;
if (options != null) {
String offsetStr = options.get(Constants.Name.OFFSET) == null ? "0" : options.get(Constants.Name.OFFSET).toString();
smooth = WXUtils.getBoolean(options.get(Constants.Name.ANIMATED), true);
if (offsetStr != null) {
try {
offsetFloat = WXViewUtils.getRealPxByWidth(Float.parseFloat(offsetStr), getInstance().getInstanceViewPortWidth());
} catch (Exception e) {
WXLogUtils.e("Float parseFloat error :" + e.getMessage());
}
}
position = WXUtils.getNumberInt(options.get(Constants.Name.Recycler.CELL_INDEX), -1);
typeIndex = WXUtils.getNumberInt(options.get(Constants.Name.Recycler.TYPE_INDEX), -1);
}
WXCell cell = findCell(component);
if (typeIndex >= 0) {
if (cellDataManager.listData != null && component.getRef() != null) {
int typePosition = 0;
for (int i = 0; i < cellDataManager.listData.size(); i++) {
WXCell template = getSourceTemplate(i);
if (template == null) {
continue;
}
if (cell.getRef().equals(template.getRef())) {
typePosition++;
}
if (typePosition > typeIndex) {
position = i;
break;
}
}
if (position < 0) {
position = cellDataManager.listData.size() - 1;
}
}
}
final int offset = (int) offsetFloat;
BounceRecyclerView bounceRecyclerView = getHostView();
if (bounceRecyclerView == null) {
return;
}
if (position >= 0) {
final int pos = position;
final WXRecyclerView view = bounceRecyclerView.getInnerView();
view.scrollTo(smooth, pos, offset, getOrientation());
}
}
Aggregations