| /* |
| * 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" |
| #import "WXComponent+Layout.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 && ( isnan(self.flexCssNode->getStyleWidth()) || _isUseContainerWidth)) { |
| self.flexCssNode->setStyleWidth([self.delegate headerWidthForLayout:self],NO); |
| //TODO: set _isUseContainerWidth to NO if updateStyles have width |
| _isUseContainerWidth = YES; |
| } |
| |
| if ([self needsLayout]) { |
| std::pair<float, float> renderPageSize; |
| renderPageSize.first = self.weexInstance.frame.size.width; |
| renderPageSize.second = self.weexInstance.frame.size.height; |
| self.flexCssNode->calculateLayout(renderPageSize); |
| } |
| [super _calculateFrameWithSuperAbsolutePosition:superAbsolutePosition gatherDirtyComponents:dirtyComponents]; |
| } |
| |
| @end |