blob: dbfe3dc2d240127129d8f7dab0eb98fc12c796e5 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
#import "WXHeaderComponent.h"
#import "WXComponent_internal.h"
@implementation WXHeaderComponent
{
BOOL _isUseContainerWidth;
}
- (instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDictionary *)styles attributes:(NSDictionary *)attributes events:(NSArray *)events weexInstance:(WXSDKInstance *)weexInstance
{
self = [super initWithRef:ref type:type styles:styles attributes:attributes events:events weexInstance:weexInstance];
if (self) {
_async = YES;
_isNeedJoinLayoutSystem = NO;
_keepScrollPosition = attributes[@"keepScrollPosition"] ? [WXConvert BOOL:attributes[@"keepScrollPosition"]] : NO;
}
return self;
}
- (void)updateAttributes:(NSDictionary *)attributes
{
if (attributes[@"keepScrollPosition"]) {
_keepScrollPosition = [WXConvert BOOL:attributes[@"keepScrollPosition"]];
}
}
- (BOOL)isSticky
{
return _positionType == WXPositionTypeSticky;
}
- (void)_frameDidCalculated:(BOOL)isChanged
{
[super _frameDidCalculated:isChanged];
if (isChanged) {
[self.delegate headerDidLayout:self];
}
}
- (void)_removeFromSupercomponent
{
[super _removeFromSupercomponent];
[self.delegate headerDidRemove:self];
}
- (void)_calculateFrameWithSuperAbsolutePosition:(CGPoint)superAbsolutePosition gatherDirtyComponents:(NSMutableSet<WXComponent *> *)dirtyComponents
{
if (self.delegate && (isUndefined(self.cssNode->style.dimensions[CSS_WIDTH]) || _isUseContainerWidth)) {
self.cssNode->style.dimensions[CSS_WIDTH] = [self.delegate headerWidthForLayout:self];
//TODO: set _isUseContainerWidth to NO if updateStyles have width
_isUseContainerWidth = YES;
}
if ([self needsLayout]) {
layoutNode(self.cssNode, CSS_UNDEFINED, CSS_UNDEFINED, CSS_DIRECTION_INHERIT);
if ([WXLog logLevel] >= WXLogLevelDebug) {
print_css_node(self.cssNode, CSS_PRINT_LAYOUT | CSS_PRINT_STYLE | CSS_PRINT_CHILDREN);
}
}
[super _calculateFrameWithSuperAbsolutePosition:superAbsolutePosition gatherDirtyComponents:dirtyComponents];
}
@end