作者:圣菁振婷玉勇 | 来源:互联网 | 2023-09-14 15:35
list的实现使用的是RecyclerView,但getItemViewType返回的是dom的ref,ref在一个dom树里应该是唯一的;
1 2 3
| public int getItemViewType(int position) {
return generateViewType(getChild(position));
} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| 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;
} |