iOS SwipeLayout
This commit is contained in:
@@ -94,4 +94,8 @@ typedef NS_ENUM(NSInteger, DoricGravity) {
|
||||
@property(nonatomic, copy) NSString *tagString;
|
||||
|
||||
- (UIView *)viewWithTagString:(NSString *)tagString;
|
||||
|
||||
- (CGSize)targetLayoutSize;
|
||||
|
||||
- (void)layoutSelf;
|
||||
@end
|
||||
|
@@ -70,7 +70,7 @@ - (void)layoutSubviews {
|
||||
if ([self.superview isKindOfClass:[DoricLayoutContainer class]]) {
|
||||
[self.superview layoutSubviews];
|
||||
} else {
|
||||
CGSize size = [self sizeThatFits:CGSizeMake(self.superview.width, self.superview.height)];
|
||||
CGSize size = [self sizeThatFits:self.targetLayoutSize];
|
||||
[self layout:size];
|
||||
}
|
||||
}
|
||||
@@ -160,6 +160,8 @@ - (CGSize)sizeContent:(CGSize)size {
|
||||
}
|
||||
|
||||
- (void)layout:(CGSize)targetSize {
|
||||
self.width = targetSize.width;
|
||||
self.height = targetSize.height;
|
||||
for (UIView *child in self.subviews) {
|
||||
if (child.isHidden) {
|
||||
continue;
|
||||
@@ -223,8 +225,6 @@ - (void)layout:(CGSize)targetSize {
|
||||
[(DoricLayoutContainer *) child layout:size];
|
||||
}
|
||||
}
|
||||
self.width = targetSize.width;
|
||||
self.height = targetSize.height;
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -278,6 +278,8 @@ - (CGSize)sizeContent:(CGSize)size {
|
||||
}
|
||||
|
||||
- (void)layout:(CGSize)targetSize {
|
||||
self.width = targetSize.width;
|
||||
self.height = targetSize.height;
|
||||
CGFloat yStart = 0;
|
||||
if ((self.gravity & TOP) == TOP) {
|
||||
yStart = 0;
|
||||
@@ -350,8 +352,6 @@ - (void)layout:(CGSize)targetSize {
|
||||
[(DoricLayoutContainer *) child layout:size];
|
||||
}
|
||||
}
|
||||
self.width = targetSize.width;
|
||||
self.height = targetSize.height;
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -403,6 +403,8 @@ - (CGSize)sizeContent:(CGSize)size {
|
||||
}
|
||||
|
||||
- (void)layout:(CGSize)targetSize {
|
||||
self.width = targetSize.width;
|
||||
self.height = targetSize.height;
|
||||
CGFloat xStart = 0;
|
||||
if (self.contentWeight) {
|
||||
xStart = 0;
|
||||
@@ -477,8 +479,6 @@ - (void)layout:(CGSize)targetSize {
|
||||
[(DoricLayoutContainer *) child layout:size];
|
||||
}
|
||||
}
|
||||
self.width = targetSize.width;
|
||||
self.height = targetSize.height;
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -511,6 +511,33 @@ - (UIView *)viewWithTagString:(NSString *)tagString {
|
||||
return [self viewWithTag:[tagString hash]];
|
||||
}
|
||||
|
||||
- (CGSize)targetLayoutSize {
|
||||
CGFloat width = self.width;
|
||||
CGFloat height = self.height;
|
||||
if (self.layoutConfig.widthSpec == DoricLayoutAtMost
|
||||
|| self.layoutConfig.widthSpec == DoricLayoutWrapContent) {
|
||||
width = self.superview.width;
|
||||
}
|
||||
if (self.layoutConfig.heightSpec == DoricLayoutAtMost
|
||||
|| self.layoutConfig.widthSpec == DoricLayoutWrapContent) {
|
||||
height = self.superview.height;
|
||||
}
|
||||
return CGSizeMake(width, height);
|
||||
}
|
||||
|
||||
- (void)layoutSelf {
|
||||
CGSize contentSize = [self sizeThatFits:self.targetLayoutSize];
|
||||
if (self.layoutConfig.widthSpec == DoricLayoutAtMost) {
|
||||
self.width = self.superview.width;
|
||||
} else if (self.layoutConfig.widthSpec == DoricLayoutWrapContent) {
|
||||
self.width = contentSize.width;
|
||||
}
|
||||
if (self.layoutConfig.heightSpec == DoricLayoutAtMost) {
|
||||
self.height = self.superview.height;
|
||||
} else if (self.layoutConfig.heightSpec == DoricLayoutWrapContent) {
|
||||
self.height = contentSize.height;
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
DoricVLayoutView *vLayout(NSArray <__kindof UIView *> *views) {
|
||||
|
@@ -22,5 +22,9 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricSuperNode.h"
|
||||
|
||||
@interface DoricScrollerNode : DoricSuperNode<UIScrollView *>
|
||||
@interface DoricScrollView : UIScrollView
|
||||
@property(nonatomic, strong) UIView *contentView;
|
||||
@end
|
||||
|
||||
@interface DoricScrollerNode : DoricSuperNode<DoricScrollView *>
|
||||
@end
|
@@ -22,19 +22,25 @@
|
||||
#import "DoricScrollerNode.h"
|
||||
#import "DoricExtensions.h"
|
||||
|
||||
@interface DoricScrollView : UIScrollView
|
||||
@end
|
||||
|
||||
@implementation DoricScrollView
|
||||
|
||||
- (void)setContentView:(UIView *)contentView {
|
||||
if (_contentView) {
|
||||
[_contentView removeFromSuperview];
|
||||
}
|
||||
_contentView = contentView;
|
||||
[self addSubview:contentView];
|
||||
}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
[self layoutSelf];
|
||||
[self.contentView layoutSubviews];
|
||||
}
|
||||
|
||||
- (CGSize)sizeThatFits:(CGSize)size {
|
||||
if (self.subviews.count > 0) {
|
||||
UIView *child = self.subviews[0];
|
||||
CGSize childSize = [child sizeThatFits:size];
|
||||
if (self.contentView) {
|
||||
CGSize childSize = [self.contentView sizeThatFits:size];
|
||||
return CGSizeMake(MIN(size.width, childSize.width), MIN(size.height, childSize.height));
|
||||
}
|
||||
return CGSizeZero;
|
||||
@@ -47,7 +53,7 @@ @interface DoricScrollerNode ()
|
||||
@end
|
||||
|
||||
@implementation DoricScrollerNode
|
||||
- (UIScrollView *)build {
|
||||
- (DoricScrollView *)build {
|
||||
return [DoricScrollView new];
|
||||
}
|
||||
|
||||
@@ -70,12 +76,11 @@ - (void)blend:(NSDictionary *)props {
|
||||
[it blend:childProps];
|
||||
}];
|
||||
} else {
|
||||
[self.childNode.view removeFromSuperview];
|
||||
self.childNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) {
|
||||
it.viewId = viewId;
|
||||
[it initWithSuperNode:self];
|
||||
[it blend:childProps];
|
||||
[self.view addSubview:it.view];
|
||||
self.view.contentView = it.view;
|
||||
}];
|
||||
}
|
||||
}
|
||||
@@ -84,13 +89,12 @@ - (void)blend:(NSDictionary *)props {
|
||||
it.viewId = viewId;
|
||||
[it initWithSuperNode:self];
|
||||
[it blend:childProps];
|
||||
[self.view addSubview:it.view];
|
||||
self.view.contentView = it.view;
|
||||
}];
|
||||
}
|
||||
[self.view also:^(UIScrollView *it) {
|
||||
if (it.subviews.count > 0) {
|
||||
UIView *child = it.subviews[0];
|
||||
CGSize size = [child sizeThatFits:it.frame.size];
|
||||
[self.view also:^(DoricScrollView *it) {
|
||||
if (it.contentView) {
|
||||
CGSize size = [it.contentView sizeThatFits:it.frame.size];
|
||||
[it setContentSize:size];
|
||||
}
|
||||
}];
|
||||
|
Reference in New Issue
Block a user