This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/iOS/Pod/Classes/Shader/DoricScrollerNode.m

123 lines
3.5 KiB
Mathematica
Raw Normal View History

2019-11-19 14:56:25 +08:00
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2019-11-19 16:23:51 +08:00
//
// DoricScrollerNode.m
// Doric
//
// Created by pengfei.zhou on 2019/11/19.
//
2019-11-19 11:21:49 +08:00
#import "DoricScrollerNode.h"
#import "DoricExtensions.h"
#import "DoricRefreshableNode.h"
2019-11-19 11:21:49 +08:00
@implementation DoricScrollView
2019-11-26 20:15:16 +08:00
- (void)setContentView:(UIView *)contentView {
if (_contentView) {
[_contentView removeFromSuperview];
}
_contentView = contentView;
[self addSubview:contentView];
}
2019-11-19 11:21:49 +08:00
- (CGSize)sizeThatFits:(CGSize)size {
2019-11-26 20:15:16 +08:00
if (self.contentView) {
2019-11-27 16:04:43 +08:00
return [self.contentView sizeThatFits:size];
2019-11-19 11:21:49 +08:00
}
return CGSizeZero;
}
2019-11-27 16:04:43 +08:00
- (void)layoutSelf:(CGSize)targetSize {
[super layoutSelf:targetSize];
[self setContentSize:self.contentView.frame.size];
}
2019-11-27 16:41:04 +08:00
2019-11-19 11:21:49 +08:00
@end
@interface DoricScrollerNode ()
@property(nonatomic, strong) DoricViewNode *childNode;
@property(nonatomic, copy) NSString *childViewId;
@end
@implementation DoricScrollerNode
2019-11-26 20:15:16 +08:00
- (DoricScrollView *)build {
2019-11-19 11:21:49 +08:00
return [DoricScrollView new];
}
- (void)initWithSuperNode:(DoricSuperNode *)superNode {
[super initWithSuperNode:superNode];
if ([superNode isKindOfClass:[DoricRefreshableNode class]]) {
self.view.bounces = NO;
}
}
2019-11-19 11:21:49 +08:00
- (void)blend:(NSDictionary *)props {
[super blend:props];
NSDictionary *childModel = [self subModelOf:self.childViewId];
if (!childModel) {
return;
}
NSString *viewId = childModel[@"id"];
NSString *type = childModel[@"type"];
NSDictionary *childProps = childModel[@"props"];
if (self.childNode) {
if ([self.childNode.viewId isEqualToString:viewId]) {
//skip
} else {
if (self.reusable && [type isEqualToString:self.childNode.type]) {
[self.childNode also:^(DoricViewNode *it) {
it.viewId = viewId;
[it blend:childProps];
}];
} else {
self.childNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) {
it.viewId = viewId;
[it initWithSuperNode:self];
[it blend:childProps];
2019-11-26 20:15:16 +08:00
self.view.contentView = it.view;
2019-11-19 11:21:49 +08:00
}];
}
}
} else {
self.childNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) {
it.viewId = viewId;
[it initWithSuperNode:self];
[it blend:childProps];
2019-11-26 20:15:16 +08:00
self.view.contentView = it.view;
2019-11-19 11:21:49 +08:00
}];
}
}
2019-11-26 21:25:23 +08:00
- (void)blendView:(DoricScrollView *)view forPropName:(NSString *)name propValue:(id)prop {
2019-11-19 11:21:49 +08:00
if ([@"content" isEqualToString:name]) {
self.childViewId = prop;
} else {
[super blendView:view forPropName:name propValue:prop];
}
}
- (void)blendSubNode:(NSDictionary *)subModel {
[self.childNode blend:subModel[@"props"]];
2019-11-19 11:21:49 +08:00
}
2019-11-27 10:19:25 +08:00
- (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
if ([viewId isEqualToString:self.childViewId]) {
return self.childNode;
}
return nil;
}
2019-11-26 21:25:23 +08:00
@end