feat:rename collcetion to flowlayout
This commit is contained in:
parent
f2b4ba23c4
commit
0031d7a17d
@ -13,5 +13,5 @@ export default [
|
|||||||
'src/NavigatorDemo',
|
'src/NavigatorDemo',
|
||||||
'src/NavbarDemo',
|
'src/NavbarDemo',
|
||||||
'src/RefreshableDemo',
|
'src/RefreshableDemo',
|
||||||
'src/CollectionDemo',
|
'src/FlowLayoutDemo',
|
||||||
]
|
]
|
@ -1,4 +1,4 @@
|
|||||||
import { Group, Panel, collection, layoutConfig, CollectionItem, } from "doric";
|
import { Group, Panel, flowlayout, layoutConfig, FlowLayoutItem } from "doric";
|
||||||
import { colors, label } from "./utils";
|
import { colors, label } from "./utils";
|
||||||
|
|
||||||
const imageUrls = [
|
const imageUrls = [
|
||||||
@ -13,16 +13,16 @@ const imageUrls = [
|
|||||||
'https://misc.aotu.io/ONE-SUNDAY/SteamEngine.png',
|
'https://misc.aotu.io/ONE-SUNDAY/SteamEngine.png',
|
||||||
]
|
]
|
||||||
@Entry
|
@Entry
|
||||||
class CollectionDemo extends Panel {
|
class FlowDemo extends Panel {
|
||||||
build(rootView: Group): void {
|
build(rootView: Group): void {
|
||||||
collection({
|
flowlayout({
|
||||||
layoutConfig: layoutConfig().atmost(),
|
layoutConfig: layoutConfig().atmost(),
|
||||||
itemCount: 50,
|
itemCount: 500,
|
||||||
renderItem: (idx) => {
|
renderItem: (idx) => {
|
||||||
return new CollectionItem().apply({
|
return new FlowLayoutItem().apply({
|
||||||
bgColor: colors[idx % colors.length],
|
bgColor: colors[idx % colors.length],
|
||||||
width: 70 + idx,
|
width: 200,
|
||||||
height: 70 + idx,
|
height: 50 + idx * 10,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
@ -38,8 +38,8 @@
|
|||||||
#import "DoricNavigatorPlugin.h"
|
#import "DoricNavigatorPlugin.h"
|
||||||
#import "DoricNavBarPlugin.h"
|
#import "DoricNavBarPlugin.h"
|
||||||
#import "DoricRefreshableNode.h"
|
#import "DoricRefreshableNode.h"
|
||||||
#import "DoricCollectionItemNode.h"
|
#import "DoricFlowLayoutItemNode.h"
|
||||||
#import "DoricCollectionNode.h"
|
#import "DoricFlowLayoutNode.h"
|
||||||
|
|
||||||
@interface DoricRegistry ()
|
@interface DoricRegistry ()
|
||||||
|
|
||||||
@ -80,8 +80,8 @@ - (void)innerRegister {
|
|||||||
[self registerViewNode:DoricSliderNode.class withName:@"Slider"];
|
[self registerViewNode:DoricSliderNode.class withName:@"Slider"];
|
||||||
[self registerViewNode:DoricSlideItemNode.class withName:@"SlideItem"];
|
[self registerViewNode:DoricSlideItemNode.class withName:@"SlideItem"];
|
||||||
[self registerViewNode:DoricRefreshableNode.class withName:@"Refreshable"];
|
[self registerViewNode:DoricRefreshableNode.class withName:@"Refreshable"];
|
||||||
[self registerViewNode:DoricCollectionItemNode.class withName:@"CollectionItem"];
|
[self registerViewNode:DoricFlowLayoutItemNode.class withName:@"FlowLayoutItem"];
|
||||||
[self registerViewNode:DoricCollectionNode.class withName:@"Collection"];
|
[self registerViewNode:DoricFlowLayoutNode.class withName:@"FlowLayout"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)registerJSBundle:(NSString *)bundle withName:(NSString *)name {
|
- (void)registerJSBundle:(NSString *)bundle withName:(NSString *)name {
|
||||||
|
@ -6,5 +6,5 @@
|
|||||||
#import "DoricStackNode.h"
|
#import "DoricStackNode.h"
|
||||||
|
|
||||||
|
|
||||||
@interface DoricCollectionItemNode : DoricStackNode
|
@interface DoricFlowLayoutItemNode : DoricStackNode
|
||||||
@end
|
@end
|
@ -2,19 +2,19 @@
|
|||||||
// Created by pengfei.zhou on 2019/11/28.
|
// Created by pengfei.zhou on 2019/11/28.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "DoricCollectionItemNode.h"
|
#import "DoricFlowLayoutItemNode.h"
|
||||||
|
|
||||||
@interface DoricCollectionItemView : DoricStackView
|
@interface DoricFlowLayoutItemView : DoricStackView
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation DoricCollectionItemView
|
@implementation DoricFlowLayoutItemView
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface DoricCollectionItemNode ()
|
@interface DoricFlowLayoutItemNode ()
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation DoricCollectionItemNode
|
@implementation DoricFlowLayoutItemNode
|
||||||
- (instancetype)initWithContext:(DoricContext *)doricContext {
|
- (instancetype)initWithContext:(DoricContext *)doricContext {
|
||||||
if (self = [super initWithContext:doricContext]) {
|
if (self = [super initWithContext:doricContext]) {
|
||||||
self.reusable = YES;
|
self.reusable = YES;
|
||||||
@ -28,6 +28,6 @@ - (void)initWithSuperNode:(DoricSuperNode *)superNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (DoricStackView *)build {
|
- (DoricStackView *)build {
|
||||||
return [DoricCollectionItemView new];
|
return [DoricFlowLayoutItemView new];
|
||||||
}
|
}
|
||||||
@end
|
@end
|
@ -5,5 +5,5 @@
|
|||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "DoricSuperNode.h"
|
#import "DoricSuperNode.h"
|
||||||
|
|
||||||
@interface DoricCollectionNode : DoricSuperNode<UICollectionView *>
|
@interface DoricFlowLayoutNode : DoricSuperNode<UICollectionView *>
|
||||||
@end
|
@end
|
@ -2,22 +2,22 @@
|
|||||||
// Created by pengfei.zhou on 2019/11/28.
|
// Created by pengfei.zhou on 2019/11/28.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "DoricCollectionNode.h"
|
#import "DoricFlowLayoutNode.h"
|
||||||
#import "DoricCollectionItemNode.h"
|
#import "DoricFlowLayoutItemNode.h"
|
||||||
#import "DoricExtensions.h"
|
#import "DoricExtensions.h"
|
||||||
#import <JavaScriptCore/JavaScriptCore.h>
|
#import <JavaScriptCore/JavaScriptCore.h>
|
||||||
|
|
||||||
@interface DoricCollectionViewCell : UICollectionViewCell
|
@interface DoricFlowLayoutViewCell : UICollectionViewCell
|
||||||
@property(nonatomic, strong) DoricCollectionItemNode *viewNode;
|
@property(nonatomic, strong) DoricFlowLayoutItemNode *viewNode;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation DoricCollectionViewCell
|
@implementation DoricFlowLayoutViewCell
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface DoricCollectionView : UICollectionView
|
@interface DoricFlowLayoutView : UICollectionView
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation DoricCollectionView
|
@implementation DoricFlowLayoutView
|
||||||
- (CGSize)sizeThatFits:(CGSize)size {
|
- (CGSize)sizeThatFits:(CGSize)size {
|
||||||
if (self.subviews.count > 0) {
|
if (self.subviews.count > 0) {
|
||||||
CGFloat width = size.width;
|
CGFloat width = size.width;
|
||||||
@ -38,17 +38,18 @@ - (void)layoutSelf:(CGSize)targetSize {
|
|||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface DoricCollectionNode () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
@interface DoricFlowLayoutNode () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
||||||
@property(nonatomic, strong) NSMutableDictionary <NSNumber *, NSString *> *itemViewIds;
|
@property(nonatomic, strong) NSMutableDictionary <NSNumber *, NSString *> *itemViewIds;
|
||||||
@property(nonatomic, strong) NSMutableDictionary <NSNumber *, NSValue *> *itemSizeInfo;
|
@property(nonatomic, strong) NSMutableDictionary <NSNumber *, NSValue *> *itemSizeInfo;
|
||||||
@property(nonatomic, assign) NSUInteger itemCount;
|
@property(nonatomic, assign) NSUInteger itemCount;
|
||||||
@property(nonatomic, assign) NSUInteger batchCount;
|
@property(nonatomic, assign) NSUInteger batchCount;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation DoricCollectionNode
|
@implementation DoricFlowLayoutNode
|
||||||
- (instancetype)initWithContext:(DoricContext *)doricContext {
|
- (instancetype)initWithContext:(DoricContext *)doricContext {
|
||||||
if (self = [super initWithContext:doricContext]) {
|
if (self = [super initWithContext:doricContext]) {
|
||||||
_itemViewIds = [NSMutableDictionary new];
|
_itemViewIds = [NSMutableDictionary new];
|
||||||
|
_itemSizeInfo = [NSMutableDictionary new];
|
||||||
_batchCount = 15;
|
_batchCount = 15;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@ -58,14 +59,14 @@ - (UICollectionView *)build {
|
|||||||
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
|
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
|
||||||
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
|
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
|
||||||
|
|
||||||
return [[[DoricCollectionView alloc] initWithFrame:CGRectZero
|
return [[[DoricFlowLayoutView alloc] initWithFrame:CGRectZero
|
||||||
collectionViewLayout:flowLayout]
|
collectionViewLayout:flowLayout]
|
||||||
also:^(UICollectionView *it) {
|
also:^(UICollectionView *it) {
|
||||||
it.backgroundColor = [UIColor whiteColor];
|
it.backgroundColor = [UIColor whiteColor];
|
||||||
it.pagingEnabled = YES;
|
it.pagingEnabled = YES;
|
||||||
it.delegate = self;
|
it.delegate = self;
|
||||||
it.dataSource = self;
|
it.dataSource = self;
|
||||||
[it registerClass:[DoricCollectionViewCell class] forCellWithReuseIdentifier:@"doricCell"];
|
[it registerClass:[DoricFlowLayoutViewCell class] forCellWithReuseIdentifier:@"doricCell"];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,8 +107,8 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
|
|||||||
__block DoricViewNode *ret = nil;
|
__block DoricViewNode *ret = nil;
|
||||||
[self.doricContext.driver ensureSyncInMainQueue:^{
|
[self.doricContext.driver ensureSyncInMainQueue:^{
|
||||||
for (UICollectionViewCell *collectionViewCell in self.view.visibleCells) {
|
for (UICollectionViewCell *collectionViewCell in self.view.visibleCells) {
|
||||||
if ([collectionViewCell isKindOfClass:[DoricCollectionViewCell class]]) {
|
if ([collectionViewCell isKindOfClass:[DoricFlowLayoutViewCell class]]) {
|
||||||
DoricCollectionItemNode *node = ((DoricCollectionViewCell *) collectionViewCell).viewNode;
|
DoricFlowLayoutItemNode *node = ((DoricFlowLayoutViewCell *) collectionViewCell).viewNode;
|
||||||
if ([viewId isEqualToString:node.viewId]) {
|
if ([viewId isEqualToString:node.viewId]) {
|
||||||
ret = node;
|
ret = node;
|
||||||
break;
|
break;
|
||||||
@ -159,14 +160,14 @@ - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collection
|
|||||||
NSUInteger position = (NSUInteger) indexPath.row;
|
NSUInteger position = (NSUInteger) indexPath.row;
|
||||||
NSDictionary *model = [self itemModelAt:position];
|
NSDictionary *model = [self itemModelAt:position];
|
||||||
NSDictionary *props = model[@"props"];
|
NSDictionary *props = model[@"props"];
|
||||||
DoricCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"doricCell" forIndexPath:indexPath];
|
DoricFlowLayoutViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"doricCell" forIndexPath:indexPath];
|
||||||
if (!cell.viewNode) {
|
if (!cell.viewNode) {
|
||||||
DoricCollectionItemNode *itemNode = [[DoricCollectionItemNode alloc] initWithContext:self.doricContext];
|
DoricFlowLayoutItemNode *itemNode = [[DoricFlowLayoutItemNode alloc] initWithContext:self.doricContext];
|
||||||
[itemNode initWithSuperNode:self];
|
[itemNode initWithSuperNode:self];
|
||||||
cell.viewNode = itemNode;
|
cell.viewNode = itemNode;
|
||||||
[cell.contentView addSubview:itemNode.view];
|
[cell.contentView addSubview:itemNode.view];
|
||||||
}
|
}
|
||||||
DoricCollectionItemNode *node = cell.viewNode;
|
DoricFlowLayoutItemNode *node = cell.viewNode;
|
||||||
node.viewId = model[@"id"];
|
node.viewId = model[@"id"];
|
||||||
[node blend:props];
|
[node blend:props];
|
||||||
CGSize size = [node.view measureSize:CGSizeMake(collectionView.width, collectionView.height)];
|
CGSize size = [node.view measureSize:CGSizeMake(collectionView.width, collectionView.height)];
|
||||||
@ -185,4 +186,11 @@ - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@end
|
@ -17,31 +17,36 @@ import { Stack } from './layouts'
|
|||||||
import { Property, IView, Superview, View } from '../ui/view'
|
import { Property, IView, Superview, View } from '../ui/view'
|
||||||
import { layoutConfig } from '../util/index.util'
|
import { layoutConfig } from '../util/index.util'
|
||||||
|
|
||||||
export class CollectionItem extends Stack {
|
export class FlowLayoutItem extends Stack {
|
||||||
/**
|
/**
|
||||||
* Set to reuse native view
|
* Set to reuse native view
|
||||||
*/
|
*/
|
||||||
@Property
|
@Property
|
||||||
identifier?: string
|
identifier?: string
|
||||||
}
|
}
|
||||||
export interface ICollection extends IView {
|
export interface IFlowLayout extends IView {
|
||||||
renderItem: (index: number) => CollectionItem
|
renderItem: (index: number) => FlowLayoutItem
|
||||||
itemCount: number
|
itemCount: number
|
||||||
batchCount?: number
|
batchCount?: number
|
||||||
|
column?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Collection extends Superview implements ICollection {
|
export class FlowLayout extends Superview implements IFlowLayout {
|
||||||
private cachedViews: Map<string, CollectionItem> = new Map
|
private cachedViews: Map<string, FlowLayoutItem> = new Map
|
||||||
private ignoreDirtyCallOnce = false
|
private ignoreDirtyCallOnce = false
|
||||||
|
|
||||||
allSubviews() {
|
allSubviews() {
|
||||||
return this.cachedViews.values()
|
return this.cachedViews.values()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Property
|
||||||
|
column = 1
|
||||||
|
|
||||||
@Property
|
@Property
|
||||||
itemCount = 0
|
itemCount = 0
|
||||||
|
|
||||||
@Property
|
@Property
|
||||||
renderItem!: (index: number) => CollectionItem
|
renderItem!: (index: number) => FlowLayoutItem
|
||||||
|
|
||||||
@Property
|
@Property
|
||||||
batchCount = 15
|
batchCount = 15
|
||||||
@ -78,16 +83,16 @@ export class Collection extends Superview implements ICollection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function collection(config: ICollection) {
|
export function flowlayout(config: IFlowLayout) {
|
||||||
const ret = new Collection
|
const ret = new FlowLayout
|
||||||
for (let key in config) {
|
for (let key in config) {
|
||||||
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
|
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
export function collectionItem(item: View) {
|
export function flowItem(item: View) {
|
||||||
return (new CollectionItem).also((it) => {
|
return (new FlowLayoutItem).also((it) => {
|
||||||
it.layoutConfig = layoutConfig().wrap()
|
it.layoutConfig = layoutConfig().wrap()
|
||||||
it.addChild(item)
|
it.addChild(item)
|
||||||
})
|
})
|
@ -20,4 +20,4 @@ export * from './list'
|
|||||||
export * from './slider'
|
export * from './slider'
|
||||||
export * from './scroller'
|
export * from './scroller'
|
||||||
export * from './refreshable'
|
export * from './refreshable'
|
||||||
export * from './collection'
|
export * from './flowlayout'
|
Reference in New Issue
Block a user