android: fix in flowlayout, the fullspaned item is being reused unproperly

This commit is contained in:
pengfei.zhou 2021-10-12 17:03:29 +08:00 committed by osborn
parent 6cae752456
commit eaaa2c457a
2 changed files with 10 additions and 8 deletions

View File

@ -62,16 +62,20 @@ class FlowAdapter extends RecyclerView.Adapter<FlowAdapter.DoricViewHolder> {
@Override @Override
public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) { public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) {
JSValue jsValue = getItemModel(position); JSValue jsValue = getItemModel(position);
boolean fullSpan = this.flowLayoutNode.loadMore && position >= this.itemCount;
if (jsValue != null && jsValue.isObject()) { if (jsValue != null && jsValue.isObject()) {
JSObject jsObject = jsValue.asObject(); JSObject jsObject = jsValue.asObject();
holder.flowLayoutItemNode.setId(jsObject.getProperty("id").asString().value()); holder.flowLayoutItemNode.setId(jsObject.getProperty("id").asString().value());
holder.flowLayoutItemNode.blend(jsObject.getProperty("props").asObject()); JSObject props = jsObject.getProperty("props").asObject();
holder.flowLayoutItemNode.blend(props);
JSValue fullSpanValue = props.getProperty("fullSpan");
if (fullSpanValue.isBoolean()) {
fullSpan = fullSpanValue.asBoolean().value();
} }
boolean fullSpan = this.flowLayoutNode.loadMore && position >= this.itemCount;
if (holder.flowLayoutItemNode.fullSpan != null) {
fullSpan = holder.flowLayoutItemNode.fullSpan;
} }
if (fullSpan) { if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
((StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams()).setFullSpan(fullSpan);
} else if (fullSpan) {
StaggeredGridLayoutManager.LayoutParams layoutParams = new StaggeredGridLayoutManager.LayoutParams( StaggeredGridLayoutManager.LayoutParams layoutParams = new StaggeredGridLayoutManager.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
holder.itemView.getLayoutParams().height holder.itemView.getLayoutParams().height

View File

@ -32,7 +32,6 @@ import pub.doric.shader.StackNode;
@DoricPlugin(name = "FlowLayoutItem") @DoricPlugin(name = "FlowLayoutItem")
public class FlowLayoutItemNode extends StackNode { public class FlowLayoutItemNode extends StackNode {
public String identifier = ""; public String identifier = "";
public Boolean fullSpan = null;
public FlowLayoutItemNode(DoricContext doricContext) { public FlowLayoutItemNode(DoricContext doricContext) {
super(doricContext); super(doricContext);
@ -44,7 +43,6 @@ public class FlowLayoutItemNode extends StackNode {
if ("identifier".equals(name)) { if ("identifier".equals(name)) {
this.identifier = prop.asString().value(); this.identifier = prop.asString().value();
} else if ("fullSpan".equals(name)) { } else if ("fullSpan".equals(name)) {
this.fullSpan = prop.asBoolean().value();
} else { } else {
super.blend(view, name, prop); super.blend(view, name, prop);
} }