Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[WEEX-598][iOS] slider component can not request gesture stoppropagat…
Browse files Browse the repository at this point in the history
…ion (#1478)
  • Loading branch information
doumafang authored and cxfeng1 committed Aug 27, 2018
1 parent a797740 commit bd0789a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
3 changes: 3 additions & 0 deletions ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@
- (void)setIndicatorView:(WXIndicatorView *)indicatorView;

@end
@interface WXRecycleSliderScrollView: UIScrollView
@end

28 changes: 24 additions & 4 deletions ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#import "WXSDKManager.h"
#import "WXUtility.h"
#import "WXComponent+Layout.h"
#import "WXComponent+Events.h"

typedef NS_ENUM(NSInteger, Direction) {
DirectionNone = 1 << 0,
Expand All @@ -40,15 +41,16 @@ - (void)recycleSliderView:(WXRecycleSliderView *)recycleSliderView didScroll:(UI
- (void)recycleSliderView:(WXRecycleSliderView *)recycleSliderView didScrollToItemAtIndex:(NSInteger)index;
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
- (BOOL)requestGestureShouldStopPropagation:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;

@end


@interface WXRecycleSliderView : UIView <UIScrollViewDelegate>

@property (nonatomic, strong) WXIndicatorView *indicator;
@property (nonatomic, weak) id<WXRecycleSliderViewDelegate> delegate;

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) WXRecycleSliderScrollView *scrollView;
@property (nonatomic, strong) NSMutableArray *itemViews;
@property (nonatomic, assign) Direction direction;
@property (nonatomic, assign) NSInteger currentIndex;
Expand All @@ -70,7 +72,7 @@ - (id)initWithFrame:(CGRect)frame
if (self) {
_currentIndex = 0;
_itemViews = [[NSMutableArray alloc] init];
_scrollView = [[UIScrollView alloc] init];
_scrollView = [[WXRecycleSliderScrollView alloc] init];
_scrollView.backgroundColor = [UIColor clearColor];
_scrollView.delegate = self;
_scrollView.showsHorizontalScrollIndicator = NO;
Expand Down Expand Up @@ -256,7 +258,6 @@ - (void)nextPage {

- (void)lastPage
{

NSInteger lastIndex = [self currentIndex]-1;
if (_itemViews.count > 1) {
if (_infinite) {
Expand Down Expand Up @@ -589,6 +590,11 @@ - (void)removeEvent:(NSString *)eventName
}
}

- (BOOL)requestGestureShouldStopPropagation:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return [self gestureShouldStopPropagation:gestureRecognizer shouldReceiveTouch:touch];
}

#pragma mark WXIndicatorComponentDelegate Methods

-(void)setIndicatorView:(WXIndicatorView *)indicatorView
Expand Down Expand Up @@ -680,3 +686,17 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL
}

@end

@implementation WXRecycleSliderScrollView
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
WXRecycleSliderView *view = (WXRecycleSliderView *)self.delegate;
if ([(id <WXRecycleSliderViewDelegate>) view.wx_component respondsToSelector:@selector(requestGestureShouldStopPropagation:shouldReceiveTouch:)]) {
return [(id <WXRecycleSliderViewDelegate>) view.wx_component requestGestureShouldStopPropagation:gestureRecognizer shouldReceiveTouch:touch];
}
else{
return YES;
}
}
@end

2 changes: 1 addition & 1 deletion ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ - (void)viewDidLoad
{
[super viewDidLoad];
[self setContentSize:_contentSize];
WXScrollerComponentView* scrollView = (WXScrollerComponentView *)self.view;
WXScrollerComponentView *scrollView = (WXScrollerComponentView *)self.view;
scrollView.delegate = self;
scrollView.exclusiveTouch = YES;
scrollView.autoresizesSubviews = NO;
Expand Down

0 comments on commit bd0789a

Please sign in to comment.