list的实现使用的是RecyclerView,但getItemViewType返回的是dom的ref,ref在一个dom树里应该是唯一的;
public int getItemViewType(int position) {
return generateViewType(getChild(position));
}
private int generateViewType(WXComponent component) {
long id;
try {
id = Integer.parseInt(component.getDomObject().getRef());
String type = component.getDomObject().getAttrs().getScope();
if (!TextUtils.isEmpty(type)) {
if (mRefToViewType == null) {
mRefToViewType = new ArrayMap<>();
}
if (!mRefToViewType.containsKey(type)) {
mRefToViewType.put(type, id);
}
id = mRefToViewType.get(type);
}
} catch (RuntimeException e) {
WXLogUtils.eTag(TAG, e);
id = RecyclerView.NO_ID;
WXLogUtils.e(TAG, "getItemViewType: NO ID, this will crash the whole render system of WXListRecyclerView");
}
return (int) id;
}
阿神2017-04-18 10:55:21
Reuse requires views of the same type.
According to the description, the type of each item is unique, that is, they are not the same thing. The code cannot tell whether it can be reused.
There should be confusion here. The unique identifier (id) required elsewhere is mixed with the type required by RecyclerView. If you want the Views of two Items to be shared, the types of the two Views should be the same (their IDs may be different)