diff --git a/doric-iOS/Pod/Classes/Shader/DoricNestedSliderNode.m b/doric-iOS/Pod/Classes/Shader/DoricNestedSliderNode.m index 32a57459..239d951c 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricNestedSliderNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricNestedSliderNode.m @@ -25,6 +25,13 @@ @interface DoricNestedSliderView : UIScrollView @end @implementation DoricNestedSliderView +- (CGSize)sizeThatFits:(CGSize)size { + CGSize result = [super sizeThatFits:size]; + if (self.doricLayout.heightSpec == DoricLayoutFit && self.contentSize.height > 0) { + return CGSizeMake(result.width, self.contentSize.height); + } + return result; +} @end @interface DoricNestedSliderNode () diff --git a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m index 006b9085..df5c808c 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m @@ -36,6 +36,7 @@ @interface DoricSliderNode () 0) { + return CGSizeMake(result.width, self.contentSize.height); + } + return result; +} @end @implementation DoricSliderNode @@ -109,6 +118,12 @@ - (void)blendView:(UICollectionView *)view forPropName:(NSString *)name propValu } else if ([prop isKindOfClass:NSString.class]) { self.slideStyle = prop; } + } else if ([@"slidePosition" isEqualToString:name]) { + self.slidePosition = [prop unsignedIntegerValue]; + if (self.view.width > 0 && ((NSUInteger) self.view.contentOffset.x / self.view.width) == self.slidePosition) { + } else { + self.needResetScroll = YES; + } } else { [super blendView:view forPropName:name propValue:prop]; } @@ -144,10 +159,8 @@ - (void)afterBlended:(NSDictionary *)props { if (needToScroll) { dispatch_async(dispatch_get_main_queue(), ^{ __strong typeof(_self) self = _self; - [self.view reloadData]; - - int position = self.loop ? 1 : 0; + NSUInteger position = (self.loop ? 1 : 0) + self.slidePosition; if (self.view.width == 0) { self.needResetScroll = true; } else { @@ -197,6 +210,18 @@ - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collection [node blend:props]; [node.view.doricLayout apply:CGSizeMake(collectionView.width, collectionView.height)]; [node requestLayout]; + BOOL needLayout = NO; + if (self.view.doricLayout.widthSpec == DoricLayoutFit && self.view.width < node.view.width) { + self.view.width = node.view.width; + needLayout = YES; + } + if (self.view.doricLayout.heightSpec == DoricLayoutFit && self.view.height < node.view.height) { + self.view.height = node.view.height; + needLayout = YES; + } + if (needLayout) { + [self scheduleLayout]; + } return cell; } @catch (NSException *exception) { [self.doricContext.driver.registry onException:exception inContext:self.doricContext]; @@ -204,6 +229,22 @@ - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collection } } +- (void)scheduleLayout { + if (self.scheduledLayout) { + return; + } + self.scheduledLayout = YES; + dispatch_async(dispatch_get_main_queue(), ^{ + self.scheduledLayout = NO; + DoricSuperNode *node = self.superNode; + while (node.superNode != nil) { + node = node.superNode; + } + [node requestLayout]; + [self.view reloadData]; + }); +} + - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath { return NO; } @@ -361,6 +402,7 @@ - (void)reset { self.slideStyle = nil; self.minScale = .618f; self.maxScale = 1.f; + self.slidePosition = 0; } - (void)subNodeContentChanged:(DoricViewNode *)subNode {