FlowLayoutItem add fullSpan attribute

This commit is contained in:
pengfei.zhou 2021-10-11 16:26:56 +08:00 committed by osborn
parent 9429c75834
commit 0e77c62e13
13 changed files with 53 additions and 5 deletions

View File

@ -69,7 +69,8 @@ class FlowAdapter extends RecyclerView.Adapter<FlowAdapter.DoricViewHolder> {
holder.flowLayoutItemNode.setId(jsObject.getProperty("id").asString().value());
holder.flowLayoutItemNode.blend(jsObject.getProperty("props").asObject());
}
if ((this.flowLayoutNode.hasHeader() && position == 0)
if (holder.flowLayoutItemNode.fullSpan
|| (this.flowLayoutNode.hasHeader() && position == 0)
|| (this.flowLayoutNode.hasFooter() && position == this.getItemCount() - 1)
|| this.flowLayoutNode.loadMore
&& position == this.itemCount + (this.flowLayoutNode.hasHeader() ? 1 : 0)) {

View File

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

View File

@ -41,6 +41,10 @@ class FlowDemo extends Panel {
backgroundColor: colors[idx % colors.length],
height: 50 + (idx % 3) * 20,
layoutConfig: layoutConfig().configWidth(LayoutSpec.MOST),
}).also(it => {
if (idx == 15) {
it.fullSpan = true
}
})
},
loadMore: true,

View File

@ -401,7 +401,8 @@ - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collection
DoricFlowLayoutItemNode *node = cell.viewNode;
node.viewId = model[@"id"];
[node blend:props];
BOOL fillWidth = (self.hasHeader && position == 0)
BOOL fillWidth = [props[@"fullSpan"] boolValue]
|| (self.hasHeader && position == 0)
|| (self.hasFooter
&& position == self.itemCount
+ (self.loadMore ? 1 : 0)
@ -456,7 +457,7 @@ - (NSInteger)doricFlowLayoutColumnCount {
- (BOOL)doricFlowLayoutItemFullSpan:(NSIndexPath *)indexPath {
NSUInteger position = (NSUInteger) indexPath.row;
return (self.hasHeader && position == 0)
if ((self.hasHeader && position == 0)
|| (self.hasFooter
&& position == self.itemCount
+ (self.loadMore ? 1 : 0)
@ -464,7 +465,12 @@ - (BOOL)doricFlowLayoutItemFullSpan:(NSIndexPath *)indexPath {
+ (self.hasFooter ? 1 : 0)
- 1)
|| (self.loadMore
&& position == self.itemCount + (self.hasHeader ? 1 : 0));
&& position == self.itemCount + (self.hasHeader ? 1 : 0))) {
return YES;
} else {
NSDictionary *model = [self itemModelAt:position];
return [model[@"props"][@"fullSpan"] boolValue];
}
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

View File

@ -2931,6 +2931,10 @@ var FlowLayoutItem = /** @class */ (function (_super) {
Property,
__metadata$5("design:type", String)
], FlowLayoutItem.prototype, "identifier", void 0);
__decorate$5([
Property,
__metadata$5("design:type", Boolean)
], FlowLayoutItem.prototype, "fullSpan", void 0);
return FlowLayoutItem;
}(Stack));
var FlowLayout = /** @class */ (function (_super) {

View File

@ -2211,6 +2211,10 @@ __decorate$5([
Property,
__metadata$5("design:type", String)
], FlowLayoutItem.prototype, "identifier", void 0);
__decorate$5([
Property,
__metadata$5("design:type", Boolean)
], FlowLayoutItem.prototype, "fullSpan", void 0);
class FlowLayout extends Superview {
constructor() {
super(...arguments);

View File

@ -3732,6 +3732,10 @@ __decorate$5([
Property,
__metadata$5("design:type", String)
], FlowLayoutItem.prototype, "identifier", void 0);
__decorate$5([
Property,
__metadata$5("design:type", Boolean)
], FlowLayoutItem.prototype, "fullSpan", void 0);
class FlowLayout extends Superview {
constructor() {
super(...arguments);

4
doric-js/index.d.ts vendored
View File

@ -835,6 +835,10 @@ declare module 'doric/lib/src/widget/flowlayout' {
* Set to reuse native view
*/
identifier?: string;
/**
* When set to true, the item will layout using all span area.
*/
fullSpan?: boolean;
}
export class FlowLayout extends Superview {
allSubviews(): FlowLayoutItem[];

View File

@ -5,6 +5,10 @@ export declare class FlowLayoutItem extends Stack {
* Set to reuse native view
*/
identifier?: string;
/**
* When set to true, the item will layout using all span area.
*/
fullSpan?: boolean;
}
export declare class FlowLayout extends Superview {
private cachedViews;

View File

@ -31,6 +31,10 @@ __decorate([
Property,
__metadata("design:type", String)
], FlowLayoutItem.prototype, "identifier", void 0);
__decorate([
Property,
__metadata("design:type", Boolean)
], FlowLayoutItem.prototype, "fullSpan", void 0);
export class FlowLayout extends Superview {
constructor() {
super(...arguments);

View File

@ -23,6 +23,12 @@ export class FlowLayoutItem extends Stack {
*/
@Property
identifier?: string
/**
* When set to true, the item will layout using all span area.
* HeaderView, footerView or loadMoreView is always true by default.
*/
@Property
fullSpan?: boolean
}
export class FlowLayout extends Superview {

View File

@ -3786,6 +3786,10 @@ __decorate$5([
Property,
__metadata$5("design:type", String)
], FlowLayoutItem.prototype, "identifier", void 0);
__decorate$5([
Property,
__metadata$5("design:type", Boolean)
], FlowLayoutItem.prototype, "fullSpan", void 0);
class FlowLayout extends Superview {
constructor() {
super(...arguments);

File diff suppressed because one or more lines are too long