iOS: Scroller support fit width or height

This commit is contained in:
pengfei.zhou
2022-08-25 14:19:08 +08:00
committed by osborn
parent 0c868f095d
commit 55efff976a
4 changed files with 114 additions and 49 deletions

View File

@@ -25,34 +25,6 @@
#import "DoricPromise.h"
#import "DoricJSDispatcher.h"
@implementation DoricScrollView
- (void)setContentView:(UIView *)contentView {
if (_contentView) {
[_contentView removeFromSuperview];
}
_contentView = contentView;
[self addSubview:contentView];
}
- (CGSize)sizeThatFits:(CGSize)size {
if (self.contentView) {
if (!self.contentView.doricLayout.resolved) {
[self.contentView.doricLayout apply:size];
}
return CGSizeMake(
self.contentView.doricLayout.measuredWidth,
self.contentView.doricLayout.measuredHeight);
}
return CGSizeZero;
}
- (void)layoutSubviews {
[super layoutSubviews];
self.contentSize = self.contentView.frame.size;
}
@end
@interface DoricScrollerNode () <UIScrollViewDelegate>
@property(nonatomic, strong) DoricViewNode *childNode;
@property(nonatomic, copy) NSString *childViewId;
@@ -71,6 +43,7 @@ - (DoricScrollView *)build {
if (@available(iOS 11, *)) {
it.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
it.doricLayout.layoutType = DoricScroller;
}];
}
@@ -123,7 +96,6 @@ - (void)afterBlended:(NSDictionary *)props {
- (void)requestLayout {
[self.childNode requestLayout];
[self.view.contentView.doricLayout apply:self.view.frame.size];
[super requestLayout];
}