Skip to content

Commit

Permalink
* [ios] bug fix: slider is embed in list cell
Browse files Browse the repository at this point in the history
  • Loading branch information
boboning committed Jun 28, 2016
1 parent 3be6561 commit d56c7ec
Showing 1 changed file with 38 additions and 24 deletions.
62 changes: 38 additions & 24 deletions ios/sdk/WeexSDK/Sources/Component/WXSliderComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "WXSliderComponent.h"
#import "WXIndicatorComponent.h"
#import "WXComponent_internal.h"
#import "NSTimer+Weex.h"
#import "WXSDKManager.h"
#import "WXUtility.h"
Expand Down Expand Up @@ -324,35 +325,48 @@ - (void)viewDidUnload

- (void)insertSubview:(WXComponent *)subcomponent atIndex:(NSInteger)index
{
UIView *view = subcomponent.view;

if(index < 0) {
[self.childrenView addObject:view];
}
else {
[self.childrenView insertObject:view atIndex:index];
if (subcomponent->_positionType == WXPositionTypeFixed) {
[self.weexInstance.rootView addSubview:subcomponent.view];
return;
}

WXSliderView *sliderView = (WXSliderView *)self.view;
if ([view isKindOfClass:[WXIndicatorView class]]) {
[sliderView addSubview:view];
return;
// use _lazyCreateView to forbid component like cell's view creating
if(_lazyCreateView) {
subcomponent->_lazyCreateView = YES;
}

if (index == -1) {
[sliderView insertItemView:view atIndex:index];
} else {
NSInteger offset = 0;
for (int i = 0; i < [self.childrenView count]; ++i) {
if (index == i) break;

if ([self.childrenView[i] isKindOfClass:[WXIndicatorView class]]) {
offset++;
if (!subcomponent->_lazyCreateView || (self->_lazyCreateView && [self isViewLoaded])) {
UIView *view = subcomponent.view;

if(index < 0) {
[self.childrenView addObject:view];
}
else {
[self.childrenView insertObject:view atIndex:index];
}

WXSliderView *sliderView = (WXSliderView *)self.view;
if ([view isKindOfClass:[WXIndicatorView class]]) {
[sliderView addSubview:view];
return;
}

if (index == -1) {
[sliderView insertItemView:view atIndex:index];
} else {
NSInteger offset = 0;
for (int i = 0; i < [self.childrenView count]; ++i) {
if (index == i) break;

if ([self.childrenView[i] isKindOfClass:[WXIndicatorView class]]) {
offset++;
}
}
[sliderView insertItemView:view atIndex:index - offset];
}
[sliderView insertItemView:view atIndex:index - offset];

[sliderView loadData];
}
[sliderView loadData];
}

- (void)updateAttributes:(NSDictionary *)attributes
Expand Down Expand Up @@ -385,8 +399,8 @@ - (void)removeEvent:(NSString *)eventName

-(void)setIndicatorView:(WXIndicatorView *)indicatorView
{
//NSAssert(_sliderView, @"");
[(WXSliderView *)self.view setIndicator:indicatorView];
NSAssert(_sliderView, @"");
[_sliderView setIndicator:indicatorView];
}

#pragma mark Private Methods
Expand Down

0 comments on commit d56c7ec

Please sign in to comment.