iOS:fix Scroller

This commit is contained in:
pengfei.zhou 2020-04-03 18:15:43 +08:00 committed by osborn
parent 2e0bbcfb89
commit eb78e3e201
3 changed files with 29 additions and 24 deletions

View File

@ -95,6 +95,8 @@ typedef NS_ENUM(NSInteger, DoricGravity) {
- (instancetype)init; - (instancetype)init;
- (void)apply; - (void)apply;
- (void)apply:(CGSize)frameSize;
@end @end

View File

@ -69,16 +69,20 @@ - (instancetype)init {
return self; return self;
} }
- (void)apply { - (void)apply:(CGSize)frameSize {
if (!CGAffineTransformEqualToTransform(self.view.transform, CGAffineTransformIdentity)) { if (!CGAffineTransformEqualToTransform(self.view.transform, CGAffineTransformIdentity)) {
return; return;
} }
self.resolved = NO; self.resolved = NO;
[self measure:self.view.frame.size]; [self measure:frameSize];
[self layout]; [self layout];
[self setFrame]; [self setFrame];
} }
- (void)apply {
[self apply:self.view.frame.size];
}
- (void)measure:(CGSize)targetSize { - (void)measure:(CGSize)targetSize {
if (self.widthSpec == DoricLayoutMost) { if (self.widthSpec == DoricLayoutMost) {
self.measuredWidth = targetSize.width; self.measuredWidth = targetSize.width;
@ -433,7 +437,7 @@ - (void)layoutHLayout {
if ((gravity & DoricGravityTop) == DoricGravityTop) { if ((gravity & DoricGravityTop) == DoricGravityTop) {
layout.measuredY = self.paddingTop; layout.measuredY = self.paddingTop;
} else if ((gravity & DoricGravityBottom) == DoricGravityBottom) { } else if ((gravity & DoricGravityBottom) == DoricGravityBottom) {
layout.measuredY = self.measuredHeight - self.paddingBottom - child.height; layout.measuredY = self.measuredHeight - self.paddingBottom - layout.measuredHeight;
} else if ((gravity & DoricGravityCenterY) == DoricGravityCenterY) { } else if ((gravity & DoricGravityCenterY) == DoricGravityCenterY) {
layout.measuredY = self.measuredHeight / 2 - layout.measuredHeight / 2; layout.measuredY = self.measuredHeight / 2 - layout.measuredHeight / 2;
} else { } else {

View File

@ -27,26 +27,26 @@
@implementation DoricScrollView @implementation DoricScrollView
//- (void)setContentView:(UIView *)contentView { - (void)setContentView:(UIView *)contentView {
// if (_contentView) { if (_contentView) {
// [_contentView removeFromSuperview]; [_contentView removeFromSuperview];
// } }
// _contentView = contentView; _contentView = contentView;
// [self addSubview:contentView]; [self addSubview:contentView];
//} }
//
//- (CGSize)sizeThatFits:(CGSize)size {
// if (self.contentView) {
// return [self.contentView measureSize:size];
// }
// return CGSizeZero;
//}
//
//- (void)layoutSelf:(CGSize)targetSize {
// [super layoutSelf:targetSize];
// [self setContentSize:self.contentView.frame.size];
//}
- (CGSize)sizeThatFits:(CGSize)size {
if (self.contentView) {
[self.contentView.doricLayout apply:self.frame.size];
return self.contentView.frame.size;
}
return CGSizeZero;
}
- (void)layoutSubviews {
[super layoutSubviews];
self.contentSize = self.contentView.frame.size;
}
@end @end
@interface DoricScrollerNode () <UIScrollViewDelegate> @interface DoricScrollerNode () <UIScrollViewDelegate>
@ -77,8 +77,7 @@ - (void)initWithSuperNode:(DoricSuperNode *)superNode {
} }
} }
- (void)blend:(NSDictionary *)props { - (void)afterBlended:(NSDictionary *)props {
[super blend:props];
NSDictionary *childModel = [self subModelOf:self.childViewId]; NSDictionary *childModel = [self subModelOf:self.childViewId];
if (!childModel) { if (!childModel) {
return; return;