You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by bo...@apache.org on 2017/04/10 03:51:49 UTC
[1/9] incubator-weex git commit: * [ios] the new slider component
which is named WXRecycleSliderComponent to replace the old slider component
which is name WXSliderComponent.
Repository: incubator-weex
Updated Branches:
refs/heads/0.12-dev 5b1126a56 -> 51ba98801
* [ios] the new slider component which is named WXRecycleSliderComponent to replace the old slider component which is name WXSliderComponent.
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/b7bcdb1c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/b7bcdb1c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/b7bcdb1c
Branch: refs/heads/0.12-dev
Commit: b7bcdb1ccd807ee1e17e54de124dedf77746f022
Parents: 288b6e1
Author: LiuHongfeng(GuJian) <La...@gmail.com>
Authored: Wed Apr 5 11:00:00 2017 +0800
Committer: LiuHongfeng(GuJian) <La...@gmail.com>
Committed: Wed Apr 5 11:00:00 2017 +0800
----------------------------------------------------------------------
ios/sdk/WeexSDK.xcodeproj/project.pbxproj | 8 +
.../Sources/Component/WXIndicatorComponent.m | 11 +-
.../Component/WXRecycleSliderComponent.h | 18 +
.../Component/WXRecycleSliderComponent.m | 528 +++++++++++++++++++
ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m | 3 +-
5 files changed, 564 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b7bcdb1c/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
index f861bd9..c1470ac 100644
--- a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
+++ b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
@@ -37,6 +37,8 @@
2AE5B7561CABA04E0082FDDB /* WXEventModuleProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 2AE5B7551CABA04E0082FDDB /* WXEventModuleProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
2AFEB17B1C747139000507FA /* WXInstanceWrap.h in Headers */ = {isa = PBXBuildFile; fileRef = 2AFEB1791C747139000507FA /* WXInstanceWrap.h */; };
2AFEB17C1C747139000507FA /* WXInstanceWrap.m in Sources */ = {isa = PBXBuildFile; fileRef = 2AFEB17A1C747139000507FA /* WXInstanceWrap.m */; };
+ 37D940681E9492C600A5C45F /* WXRecycleSliderComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 37D940661E9492C600A5C45F /* WXRecycleSliderComponent.m */; };
+ 37D940691E9492C600A5C45F /* WXRecycleSliderComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = 37D940671E9492C600A5C45F /* WXRecycleSliderComponent.h */; };
591324A31D49B7F1004E89ED /* WXTimerModuleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 591324A21D49B7F1004E89ED /* WXTimerModuleTests.m */; };
591DD3311D23AD5800BE8709 /* WXErrorView.m in Sources */ = {isa = PBXBuildFile; fileRef = 591DD32F1D23AD5800BE8709 /* WXErrorView.m */; };
591DD3321D23AD5800BE8709 /* WXErrorView.h in Headers */ = {isa = PBXBuildFile; fileRef = 591DD3301D23AD5800BE8709 /* WXErrorView.h */; };
@@ -347,6 +349,8 @@
2AE5B7551CABA04E0082FDDB /* WXEventModuleProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXEventModuleProtocol.h; sourceTree = "<group>"; };
2AFEB1791C747139000507FA /* WXInstanceWrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXInstanceWrap.h; sourceTree = "<group>"; };
2AFEB17A1C747139000507FA /* WXInstanceWrap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXInstanceWrap.m; sourceTree = "<group>"; };
+ 37D940661E9492C600A5C45F /* WXRecycleSliderComponent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXRecycleSliderComponent.m; sourceTree = "<group>"; };
+ 37D940671E9492C600A5C45F /* WXRecycleSliderComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXRecycleSliderComponent.h; sourceTree = "<group>"; };
591324A21D49B7F1004E89ED /* WXTimerModuleTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXTimerModuleTests.m; sourceTree = "<group>"; };
591DD32F1D23AD5800BE8709 /* WXErrorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXErrorView.m; sourceTree = "<group>"; };
591DD3301D23AD5800BE8709 /* WXErrorView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXErrorView.h; sourceTree = "<group>"; };
@@ -1116,6 +1120,8 @@
77E65A181C155F25008B8775 /* WXScrollerComponent.m */,
2A44AB0F1C1AD5B00067A7EA /* WXSliderComponent.h */,
59D3CA461CFC3CC0008835DC /* WXSliderComponent.m */,
+ 37D940661E9492C600A5C45F /* WXRecycleSliderComponent.m */,
+ 37D940671E9492C600A5C45F /* WXRecycleSliderComponent.h */,
74CC7A1B1C2BC5F800829368 /* WXCellComponent.m */,
74CC7A1E1C2BF9DC00829368 /* WXListComponent.h */,
74CC7A1F1C2BF9DC00829368 /* WXListComponent.m */,
@@ -1235,6 +1241,7 @@
2A919DA61E321F1F006EB6B5 /* WXBridgeMethod.h in Headers */,
77D161281C02DE1A0010B15B /* WXSDKManager.h in Headers */,
59CE27E81CC387DB000BE37A /* WXEmbedComponent.h in Headers */,
+ 37D940691E9492C600A5C45F /* WXRecycleSliderComponent.h in Headers */,
74BB5FB91DFEE81A004FC3DF /* WXMetaModule.h in Headers */,
DCA0EF641D6EED6F00CB18B9 /* WXGlobalEventModule.h in Headers */,
2A837AB21CD9DE9200AEDF03 /* WXLoadingComponent.h in Headers */,
@@ -1624,6 +1631,7 @@
74D205211E091B8000128F44 /* WXCallJSMethod.m in Sources */,
59D3CA471CFC3CC0008835DC /* WXSliderComponent.m in Sources */,
77D1613D1C02DEA60010B15B /* WXJSCoreBridge.m in Sources */,
+ 37D940681E9492C600A5C45F /* WXRecycleSliderComponent.m in Sources */,
C41E1A981DC1FD15009C7F90 /* WXDatePickerManager.m in Sources */,
77D1614C1C02E3790010B15B /* WXConvert.m in Sources */,
749DC27C1D40827B009E1C91 /* WXMonitor.m in Sources */,
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b7bcdb1c/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
index 5b2b858..7f16ab8 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
@@ -7,7 +7,8 @@
*/
#import "WXIndicatorComponent.h"
-#import "WXSliderComponent.h"
+//#import "WXSliderComponent.h"
+#import "WXRecycleSliderComponent.h"
#import "WXConvert.h"
#import "WXSliderNeighborComponent.h"
#import "WXSDKInstance.h"
@@ -159,8 +160,12 @@
_indicatorView.pointSize = _itemSize;
WXComponent *parent = self.supercomponent;
- if([parent isKindOfClass:[WXSliderComponent class]] || [parent isKindOfClass:[WXSliderNeighborComponent class]]) {
- WXSliderComponent *parentSlider = (WXSliderComponent *)parent;
+// if([parent isKindOfClass:[WXSliderComponent class]] || [parent isKindOfClass:[WXSliderNeighborComponent class]]) {
+// WXSliderComponent *parentSlider = (WXSliderComponent *)parent;
+// [parentSlider setIndicatorView:_indicatorView];
+// }
+ if([parent isKindOfClass:[WXRecycleSliderComponent class]] || [parent isKindOfClass:[WXSliderNeighborComponent class]]) {
+ WXRecycleSliderComponent *parentSlider = (WXRecycleSliderComponent *)parent;
[parentSlider setIndicatorView:_indicatorView];
}
else {
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b7bcdb1c/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.h b/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.h
new file mode 100644
index 0000000..5dd0798
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.h
@@ -0,0 +1,18 @@
+/**
+ * Created by Weex.
+ * Copyright (c) 2016, Alibaba, Inc. All rights reserved.
+ *
+ * This source code is licensed under the Apache Licence 2.0.
+ * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
+ */
+
+#import <Foundation/Foundation.h>
+#import "WXComponent.h"
+
+@class WXIndicatorView;
+
+@interface WXRecycleSliderComponent : WXComponent
+
+- (void)setIndicatorView:(WXIndicatorView *)indicatorView;
+
+@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b7bcdb1c/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
new file mode 100644
index 0000000..d4e1058
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
@@ -0,0 +1,528 @@
+/**
+ * Created by Weex.
+ * Copyright (c) 2016, Alibaba, Inc. All rights reserved.
+ *
+ * This source code is licensed under the Apache Licence 2.0.
+ * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
+ */
+
+#import "WXRecycleSliderComponent.h"
+#import "WXIndicatorComponent.h"
+#import "WXComponent_internal.h"
+#import "NSTimer+Weex.h"
+#import "WXSDKManager.h"
+#import "WXUtility.h"
+
+typedef NS_ENUM(NSInteger, Direction) {
+ DirectionNone = 1 << 0,
+ DirectionLeft = 1 << 1,
+ DirectionRight = 1 << 2
+};
+
+@class WXRecycleSliderView;
+@class WXIndicatorView;
+
+@protocol WXRecycleSliderViewDelegate <UIScrollViewDelegate>
+
+- (void)recycleSliderView:(WXRecycleSliderView *)recycleSliderView didScroll:(UIScrollView *)scrollView;
+- (void)recycleSliderView:(WXRecycleSliderView *)recycleSliderView didScrollToItemAtIndex:(NSInteger)index;
+- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
+- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
+
+@end
+
+@interface WXRecycleSliderView : UIView <UIScrollViewDelegate>
+
+@property (nonatomic, strong) WXIndicatorView *indicator;
+@property (nonatomic, weak) id<WXRecycleSliderViewDelegate> delegate;
+
+@property (nonatomic, strong) UIScrollView *scrollView;
+@property (nonatomic, strong) NSMutableArray *itemViews;
+@property (nonatomic, assign) Direction direction;
+@property (nonatomic, assign) NSInteger currentIndex;
+@property (nonatomic, assign) NSInteger nextIndex;
+@property (nonatomic, assign) CGRect currentItemFrame;
+@property (nonatomic, assign) CGRect nextItemFrame;
+
+- (void)insertItemView:(UIView *)view atIndex:(NSInteger)index;
+- (void)removeItemView:(UIView *)view;
+
+@end
+
+@implementation WXRecycleSliderView
+
+- (id)initWithFrame:(CGRect)frame
+{
+ self = [super initWithFrame:frame];
+ if (self) {
+ _currentIndex = 0;
+ _itemViews = [[NSMutableArray alloc] init];
+ _scrollView = [[UIScrollView alloc] init];
+ _scrollView.backgroundColor = [UIColor clearColor];
+ _scrollView.delegate = self;
+ _scrollView.showsHorizontalScrollIndicator = NO;
+ _scrollView.showsVerticalScrollIndicator = NO;
+ _scrollView.scrollsToTop = NO;
+ [self addSubview:_scrollView];
+ }
+ return self;
+}
+
+- (void)layoutSubviews
+{
+ [super layoutSubviews];
+ self.scrollView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
+ if (self.itemViews.count > 1) {
+ self.scrollView.contentSize = CGSizeMake(self.width * 3, 0);
+ } else {
+ self.scrollView.contentSize = CGSizeZero;
+ }
+ self.scrollView.contentOffset = CGPointMake(self.width, 0);
+ _currentItemFrame = CGRectMake(self.width, 0, self.width, self.height);
+ _nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
+ [self resetItemViewsFrame];
+}
+
+#pragma mark --private methods--
+- (CGFloat)height {
+ return self.scrollView.frame.size.height;
+}
+
+- (CGFloat)width {
+ return self.scrollView.frame.size.width;
+}
+
+- (UIView *)getItemAtIndex:(NSInteger)index
+{
+ if (self.itemViews.count > index) {
+ return [self.itemViews objectAtIndex:index];
+ }else{
+ return nil;
+ }
+}
+
+- (void)setCurrentIndex:(NSInteger)currentIndex
+{
+ _currentIndex = currentIndex;
+ if (_direction == DirectionRight) { // \u5982\u679c\u662f\u5411\u53f3\u6eda\u52a8
+ self.nextItemFrame = CGRectMake(0, 0, self.width, self.height);
+ self.nextIndex = self.currentIndex - 1;
+ if (self.nextIndex < 0)
+ {
+ self.nextIndex = _itemViews.count - 1;
+ }
+ }else if (_direction == DirectionLeft){ // \u5982\u679c\u662f\u5411\u5de6\u8fb9\u6eda\u52a8
+ self.nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
+ self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
+ }
+ [self resetItemViewsFrame];
+ [self.indicator setPointCount:self.itemViews.count];
+ [self.indicator setCurrentPoint:currentIndex];
+ if (self.delegate && [self.delegate respondsToSelector:@selector(recycleSliderView:didScrollToItemAtIndex:)]) {
+ [self.delegate recycleSliderView:self didScrollToItemAtIndex:_currentIndex];
+ }
+}
+
+#pragma mark - \u8bbe\u7f6e\u6eda\u52a8\u65b9\u5411
+- (void)setDirection:(Direction)direction {
+ //\u53d8\u6362\u65b9\u5411\u65f6\u8bbe\u7f6e\u4e00\u6b21\u5404view frame
+ if (_direction == direction) return;
+ _direction = direction;
+ if (_direction == DirectionNone) return;
+
+ if (_direction == DirectionRight) { // \u5982\u679c\u662f\u5411\u53f3\u6eda\u52a8
+ self.nextItemFrame = CGRectMake(0, 0, self.width, self.height);
+ self.nextIndex = self.currentIndex - 1;
+ if (self.nextIndex < 0)
+ {
+ self.nextIndex = _itemViews.count - 1;
+ }
+ }else if (_direction == DirectionLeft){ // \u5982\u679c\u662f\u5411\u5de6\u8fb9\u6eda\u52a8
+ self.nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
+ self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
+ }
+ [self getItemAtIndex:_nextIndex].frame = _nextItemFrame;
+}
+
+- (void)resetItemViewsFrame
+{
+ for (int i = 0; i < self.itemViews.count; i++) {
+ UIView *view = [self.itemViews objectAtIndex:i];
+ if (i != self.currentIndex && i != self.nextIndex) {
+ view.frame = CGRectMake(self.frame.size.width * 3, 0, self.width, self.height);;
+ }
+ }
+ [self getItemAtIndex:_currentIndex].frame = _currentItemFrame;
+ [self getItemAtIndex:_nextIndex].frame = _nextItemFrame;
+}
+
+- (void)nextPage {
+ [self.scrollView setContentOffset:CGPointMake(self.width * 2, 0) animated:YES];
+}
+
+- (void)resetScrollView {
+ if (self.scrollView.contentOffset.x / self.width == 1)
+ {
+ return;
+ }
+ [self setCurrentIndex:self.nextIndex];
+ self.scrollView.contentOffset = CGPointMake(self.width, 0);
+}
+
+#pragma mark Public Methods
+
+- (void)setIndicator:(WXIndicatorView *)indicator
+{
+ _indicator = indicator;
+ [_indicator setPointCount:self.itemViews.count];
+ [_indicator setCurrentPoint:_currentIndex];
+}
+
+- (void)insertItemView:(UIView *)view atIndex:(NSInteger)index
+{
+ if (![self.itemViews containsObject:view]) {
+ view.tag = self.itemViews.count;
+ if (index < 0) {
+ [self.itemViews addObject:view];
+ } else {
+ [self.itemViews insertObject:view atIndex:index];
+ }
+ }
+
+ if (![self.scrollView.subviews containsObject:view]) {
+ if (index < 0) {
+ [self.scrollView addSubview:view];
+ } else {
+ [self.scrollView insertSubview:view atIndex:index];
+ }
+ }
+ [self setCurrentIndex:_currentIndex];
+ [self layoutSubviews];
+}
+
+- (void)removeItemView:(UIView *)view
+{
+ if ([self.itemViews containsObject:view]) {
+ [self.itemViews removeObject:view];
+ }
+
+ if ([self.scrollView.subviews containsObject:view]) {
+ [view removeFromSuperview];
+ }
+ [self setCurrentIndex:_currentIndex];
+ [self layoutSubviews];
+}
+
+#pragma mark ScrollView Delegate
+
+- (void)scrollViewDidScroll:(UIScrollView *)scrollView
+{
+ CGFloat offX = scrollView.contentOffset.x;
+ self.direction = offX > self.width ? DirectionLeft : offX < self.width ? DirectionRight : DirectionNone;
+ if (self.delegate && [self.delegate respondsToSelector:@selector(recycleSliderView:didScroll:)]) {
+ [self.delegate recycleSliderView:self didScroll:self.scrollView];
+ }
+}
+
+- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
+{
+ if (self.delegate && [self.delegate respondsToSelector:@selector(scrollViewWillBeginDragging:)]) {
+ [self.delegate scrollViewWillBeginDragging:self.scrollView];
+ }
+}
+
+- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
+{
+ if (self.delegate && [self.delegate respondsToSelector:@selector(scrollViewDidEndDragging: willDecelerate:)]) {
+ [self.delegate scrollViewDidEndDragging:self.scrollView willDecelerate:decelerate];
+ }
+}
+
+- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
+ [self resetScrollView];
+}
+
+- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
+ [self resetScrollView];
+}
+
+@end
+
+@interface WXRecycleSliderComponent ()<WXRecycleSliderViewDelegate>
+
+@property (nonatomic, strong) WXRecycleSliderView *recycleSliderView;
+@property (nonatomic, strong) NSTimer *autoTimer;
+@property (nonatomic, assign) NSInteger currentIndex;
+@property (nonatomic, assign) BOOL autoPlay;
+@property (nonatomic, assign) NSUInteger interval;
+@property (nonatomic, assign) NSInteger index;
+@property (nonatomic, assign) CGFloat lastOffsetXRatio;
+@property (nonatomic, assign) CGFloat offsetXAccuracy;
+@property (nonatomic, assign) BOOL sliderChangeEvent;
+@property (nonatomic, assign) BOOL sliderScrollEvent;
+@property (nonatomic, assign) BOOL sliderScrollStartEvent;
+@property (nonatomic, assign) BOOL sliderScrollEndEvent;
+@property (nonatomic, assign) BOOL sliderStartEventFired;
+@property (nonatomic, strong) NSMutableArray *childrenView;
+@property (nonatomic, assign) BOOL scrollable;
+
+@end
+
+@implementation WXRecycleSliderComponent
+
+- (void) dealloc
+{
+ [self _stopAutoPlayTimer];
+}
+
+- (instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDictionary *)styles attributes:(NSDictionary *)attributes events:(NSArray *)events weexInstance:(WXSDKInstance *)weexInstance
+{
+ if (self = [super initWithRef:ref type:type styles:styles attributes:attributes events:events weexInstance:weexInstance]) {
+ _sliderChangeEvent = NO;
+ _sliderScrollEvent = NO;
+ _interval = 3000;
+ _childrenView = [NSMutableArray new];
+ _lastOffsetXRatio = 0;
+
+ if (attributes[@"autoPlay"]) {
+ _autoPlay = [attributes[@"autoPlay"] boolValue];
+ }
+
+ if (attributes[@"interval"]) {
+ _interval = [attributes[@"interval"] integerValue];
+ }
+
+ if (attributes[@"index"]) {
+ _index = [attributes[@"index"] integerValue];
+ }
+
+ _scrollable = attributes[@"scrollable"] ? [WXConvert BOOL:attributes[@"scrollable"]] : YES;
+
+ if (attributes[@"offsetXAccuracy"]) {
+ _offsetXAccuracy = [WXConvert CGFloat:attributes[@"offsetXAccuracy"]];
+ }
+
+ self.cssNode->style.flex_direction = CSS_FLEX_DIRECTION_ROW;
+ }
+ return self;
+}
+
+- (UIView *)loadView
+{
+ return [[WXRecycleSliderView alloc] init];
+}
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+
+ _recycleSliderView = (WXRecycleSliderView *)self.view;
+ _recycleSliderView.delegate = self;
+ _recycleSliderView.scrollView.pagingEnabled = YES;
+ _recycleSliderView.exclusiveTouch = YES;
+ _recycleSliderView.scrollView.scrollEnabled = _scrollable;
+
+ if (_autoPlay) {
+ [self _startAutoPlayTimer];
+ } else {
+ [self _stopAutoPlayTimer];
+ }
+}
+
+- (void)layoutDidFinish
+{
+ _recycleSliderView.currentIndex = _index;
+}
+
+- (void)viewDidUnload
+{
+ [_childrenView removeAllObjects];
+}
+
+- (void)insertSubview:(WXComponent *)subcomponent atIndex:(NSInteger)index
+{
+ if (subcomponent->_positionType == WXPositionTypeFixed) {
+ [self.weexInstance.rootView addSubview:subcomponent.view];
+ return;
+ }
+
+ // use _lazyCreateView to forbid component like cell's view creating
+ if(_lazyCreateView) {
+ subcomponent->_lazyCreateView = YES;
+ }
+
+ 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];
+ }
+
+ WXRecycleSliderView *recycleSliderView = (WXRecycleSliderView *)self.view;
+ if ([view isKindOfClass:[WXIndicatorView class]]) {
+ [recycleSliderView addSubview:view];
+ return;
+ }
+
+ subcomponent.isViewFrameSyncWithCalculated = NO;
+
+ if (index == -1) {
+ [recycleSliderView 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++;
+ }
+ }
+ [recycleSliderView insertItemView:view atIndex:index - offset];
+ }
+ [recycleSliderView layoutSubviews];
+ }
+}
+
+- (void)willRemoveSubview:(WXComponent *)component
+{
+ UIView *view = component.view;
+
+ if(self.childrenView && [self.childrenView containsObject:view]) {
+ [self.childrenView removeObject:view];
+ }
+
+ WXRecycleSliderView *recycleSliderView = (WXRecycleSliderView *)_view;
+ [recycleSliderView removeItemView:view];
+ [recycleSliderView setCurrentIndex:0];
+}
+
+- (void)updateAttributes:(NSDictionary *)attributes
+{
+ if (attributes[@"autoPlay"]) {
+ _autoPlay = [attributes[@"autoPlay"] boolValue];
+ if (_autoPlay) {
+ [self _startAutoPlayTimer];
+ } else {
+ [self _stopAutoPlayTimer];
+ }
+ }
+
+ if (attributes[@"interval"]) {
+ _interval = [attributes[@"interval"] integerValue];
+
+ [self _stopAutoPlayTimer];
+
+ if (_autoPlay) {
+ [self _startAutoPlayTimer];
+ }
+ }
+
+ if (attributes[@"index"]) {
+ _index = [attributes[@"index"] integerValue];
+ self.currentIndex = _index;
+ self.recycleSliderView.currentIndex = _index;
+ }
+
+ if (attributes[@"scrollable"]) {
+ _scrollable = attributes[@"scrollable"] ? [WXConvert BOOL:attributes[@"scrollable"]] : YES;
+ ((WXRecycleSliderView *)self.view).scrollView.scrollEnabled = _scrollable;
+ }
+
+ if (attributes[@"offsetXAccuracy"]) {
+ _offsetXAccuracy = [WXConvert CGFloat:attributes[@"offsetXAccuracy"]];
+ }
+}
+
+- (void)addEvent:(NSString *)eventName
+{
+ if ([eventName isEqualToString:@"change"]) {
+ _sliderChangeEvent = YES;
+ }
+ if ([eventName isEqualToString:@"scroll"]) {
+ _sliderScrollEvent = YES;
+ }
+}
+
+- (void)removeEvent:(NSString *)eventName
+{
+ if ([eventName isEqualToString:@"change"]) {
+ _sliderChangeEvent = NO;
+ }
+ if ([eventName isEqualToString:@"scroll"]) {
+ _sliderScrollEvent = NO;
+ }
+}
+
+#pragma mark Public Methods
+
+-(void)setIndicatorView:(WXIndicatorView *)indicatorView
+{
+ NSAssert(_recycleSliderView, @"");
+ [_recycleSliderView setIndicator:indicatorView];
+}
+
+#pragma mark Private Methods
+
+- (void)_startAutoPlayTimer
+{
+ if (!self.autoTimer || ![self.autoTimer isValid]) {
+ __weak __typeof__(self) weakSelf = self;
+ self.autoTimer = [NSTimer wx_scheduledTimerWithTimeInterval:_interval/1000.0f block:^() {
+ [weakSelf _autoPlayOnTimer];
+ } repeats:YES];
+ [[NSRunLoop currentRunLoop] addTimer:self.autoTimer forMode:NSRunLoopCommonModes];
+ }
+}
+
+- (void)_stopAutoPlayTimer
+{
+ if (self.autoTimer && [self.autoTimer isValid]) {
+ [self.autoTimer invalidate];
+ self.autoTimer = nil;
+ }
+}
+
+- (void)_autoPlayOnTimer
+{
+ [self.recycleSliderView nextPage];
+}
+
+#pragma mark ScrollView Delegate
+
+- (void)recycleSliderView:(WXRecycleSliderView *)recycleSliderView didScroll:(UIScrollView *)scrollView
+{
+ if (_sliderScrollEvent) {
+ CGFloat width = scrollView.frame.size.width;
+ CGFloat XDeviation = scrollView.frame.origin.x - (scrollView.contentOffset.x - width);
+ CGFloat offsetXRatio = (XDeviation / width);
+ if (fabs(offsetXRatio - _lastOffsetXRatio) >= _offsetXAccuracy) {
+ _lastOffsetXRatio = offsetXRatio;
+ [self fireEvent:@"scroll" params:@{@"offsetXRatio":[NSNumber numberWithFloat:offsetXRatio]} domChanges:nil];
+ }
+ }
+}
+
+- (void)recycleSliderView:(WXRecycleSliderView *)recycleSliderView didScrollToItemAtIndex:(NSInteger)index
+{
+ self.currentIndex = index;
+ if (_sliderChangeEvent) {
+ [self fireEvent:@"change" params:@{@"index":@(index)} domChanges:@{@"attrs": @{@"index": @(index)}}];
+ }
+}
+
+- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
+{
+ [self _stopAutoPlayTimer];
+}
+
+- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
+{
+ if (_autoPlay) {
+ [self _startAutoPlayTimer];
+ }
+}
+
+@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b7bcdb1c/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
index f28f6f1..1605e44 100644
--- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
+++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
@@ -85,7 +85,8 @@
[self registerComponent:@"input" withClass:NSClassFromString(@"WXTextInputComponent")];
[self registerComponent:@"video" withClass:NSClassFromString(@"WXVideoComponent")];
[self registerComponent:@"indicator" withClass:NSClassFromString(@"WXIndicatorComponent")];
- [self registerComponent:@"slider" withClass:NSClassFromString(@"WXSliderComponent")];
+// [self registerComponent:@"slider" withClass:NSClassFromString(@"WXSliderComponent")];
+ [self registerComponent:@"slider" withClass:NSClassFromString(@"WXRecycleSliderComponent")];
[self registerComponent:@"web" withClass:NSClassFromString(@"WXWebComponent")];
[self registerComponent:@"loading" withClass:NSClassFromString(@"WXLoadingComponent")];
[self registerComponent:@"loading-indicator" withClass:NSClassFromString(@"WXLoadingIndicator")];
[4/9] incubator-weex git commit: * [ios] fix some bugs of recycleSlider’s infinite property, especially in status of two pages.
Posted by bo...@apache.org.
* [ios] fix some bugs of recycleSlider\u2019s infinite property, especially in status of two pages.
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/7d1dba1c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/7d1dba1c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/7d1dba1c
Branch: refs/heads/0.12-dev
Commit: 7d1dba1cd8ec4070ce4ae6344143a712609bfa2a
Parents: 98345a4
Author: LiuHongfeng(GuJian) <La...@gmail.com>
Authored: Fri Apr 7 15:40:37 2017 +0800
Committer: LiuHongfeng(GuJian) <La...@gmail.com>
Committed: Fri Apr 7 15:40:37 2017 +0800
----------------------------------------------------------------------
.../Sources/Component/WXIndicatorComponent.m | 3 --
.../Component/WXRecycleSliderComponent.m | 55 +++++++++-----------
2 files changed, 24 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7d1dba1c/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
index 4610341..b4af2af 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
@@ -171,9 +171,6 @@
WXSliderNeighborComponent *parentSlider = (WXSliderNeighborComponent *)parent;
[parentSlider setIndicatorView:_indicatorView];
}
- else {
- NSAssert(NO, @"");
- }
}
- (void)updateStyles:(NSDictionary *)styles
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7d1dba1c/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
index bc86db7..48d9b73 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
@@ -95,6 +95,9 @@ typedef NS_ENUM(NSInteger, Direction) {
- (void)setCurrentIndex:(NSInteger)currentIndex
{
+ if (currentIndex >= _itemViews.count || currentIndex < 0) {
+ currentIndex = 0;
+ }
_currentIndex = currentIndex;
if (_infinite) {
if (_direction == DirectionRight) {
@@ -104,15 +107,11 @@ typedef NS_ENUM(NSInteger, Direction) {
{
self.nextIndex = _itemViews.count - 1;
}
- NSLog(@"setCurrentIndex DirectionRight");
-
}else if (_direction == DirectionLeft) {
- NSLog(@"setCurrentIndex DirectionLeft");
-
self.nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
- NSLog(@"setCurrentIndex DirectionLeft nextIndex:%ld",_nextIndex);
-
+ }else {
+ self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
}
[self resetAllViewsFrame];
} else {
@@ -142,36 +141,23 @@ typedef NS_ENUM(NSInteger, Direction) {
{
self.nextIndex = _itemViews.count - 1;
}
- NSLog(@"DirectionRight");
- NSLog(@"DirectionRight nextIndex:%ld",_nextIndex);
-// [self getItemAtIndex:_nextIndex].frame = _nextItemFrame;
UIView *view = [self getItemAtIndex:_nextIndex];
if (view) {
view.frame = _nextItemFrame;
}
-
-
}else if (_direction == DirectionLeft){
- NSLog(@"DirectionLeft");
self.nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
- NSLog(@"DirectionLeft nextIndex:%ld",_nextIndex);
UIView *view = [self getItemAtIndex:_nextIndex];
if (view) {
view.frame = _nextItemFrame;
}
-
- NSLog(@"frame %@",NSStringFromCGRect(view.frame));
- if (view) {
- self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
- NSLog(@"DirectionLeft nextIndex:%ld",_nextIndex);
- }
}
}
- (void)resetAllViewsFrame
{
- if (_infinite) {
+ if (_infinite && _itemViews.count > 1) {
self.scrollView.frame = CGRectMake(0, 0, self.width, self.height);
self.scrollView.contentOffset = CGPointMake(self.width, 0);
if (self.itemViews.count > 1) {
@@ -180,7 +166,6 @@ typedef NS_ENUM(NSInteger, Direction) {
self.scrollView.contentSize = CGSizeZero;
}
_currentItemFrame = CGRectMake(self.width, 0, self.width, self.height);
- _nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
for (int i = 0; i < self.itemViews.count; i++) {
UIView *view = [self.itemViews objectAtIndex:i];
if (i != self.currentIndex && i != self.nextIndex) {
@@ -188,9 +173,10 @@ typedef NS_ENUM(NSInteger, Direction) {
}
}
[self getItemAtIndex:_currentIndex].frame = _currentItemFrame;
- [self getItemAtIndex:_nextIndex].frame = _nextItemFrame;
- NSLog(@"resetAllViewsFrame _currentIndex:%ld nextIndex:%ld",_currentIndex,_nextIndex);
-
+ if (_itemViews.count == 2) {
+ _nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
+ [self getItemAtIndex:_nextIndex].frame = _nextItemFrame;
+ }
} else {
self.scrollView.frame = self.bounds;
self.scrollView.contentSize = CGSizeMake(self.width * _itemViews.count, self.height);
@@ -205,12 +191,14 @@ typedef NS_ENUM(NSInteger, Direction) {
}
- (void)nextPage {
- if (_infinite) {
- [self.scrollView setContentOffset:CGPointMake(self.width * 2, 0) animated:YES];
- } else {
- _currentIndex += 1;
- if (_currentIndex - 1 < _itemViews.count) {
- [self.scrollView setContentOffset:CGPointMake(_currentIndex * self.width, 0) animated:YES];
+ if (_itemViews.count > 1) {
+ if (_infinite) {
+ [self.scrollView setContentOffset:CGPointMake(self.width * 2, 0) animated:YES];
+ } else {
+ _currentIndex += 1;
+ if (_currentIndex - 1 < _itemViews.count) {
+ [self.scrollView setContentOffset:CGPointMake(_currentIndex * self.width, 0) animated:YES];
+ }
}
}
}
@@ -568,7 +556,12 @@ typedef NS_ENUM(NSInteger, Direction) {
{
if (_sliderScrollEvent) {
CGFloat width = scrollView.frame.size.width;
- CGFloat XDeviation = scrollView.frame.origin.x - (scrollView.contentOffset.x - width);
+ CGFloat XDeviation = 0;
+ if (_infinite) {
+ XDeviation = - (scrollView.contentOffset.x - width);
+ } else {
+ XDeviation = - (scrollView.contentOffset.x - width * _currentIndex);
+ }
CGFloat offsetXRatio = (XDeviation / width);
if (fabs(offsetXRatio - _lastOffsetXRatio) >= _offsetXAccuracy) {
_lastOffsetXRatio = offsetXRatio;
[5/9] incubator-weex git commit: Merge branch '0.12-dev' of
https://github.com/apache/incubator-weex into 0.12-dev-newSlider
Posted by bo...@apache.org.
Merge branch '0.12-dev' of https://github.com/apache/incubator-weex into 0.12-dev-newSlider
* '0.12-dev' of https://github.com/apache/incubator-weex: (22 commits)
* [jsfm] v0.20.3
* [android] fix NPE in move fixed view
* [doc] add scrollToElement animation support
eslint warning
* [jsfm] fix function markupState
call C++ timer instead of WxTimerModule with in week jsfm
* [example] fix banner
* [jsfm] v0.20.2
* [jsfm] update jsfm version to 0.19.17 for fixed Vue leak
* [jsfm] v0.19.17
* [jsfm] update weex-vue-framework to 2.2.1-weex.2 && destroy runtime document
* [android] fix setSize when defaultHeight is use screen height
* [jsfm] update vue framework to 2.2.2-weex.1
* [test] Closes #141: invalid/pullrequest
* [android] avoid remove-readd view when fixed component view already moved
* [html5] clear log.
* [ios] fix box shadow shadowColor get method circularly called
* [ios] add default value
* [ios] refactor gradient-color method
* [html5] update build & test config.
...
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/ec1d008a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/ec1d008a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/ec1d008a
Branch: refs/heads/0.12-dev
Commit: ec1d008a253ec9384d673de086cd36fae0e1d624
Parents: 7d1dba1 c597a05
Author: LiuHongfeng(GuJian) <La...@gmail.com>
Authored: Fri Apr 7 15:41:45 2017 +0800
Committer: LiuHongfeng(GuJian) <La...@gmail.com>
Committed: Fri Apr 7 15:41:45 2017 +0800
----------------------------------------------------------------------
android/sdk/assets/main.js | 14 +--
.../java/com/taobao/weex/WXSDKInstance.java | 15 +--
build/config.js | 8 +-
build/karma.vue.conf.js | 15 ++-
build/webpack.examples.config.js | 4 +-
doc/source/cn/references/modules/dom.md | 3 +-
doc/source/references/modules/dom.md | 3 +-
examples/module/componentRect.we | 4 +-
html5/frameworks/legacy/app/ctrl/init.js | 42 ++++++-
html5/frameworks/legacy/static/life.js | 8 +-
ios/sdk/WeexSDK.xcodeproj/project.pbxproj | 8 --
ios/sdk/WeexSDK/Resources/main.js | 14 +--
.../Component/WXComponent+GradientColor.h | 18 ---
.../Component/WXComponent+GradientColor.m | 124 -------------------
.../Sources/Component/WXComponent_internal.h | 3 +
.../WeexSDK/Sources/Layout/WXComponent+Layout.m | 1 -
ios/sdk/WeexSDK/Sources/Model/WXComponent.m | 29 ++++-
ios/sdk/WeexSDK/Sources/Utility/WXBoxShadow.m | 2 +-
ios/sdk/WeexSDK/Sources/Utility/WXUtility.h | 27 ++++
ios/sdk/WeexSDK/Sources/Utility/WXUtility.m | 101 +++++++++++++++
.../Sources/View/WXComponent+ViewManagement.m | 1 -
package.json | 9 +-
22 files changed, 253 insertions(+), 200 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/ec1d008a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
----------------------------------------------------------------------
[3/9] incubator-weex git commit: * [ios] the new slider component which is named WXRecycleSliderComponent use weex tag “recycleslider”. add infinite property to recycleslider component.
Posted by bo...@apache.org.
* [ios] the new slider component which is named WXRecycleSliderComponent use weex tag \u201crecycleslider\u201d. add infinite property to recycleslider component.
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/98345a43
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/98345a43
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/98345a43
Branch: refs/heads/0.12-dev
Commit: 98345a43a666ad410dd6ed4934388afeb21c8d8e
Parents: 552f6f2
Author: LiuHongfeng(GuJian) <La...@gmail.com>
Authored: Thu Apr 6 18:46:29 2017 +0800
Committer: LiuHongfeng(GuJian) <La...@gmail.com>
Committed: Thu Apr 6 18:46:29 2017 +0800
----------------------------------------------------------------------
.../Sources/Component/WXIndicatorComponent.m | 15 +-
.../Component/WXRecycleSliderComponent.m | 169 +++++++++++++------
.../Component/WXSliderNeighborComponent.h | 3 +
ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m | 4 +-
4 files changed, 135 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/98345a43/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
index 7f16ab8..4610341 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
@@ -7,7 +7,7 @@
*/
#import "WXIndicatorComponent.h"
-//#import "WXSliderComponent.h"
+#import "WXSliderComponent.h"
#import "WXRecycleSliderComponent.h"
#import "WXConvert.h"
#import "WXSliderNeighborComponent.h"
@@ -160,13 +160,16 @@
_indicatorView.pointSize = _itemSize;
WXComponent *parent = self.supercomponent;
-// if([parent isKindOfClass:[WXSliderComponent class]] || [parent isKindOfClass:[WXSliderNeighborComponent class]]) {
-// WXSliderComponent *parentSlider = (WXSliderComponent *)parent;
-// [parentSlider setIndicatorView:_indicatorView];
-// }
- if([parent isKindOfClass:[WXRecycleSliderComponent class]] || [parent isKindOfClass:[WXSliderNeighborComponent class]]) {
+ if([parent isKindOfClass:[WXSliderComponent class]]) {
+ WXSliderComponent *parentSlider = (WXSliderComponent *)parent;
+ [parentSlider setIndicatorView:_indicatorView];
+ }
+ if([parent isKindOfClass:[WXRecycleSliderComponent class]]) {
WXRecycleSliderComponent *parentSlider = (WXRecycleSliderComponent *)parent;
[parentSlider setIndicatorView:_indicatorView];
+ }else if ([parent isKindOfClass:[WXSliderNeighborComponent class]]) {
+ WXSliderNeighborComponent *parentSlider = (WXSliderNeighborComponent *)parent;
+ [parentSlider setIndicatorView:_indicatorView];
}
else {
NSAssert(NO, @"");
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/98345a43/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
index 52f8607..bc86db7 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
@@ -43,6 +43,7 @@ typedef NS_ENUM(NSInteger, Direction) {
@property (nonatomic, assign) NSInteger nextIndex;
@property (nonatomic, assign) CGRect currentItemFrame;
@property (nonatomic, assign) CGRect nextItemFrame;
+@property (nonatomic, assign) BOOL infinite;
- (void)insertItemView:(UIView *)view atIndex:(NSInteger)index;
- (void)removeItemView:(UIView *)view;
@@ -71,25 +72,16 @@ typedef NS_ENUM(NSInteger, Direction) {
- (void)layoutSubviews
{
[super layoutSubviews];
- self.scrollView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
- if (self.itemViews.count > 1) {
- self.scrollView.contentSize = CGSizeMake(self.width * 3, 0);
- } else {
- self.scrollView.contentSize = CGSizeZero;
- }
- self.scrollView.contentOffset = CGPointMake(self.width, 0);
- _currentItemFrame = CGRectMake(self.width, 0, self.width, self.height);
- _nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
- [self resetItemViewsFrame];
+ [self resetAllViewsFrame];
}
#pragma mark Private Methods
- (CGFloat)height {
- return self.scrollView.frame.size.height;
+ return self.frame.size.height;
}
- (CGFloat)width {
- return self.scrollView.frame.size.width;
+ return self.frame.size.width;
}
- (UIView *)getItemAtIndex:(NSInteger)index
@@ -104,60 +96,123 @@ typedef NS_ENUM(NSInteger, Direction) {
- (void)setCurrentIndex:(NSInteger)currentIndex
{
_currentIndex = currentIndex;
- if (_direction == DirectionRight) {
- self.nextItemFrame = CGRectMake(0, 0, self.width, self.height);
- self.nextIndex = self.currentIndex - 1;
- if (self.nextIndex < 0)
- {
- self.nextIndex = _itemViews.count - 1;
+ if (_infinite) {
+ if (_direction == DirectionRight) {
+ self.nextItemFrame = CGRectMake(0, 0, self.width, self.height);
+ self.nextIndex = self.currentIndex - 1;
+ if (self.nextIndex < 0)
+ {
+ self.nextIndex = _itemViews.count - 1;
+ }
+ NSLog(@"setCurrentIndex DirectionRight");
+
+ }else if (_direction == DirectionLeft) {
+ NSLog(@"setCurrentIndex DirectionLeft");
+
+ self.nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
+ self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
+ NSLog(@"setCurrentIndex DirectionLeft nextIndex:%ld",_nextIndex);
+
}
- }else if (_direction == DirectionLeft) {
- self.nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
- self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
+ [self resetAllViewsFrame];
+ } else {
+ [_scrollView setContentOffset:CGPointMake(_currentIndex * self.width, 0) animated:YES];
}
- [self resetItemViewsFrame];
- [self.indicator setPointCount:self.itemViews.count];
- [self.indicator setCurrentPoint:currentIndex];
+ [self resetIndicatorPoint];
if (self.delegate && [self.delegate respondsToSelector:@selector(recycleSliderView:didScrollToItemAtIndex:)]) {
[self.delegate recycleSliderView:self didScrollToItemAtIndex:_currentIndex];
}
}
+- (void)resetIndicatorPoint
+{
+ [self.indicator setPointCount:self.itemViews.count];
+ [self.indicator setCurrentPoint:_currentIndex];
+}
+
#pragma mark Scroll & Frames
- (void)setDirection:(Direction)direction {
- //\u53d8\u6362\u65b9\u5411\u65f6\u8bbe\u7f6e\u4e00\u6b21\u5404view frame
if (_direction == direction) return;
_direction = direction;
if (_direction == DirectionNone) return;
-
- if (_direction == DirectionRight) { // \u5982\u679c\u662f\u5411\u53f3\u6eda\u52a8
+ if (_direction == DirectionRight) {
self.nextItemFrame = CGRectMake(0, 0, self.width, self.height);
self.nextIndex = self.currentIndex - 1;
if (self.nextIndex < 0)
{
self.nextIndex = _itemViews.count - 1;
}
- }else if (_direction == DirectionLeft){ // \u5982\u679c\u662f\u5411\u5de6\u8fb9\u6eda\u52a8
+ NSLog(@"DirectionRight");
+ NSLog(@"DirectionRight nextIndex:%ld",_nextIndex);
+// [self getItemAtIndex:_nextIndex].frame = _nextItemFrame;
+ UIView *view = [self getItemAtIndex:_nextIndex];
+ if (view) {
+ view.frame = _nextItemFrame;
+ }
+
+
+ }else if (_direction == DirectionLeft){
+ NSLog(@"DirectionLeft");
self.nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
+ NSLog(@"DirectionLeft nextIndex:%ld",_nextIndex);
+ UIView *view = [self getItemAtIndex:_nextIndex];
+ if (view) {
+ view.frame = _nextItemFrame;
+ }
+
+ NSLog(@"frame %@",NSStringFromCGRect(view.frame));
+ if (view) {
+ self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
+ NSLog(@"DirectionLeft nextIndex:%ld",_nextIndex);
+ }
}
- [self getItemAtIndex:_nextIndex].frame = _nextItemFrame;
}
-- (void)resetItemViewsFrame
+- (void)resetAllViewsFrame
{
- for (int i = 0; i < self.itemViews.count; i++) {
- UIView *view = [self.itemViews objectAtIndex:i];
- if (i != self.currentIndex && i != self.nextIndex) {
- view.frame = CGRectMake(self.frame.size.width * 3, 0, self.width, self.height);;
+ if (_infinite) {
+ self.scrollView.frame = CGRectMake(0, 0, self.width, self.height);
+ self.scrollView.contentOffset = CGPointMake(self.width, 0);
+ if (self.itemViews.count > 1) {
+ self.scrollView.contentSize = CGSizeMake(self.width * 3, 0);
+ } else {
+ self.scrollView.contentSize = CGSizeZero;
+ }
+ _currentItemFrame = CGRectMake(self.width, 0, self.width, self.height);
+ _nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
+ for (int i = 0; i < self.itemViews.count; i++) {
+ UIView *view = [self.itemViews objectAtIndex:i];
+ if (i != self.currentIndex && i != self.nextIndex) {
+ view.frame = CGRectMake(self.frame.size.width * 3, 0, self.width, self.height);;
+ }
+ }
+ [self getItemAtIndex:_currentIndex].frame = _currentItemFrame;
+ [self getItemAtIndex:_nextIndex].frame = _nextItemFrame;
+ NSLog(@"resetAllViewsFrame _currentIndex:%ld nextIndex:%ld",_currentIndex,_nextIndex);
+
+ } else {
+ self.scrollView.frame = self.bounds;
+ self.scrollView.contentSize = CGSizeMake(self.width * _itemViews.count, self.height);
+ self.scrollView.contentOffset = CGPointMake(_currentIndex * self.width, 0);
+ for (int i = 0; i < _itemViews.count; i ++) {
+ UIView *view = [_itemViews objectAtIndex:i];
+ view.frame = CGRectMake(i * self.width, 0, self.width, self.height);
}
+ [self.scrollView setContentOffset:CGPointMake(_currentIndex * self.width, 0) animated:NO];
}
- [self getItemAtIndex:_currentIndex].frame = _currentItemFrame;
- [self getItemAtIndex:_nextIndex].frame = _nextItemFrame;
+ [self resetIndicatorPoint];
}
- (void)nextPage {
- [self.scrollView setContentOffset:CGPointMake(self.width * 2, 0) animated:YES];
+ if (_infinite) {
+ [self.scrollView setContentOffset:CGPointMake(self.width * 2, 0) animated:YES];
+ } else {
+ _currentIndex += 1;
+ if (_currentIndex - 1 < _itemViews.count) {
+ [self.scrollView setContentOffset:CGPointMake(_currentIndex * self.width, 0) animated:YES];
+ }
+ }
}
- (void)resetScrollView {
@@ -196,8 +251,8 @@ typedef NS_ENUM(NSInteger, Direction) {
[self.scrollView insertSubview:view atIndex:index];
}
}
- [self setCurrentIndex:_currentIndex];
[self layoutSubviews];
+ [self setCurrentIndex:_currentIndex];
}
- (void)removeItemView:(UIView *)view
@@ -209,16 +264,18 @@ typedef NS_ENUM(NSInteger, Direction) {
if ([self.scrollView.subviews containsObject:view]) {
[view removeFromSuperview];
}
- [self setCurrentIndex:_currentIndex];
[self layoutSubviews];
+ [self setCurrentIndex:_currentIndex];
}
#pragma mark ScrollView Delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
- CGFloat offX = scrollView.contentOffset.x;
- self.direction = offX > self.width ? DirectionLeft : offX < self.width ? DirectionRight : DirectionNone;
+ if (_infinite) {
+ CGFloat offX = scrollView.contentOffset.x;
+ self.direction = offX > self.width ? DirectionLeft : offX < self.width ? DirectionRight : DirectionNone;
+ }
if (self.delegate && [self.delegate respondsToSelector:@selector(recycleSliderView:didScroll:)]) {
[self.delegate recycleSliderView:self didScroll:self.scrollView];
}
@@ -239,11 +296,21 @@ typedef NS_ENUM(NSInteger, Direction) {
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
- [self resetScrollView];
+ if (_infinite) {
+ [self resetScrollView];
+ } else {
+ NSInteger index = _scrollView.contentOffset.x / self.width;
+ [self setCurrentIndex:index];
+ }
}
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
- [self resetScrollView];
+ if (_infinite) {
+ [self resetScrollView];
+ } else {
+ NSInteger index = _scrollView.contentOffset.x / self.width;
+ [self setCurrentIndex:index];
+ }
}
@end
@@ -265,6 +332,7 @@ typedef NS_ENUM(NSInteger, Direction) {
@property (nonatomic, assign) BOOL sliderStartEventFired;
@property (nonatomic, strong) NSMutableArray *childrenView;
@property (nonatomic, assign) BOOL scrollable;
+@property (nonatomic, assign) BOOL infinite;
@end
@@ -295,13 +363,11 @@ typedef NS_ENUM(NSInteger, Direction) {
if (attributes[@"index"]) {
_index = [WXConvert NSInteger:attributes[@"index"]];
}
-
_scrollable = attributes[@"scrollable"] ? [WXConvert BOOL:attributes[@"scrollable"]] : YES;
-
if (attributes[@"offsetXAccuracy"]) {
_offsetXAccuracy = [WXConvert CGFloat:attributes[@"offsetXAccuracy"]];
}
-
+ _infinite = attributes[@"infinite"] ? [WXConvert BOOL:attributes[@"infinite"]] : YES;
self.cssNode->style.flex_direction = CSS_FLEX_DIRECTION_ROW;
}
return self;
@@ -321,7 +387,7 @@ typedef NS_ENUM(NSInteger, Direction) {
_recycleSliderView.scrollView.pagingEnabled = YES;
_recycleSliderView.exclusiveTouch = YES;
_recycleSliderView.scrollView.scrollEnabled = _scrollable;
-
+ _recycleSliderView.infinite = _infinite;
if (_autoPlay) {
[self _startAutoPlayTimer];
} else {
@@ -433,6 +499,9 @@ typedef NS_ENUM(NSInteger, Direction) {
if (attributes[@"offsetXAccuracy"]) {
_offsetXAccuracy = [WXConvert CGFloat:attributes[@"offsetXAccuracy"]];
}
+ if (attributes[@"infinite"]) {
+ _infinite = [WXConvert BOOL:attributes[@"infinite"]];
+ }
}
- (void)addEvent:(NSString *)eventName
@@ -486,7 +555,11 @@ typedef NS_ENUM(NSInteger, Direction) {
- (void)_autoPlayOnTimer
{
- [self.recycleSliderView nextPage];
+ if (!_infinite && (_currentIndex == _recycleSliderView.itemViews.count - 1)) {
+ [self _stopAutoPlayTimer];
+ }else {
+ [self.recycleSliderView nextPage];
+ }
}
#pragma mark ScrollView Delegate
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/98345a43/ios/sdk/WeexSDK/Sources/Component/WXSliderNeighborComponent.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXSliderNeighborComponent.h b/ios/sdk/WeexSDK/Sources/Component/WXSliderNeighborComponent.h
index eb350d9..9060948 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXSliderNeighborComponent.h
+++ b/ios/sdk/WeexSDK/Sources/Component/WXSliderNeighborComponent.h
@@ -28,6 +28,7 @@ typedef NS_ENUM(NSInteger, WXSliderNeighborOption)
};
@class WXSliderNeighborView;
+@class WXIndicatorView;
@protocol WXSliderNeighborDelegate <NSObject>
@optional
@@ -64,5 +65,7 @@ typedef NS_ENUM(NSInteger, WXSliderNeighborOption)
@interface WXSliderNeighborComponent : WXComponent<WXSliderNeighborDelegate, WXSliderNeighborDataSource>
+- (void)setIndicatorView:(WXIndicatorView *_Nonnull)indicatorView;
+
@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/98345a43/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
index 1605e44..37c9e34 100644
--- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
+++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
@@ -85,8 +85,8 @@
[self registerComponent:@"input" withClass:NSClassFromString(@"WXTextInputComponent")];
[self registerComponent:@"video" withClass:NSClassFromString(@"WXVideoComponent")];
[self registerComponent:@"indicator" withClass:NSClassFromString(@"WXIndicatorComponent")];
-// [self registerComponent:@"slider" withClass:NSClassFromString(@"WXSliderComponent")];
- [self registerComponent:@"slider" withClass:NSClassFromString(@"WXRecycleSliderComponent")];
+ [self registerComponent:@"slider" withClass:NSClassFromString(@"WXSliderComponent")];
+ [self registerComponent:@"recycleslider" withClass:NSClassFromString(@"WXRecycleSliderComponent")];
[self registerComponent:@"web" withClass:NSClassFromString(@"WXWebComponent")];
[self registerComponent:@"loading" withClass:NSClassFromString(@"WXLoadingComponent")];
[self registerComponent:@"loading-indicator" withClass:NSClassFromString(@"WXLoadingIndicator")];
[6/9] incubator-weex git commit: * [ios] rename recycleslider to
cycleslider
Posted by bo...@apache.org.
* [ios] rename recycleslider to cycleslider
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/9f8771bd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/9f8771bd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/9f8771bd
Branch: refs/heads/0.12-dev
Commit: 9f8771bdfb2a1c11063965c338b24cf123df9b9b
Parents: ec1d008
Author: LiuHongfeng(GuJian) <La...@gmail.com>
Authored: Fri Apr 7 16:10:05 2017 +0800
Committer: LiuHongfeng(GuJian) <La...@gmail.com>
Committed: Fri Apr 7 16:10:05 2017 +0800
----------------------------------------------------------------------
ios/sdk/WeexSDK.xcodeproj/project.pbxproj | 16 +-
.../Sources/Component/WXCycleSliderComponent.h | 18 +
.../Sources/Component/WXCycleSliderComponent.m | 593 +++++++++++++++++++
.../Sources/Component/WXIndicatorComponent.m | 6 +-
ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m | 2 +-
5 files changed, 623 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/9f8771bd/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
index 16f0b53..fd4eac8 100644
--- a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
+++ b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
@@ -37,8 +37,8 @@
2AE5B7561CABA04E0082FDDB /* WXEventModuleProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 2AE5B7551CABA04E0082FDDB /* WXEventModuleProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
2AFEB17B1C747139000507FA /* WXInstanceWrap.h in Headers */ = {isa = PBXBuildFile; fileRef = 2AFEB1791C747139000507FA /* WXInstanceWrap.h */; };
2AFEB17C1C747139000507FA /* WXInstanceWrap.m in Sources */ = {isa = PBXBuildFile; fileRef = 2AFEB17A1C747139000507FA /* WXInstanceWrap.m */; };
- 37D940681E9492C600A5C45F /* WXRecycleSliderComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 37D940661E9492C600A5C45F /* WXRecycleSliderComponent.m */; };
- 37D940691E9492C600A5C45F /* WXRecycleSliderComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = 37D940671E9492C600A5C45F /* WXRecycleSliderComponent.h */; };
+ 37B51EE41E97804D0040A743 /* WXCycleSliderComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = 37B51EE21E97804D0040A743 /* WXCycleSliderComponent.h */; };
+ 37B51EE51E97804D0040A743 /* WXCycleSliderComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 37B51EE31E97804D0040A743 /* WXCycleSliderComponent.m */; };
591324A31D49B7F1004E89ED /* WXTimerModuleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 591324A21D49B7F1004E89ED /* WXTimerModuleTests.m */; };
591DD3311D23AD5800BE8709 /* WXErrorView.m in Sources */ = {isa = PBXBuildFile; fileRef = 591DD32F1D23AD5800BE8709 /* WXErrorView.m */; };
591DD3321D23AD5800BE8709 /* WXErrorView.h in Headers */ = {isa = PBXBuildFile; fileRef = 591DD3301D23AD5800BE8709 /* WXErrorView.h */; };
@@ -347,8 +347,8 @@
2AE5B7551CABA04E0082FDDB /* WXEventModuleProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXEventModuleProtocol.h; sourceTree = "<group>"; };
2AFEB1791C747139000507FA /* WXInstanceWrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXInstanceWrap.h; sourceTree = "<group>"; };
2AFEB17A1C747139000507FA /* WXInstanceWrap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXInstanceWrap.m; sourceTree = "<group>"; };
- 37D940661E9492C600A5C45F /* WXRecycleSliderComponent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXRecycleSliderComponent.m; sourceTree = "<group>"; };
- 37D940671E9492C600A5C45F /* WXRecycleSliderComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXRecycleSliderComponent.h; sourceTree = "<group>"; };
+ 37B51EE21E97804D0040A743 /* WXCycleSliderComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXCycleSliderComponent.h; sourceTree = "<group>"; };
+ 37B51EE31E97804D0040A743 /* WXCycleSliderComponent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXCycleSliderComponent.m; sourceTree = "<group>"; };
591324A21D49B7F1004E89ED /* WXTimerModuleTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXTimerModuleTests.m; sourceTree = "<group>"; };
591DD32F1D23AD5800BE8709 /* WXErrorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXErrorView.m; sourceTree = "<group>"; };
591DD3301D23AD5800BE8709 /* WXErrorView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXErrorView.h; sourceTree = "<group>"; };
@@ -1114,10 +1114,10 @@
77E65A141C155EB5008B8775 /* WXTextComponent.m */,
77E65A171C155F25008B8775 /* WXScrollerComponent.h */,
77E65A181C155F25008B8775 /* WXScrollerComponent.m */,
+ 37B51EE21E97804D0040A743 /* WXCycleSliderComponent.h */,
+ 37B51EE31E97804D0040A743 /* WXCycleSliderComponent.m */,
2A44AB0F1C1AD5B00067A7EA /* WXSliderComponent.h */,
59D3CA461CFC3CC0008835DC /* WXSliderComponent.m */,
- 37D940661E9492C600A5C45F /* WXRecycleSliderComponent.m */,
- 37D940671E9492C600A5C45F /* WXRecycleSliderComponent.h */,
74CC7A1B1C2BC5F800829368 /* WXCellComponent.m */,
74CC7A1E1C2BF9DC00829368 /* WXListComponent.h */,
74CC7A1F1C2BF9DC00829368 /* WXListComponent.m */,
@@ -1233,9 +1233,9 @@
042013AD1E66CD6A001FC79C /* WXValidateProtocol.h in Headers */,
C4D872221E5DDEDA00E39BC1 /* WXInnerLayer.h in Headers */,
2A919DA61E321F1F006EB6B5 /* WXBridgeMethod.h in Headers */,
+ 37B51EE41E97804D0040A743 /* WXCycleSliderComponent.h in Headers */,
77D161281C02DE1A0010B15B /* WXSDKManager.h in Headers */,
59CE27E81CC387DB000BE37A /* WXEmbedComponent.h in Headers */,
- 37D940691E9492C600A5C45F /* WXRecycleSliderComponent.h in Headers */,
74BB5FB91DFEE81A004FC3DF /* WXMetaModule.h in Headers */,
DCA0EF641D6EED6F00CB18B9 /* WXGlobalEventModule.h in Headers */,
2A837AB21CD9DE9200AEDF03 /* WXLoadingComponent.h in Headers */,
@@ -1612,6 +1612,7 @@
745ED2DB1C5F2C7E002DB5A8 /* WXView.m in Sources */,
DC03ADB91D508719003F76E7 /* WXTextAreaComponent.m in Sources */,
59A596231CB6311F0012CD52 /* WXNavigatorModule.m in Sources */,
+ 37B51EE51E97804D0040A743 /* WXCycleSliderComponent.m in Sources */,
77D161211C02DDB40010B15B /* WXSDKEngine.m in Sources */,
D33451091D3E19480083598A /* WXCanvasComponent.m in Sources */,
74A4BA971CB365D100195969 /* WXAppConfiguration.m in Sources */,
@@ -1624,7 +1625,6 @@
74D205211E091B8000128F44 /* WXCallJSMethod.m in Sources */,
59D3CA471CFC3CC0008835DC /* WXSliderComponent.m in Sources */,
77D1613D1C02DEA60010B15B /* WXJSCoreBridge.m in Sources */,
- 37D940681E9492C600A5C45F /* WXRecycleSliderComponent.m in Sources */,
C41E1A981DC1FD15009C7F90 /* WXDatePickerManager.m in Sources */,
77D1614C1C02E3790010B15B /* WXConvert.m in Sources */,
749DC27C1D40827B009E1C91 /* WXMonitor.m in Sources */,
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/9f8771bd/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.h b/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.h
new file mode 100644
index 0000000..4b011dd
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.h
@@ -0,0 +1,18 @@
+/**
+ * Created by Weex.
+ * Copyright (c) 2016, Alibaba, Inc. All rights reserved.
+ *
+ * This source code is licensed under the Apache Licence 2.0.
+ * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
+ */
+
+#import <Foundation/Foundation.h>
+#import "WXComponent.h"
+
+@class WXIndicatorView;
+
+@interface WXCycleSliderComponent : WXComponent
+
+- (void)setIndicatorView:(WXIndicatorView *)indicatorView;
+
+@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/9f8771bd/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.m
new file mode 100644
index 0000000..a8fc879
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.m
@@ -0,0 +1,593 @@
+/**
+ * Created by Weex.
+ * Copyright (c) 2016, Alibaba, Inc. All rights reserved.
+ *
+ * This source code is licensed under the Apache Licence 2.0.
+ * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
+ */
+
+#import "WXCycleSliderComponent.h"
+#import "WXIndicatorComponent.h"
+#import "WXComponent_internal.h"
+#import "NSTimer+Weex.h"
+#import "WXSDKManager.h"
+#import "WXUtility.h"
+
+typedef NS_ENUM(NSInteger, Direction) {
+ DirectionNone = 1 << 0,
+ DirectionLeft = 1 << 1,
+ DirectionRight = 1 << 2
+};
+
+@class WXRecycleSliderView;
+@class WXIndicatorView;
+
+@protocol WXRecycleSliderViewDelegate <UIScrollViewDelegate>
+
+- (void)recycleSliderView:(WXRecycleSliderView *)recycleSliderView didScroll:(UIScrollView *)scrollView;
+- (void)recycleSliderView:(WXRecycleSliderView *)recycleSliderView didScrollToItemAtIndex:(NSInteger)index;
+- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
+- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
+
+@end
+
+@interface WXRecycleSliderView : UIView <UIScrollViewDelegate>
+
+@property (nonatomic, strong) WXIndicatorView *indicator;
+@property (nonatomic, weak) id<WXRecycleSliderViewDelegate> delegate;
+
+@property (nonatomic, strong) UIScrollView *scrollView;
+@property (nonatomic, strong) NSMutableArray *itemViews;
+@property (nonatomic, assign) Direction direction;
+@property (nonatomic, assign) NSInteger currentIndex;
+@property (nonatomic, assign) NSInteger nextIndex;
+@property (nonatomic, assign) CGRect currentItemFrame;
+@property (nonatomic, assign) CGRect nextItemFrame;
+@property (nonatomic, assign) BOOL infinite;
+
+- (void)insertItemView:(UIView *)view atIndex:(NSInteger)index;
+- (void)removeItemView:(UIView *)view;
+
+@end
+
+@implementation WXRecycleSliderView
+
+- (id)initWithFrame:(CGRect)frame
+{
+ self = [super initWithFrame:frame];
+ if (self) {
+ _currentIndex = 0;
+ _itemViews = [[NSMutableArray alloc] init];
+ _scrollView = [[UIScrollView alloc] init];
+ _scrollView.backgroundColor = [UIColor clearColor];
+ _scrollView.delegate = self;
+ _scrollView.showsHorizontalScrollIndicator = NO;
+ _scrollView.showsVerticalScrollIndicator = NO;
+ _scrollView.scrollsToTop = NO;
+ [self addSubview:_scrollView];
+ }
+ return self;
+}
+
+- (void)layoutSubviews
+{
+ [super layoutSubviews];
+ [self resetAllViewsFrame];
+}
+
+#pragma mark Private Methods
+- (CGFloat)height {
+ return self.frame.size.height;
+}
+
+- (CGFloat)width {
+ return self.frame.size.width;
+}
+
+- (UIView *)getItemAtIndex:(NSInteger)index
+{
+ if (self.itemViews.count > index) {
+ return [self.itemViews objectAtIndex:index];
+ }else{
+ return nil;
+ }
+}
+
+- (void)setCurrentIndex:(NSInteger)currentIndex
+{
+ if (currentIndex >= _itemViews.count || currentIndex < 0) {
+ currentIndex = 0;
+ }
+ _currentIndex = currentIndex;
+ if (_infinite) {
+ if (_direction == DirectionRight) {
+ self.nextItemFrame = CGRectMake(0, 0, self.width, self.height);
+ self.nextIndex = self.currentIndex - 1;
+ if (self.nextIndex < 0)
+ {
+ self.nextIndex = _itemViews.count - 1;
+ }
+ }else if (_direction == DirectionLeft) {
+ self.nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
+ self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
+ }else {
+ self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
+ }
+ [self resetAllViewsFrame];
+ } else {
+ [_scrollView setContentOffset:CGPointMake(_currentIndex * self.width, 0) animated:YES];
+ }
+ [self resetIndicatorPoint];
+ if (self.delegate && [self.delegate respondsToSelector:@selector(recycleSliderView:didScrollToItemAtIndex:)]) {
+ [self.delegate recycleSliderView:self didScrollToItemAtIndex:_currentIndex];
+ }
+}
+
+- (void)resetIndicatorPoint
+{
+ [self.indicator setPointCount:self.itemViews.count];
+ [self.indicator setCurrentPoint:_currentIndex];
+}
+
+#pragma mark Scroll & Frames
+- (void)setDirection:(Direction)direction {
+ if (_direction == direction) return;
+ _direction = direction;
+ if (_direction == DirectionNone) return;
+ if (_direction == DirectionRight) {
+ self.nextItemFrame = CGRectMake(0, 0, self.width, self.height);
+ self.nextIndex = self.currentIndex - 1;
+ if (self.nextIndex < 0)
+ {
+ self.nextIndex = _itemViews.count - 1;
+ }
+ UIView *view = [self getItemAtIndex:_nextIndex];
+ if (view) {
+ view.frame = _nextItemFrame;
+ }
+ }else if (_direction == DirectionLeft){
+ self.nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
+ self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
+ UIView *view = [self getItemAtIndex:_nextIndex];
+ if (view) {
+ view.frame = _nextItemFrame;
+ }
+ }
+}
+
+- (void)resetAllViewsFrame
+{
+ if (_infinite && _itemViews.count > 1) {
+ self.scrollView.frame = CGRectMake(0, 0, self.width, self.height);
+ self.scrollView.contentOffset = CGPointMake(self.width, 0);
+ if (self.itemViews.count > 1) {
+ self.scrollView.contentSize = CGSizeMake(self.width * 3, 0);
+ } else {
+ self.scrollView.contentSize = CGSizeZero;
+ }
+ _currentItemFrame = CGRectMake(self.width, 0, self.width, self.height);
+ for (int i = 0; i < self.itemViews.count; i++) {
+ UIView *view = [self.itemViews objectAtIndex:i];
+ if (i != self.currentIndex && i != self.nextIndex) {
+ view.frame = CGRectMake(self.frame.size.width * 3, 0, self.width, self.height);;
+ }
+ }
+ [self getItemAtIndex:_currentIndex].frame = _currentItemFrame;
+ if (_itemViews.count == 2) {
+ _nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
+ [self getItemAtIndex:_nextIndex].frame = _nextItemFrame;
+ }
+ } else {
+ self.scrollView.frame = self.bounds;
+ self.scrollView.contentSize = CGSizeMake(self.width * _itemViews.count, self.height);
+ self.scrollView.contentOffset = CGPointMake(_currentIndex * self.width, 0);
+ for (int i = 0; i < _itemViews.count; i ++) {
+ UIView *view = [_itemViews objectAtIndex:i];
+ view.frame = CGRectMake(i * self.width, 0, self.width, self.height);
+ }
+ [self.scrollView setContentOffset:CGPointMake(_currentIndex * self.width, 0) animated:NO];
+ }
+ [self resetIndicatorPoint];
+}
+
+- (void)nextPage {
+ if (_itemViews.count > 1) {
+ if (_infinite) {
+ [self.scrollView setContentOffset:CGPointMake(self.width * 2, 0) animated:YES];
+ } else {
+ _currentIndex += 1;
+ if (_currentIndex - 1 < _itemViews.count) {
+ [self.scrollView setContentOffset:CGPointMake(_currentIndex * self.width, 0) animated:YES];
+ }
+ }
+ }
+}
+
+- (void)resetScrollView {
+ if (self.scrollView.contentOffset.x / self.width == 1)
+ {
+ return;
+ }
+ [self setCurrentIndex:self.nextIndex];
+ self.scrollView.contentOffset = CGPointMake(self.width, 0);
+}
+
+#pragma mark Public Methods
+
+- (void)setIndicator:(WXIndicatorView *)indicator
+{
+ _indicator = indicator;
+ [_indicator setPointCount:self.itemViews.count];
+ [_indicator setCurrentPoint:_currentIndex];
+}
+
+- (void)insertItemView:(UIView *)view atIndex:(NSInteger)index
+{
+ if (![self.itemViews containsObject:view]) {
+ view.tag = self.itemViews.count;
+ if (index < 0) {
+ [self.itemViews addObject:view];
+ } else {
+ [self.itemViews insertObject:view atIndex:index];
+ }
+ }
+
+ if (![self.scrollView.subviews containsObject:view]) {
+ if (index < 0) {
+ [self.scrollView addSubview:view];
+ } else {
+ [self.scrollView insertSubview:view atIndex:index];
+ }
+ }
+ [self layoutSubviews];
+ [self setCurrentIndex:_currentIndex];
+}
+
+- (void)removeItemView:(UIView *)view
+{
+ if ([self.itemViews containsObject:view]) {
+ [self.itemViews removeObject:view];
+ }
+
+ if ([self.scrollView.subviews containsObject:view]) {
+ [view removeFromSuperview];
+ }
+ [self layoutSubviews];
+ [self setCurrentIndex:_currentIndex];
+}
+
+#pragma mark ScrollView Delegate
+
+- (void)scrollViewDidScroll:(UIScrollView *)scrollView
+{
+ if (_infinite) {
+ CGFloat offX = scrollView.contentOffset.x;
+ self.direction = offX > self.width ? DirectionLeft : offX < self.width ? DirectionRight : DirectionNone;
+ }
+ if (self.delegate && [self.delegate respondsToSelector:@selector(recycleSliderView:didScroll:)]) {
+ [self.delegate recycleSliderView:self didScroll:self.scrollView];
+ }
+}
+
+- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
+{
+ if (self.delegate && [self.delegate respondsToSelector:@selector(scrollViewWillBeginDragging:)]) {
+ [self.delegate scrollViewWillBeginDragging:self.scrollView];
+ }
+}
+
+- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
+{
+ if (self.delegate && [self.delegate respondsToSelector:@selector(scrollViewDidEndDragging: willDecelerate:)]) {
+ [self.delegate scrollViewDidEndDragging:self.scrollView willDecelerate:decelerate];
+ }
+}
+
+- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
+ if (_infinite) {
+ [self resetScrollView];
+ } else {
+ NSInteger index = _scrollView.contentOffset.x / self.width;
+ [self setCurrentIndex:index];
+ }
+}
+
+- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
+ if (_infinite) {
+ [self resetScrollView];
+ } else {
+ NSInteger index = _scrollView.contentOffset.x / self.width;
+ [self setCurrentIndex:index];
+ }
+}
+
+@end
+
+@interface WXCycleSliderComponent ()<WXRecycleSliderViewDelegate>
+
+@property (nonatomic, strong) WXRecycleSliderView *recycleSliderView;
+@property (nonatomic, strong) NSTimer *autoTimer;
+@property (nonatomic, assign) NSInteger currentIndex;
+@property (nonatomic, assign) BOOL autoPlay;
+@property (nonatomic, assign) NSUInteger interval;
+@property (nonatomic, assign) NSInteger index;
+@property (nonatomic, assign) CGFloat lastOffsetXRatio;
+@property (nonatomic, assign) CGFloat offsetXAccuracy;
+@property (nonatomic, assign) BOOL sliderChangeEvent;
+@property (nonatomic, assign) BOOL sliderScrollEvent;
+@property (nonatomic, assign) BOOL sliderScrollStartEvent;
+@property (nonatomic, assign) BOOL sliderScrollEndEvent;
+@property (nonatomic, assign) BOOL sliderStartEventFired;
+@property (nonatomic, strong) NSMutableArray *childrenView;
+@property (nonatomic, assign) BOOL scrollable;
+@property (nonatomic, assign) BOOL infinite;
+
+@end
+
+@implementation WXCycleSliderComponent
+
+- (void) dealloc
+{
+ [self _stopAutoPlayTimer];
+}
+
+- (instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDictionary *)styles attributes:(NSDictionary *)attributes events:(NSArray *)events weexInstance:(WXSDKInstance *)weexInstance
+{
+ if (self = [super initWithRef:ref type:type styles:styles attributes:attributes events:events weexInstance:weexInstance]) {
+ _sliderChangeEvent = NO;
+ _sliderScrollEvent = NO;
+ _interval = 3000;
+ _childrenView = [NSMutableArray new];
+ _lastOffsetXRatio = 0;
+
+ if (attributes[@"autoPlay"]) {
+ _autoPlay = [WXConvert BOOL:attributes[@"autoPlay"]];
+ }
+
+ if (attributes[@"interval"]) {
+ _interval = [WXConvert NSInteger:attributes[@"interval"]];
+ }
+
+ if (attributes[@"index"]) {
+ _index = [WXConvert NSInteger:attributes[@"index"]];
+ }
+ _scrollable = attributes[@"scrollable"] ? [WXConvert BOOL:attributes[@"scrollable"]] : YES;
+ if (attributes[@"offsetXAccuracy"]) {
+ _offsetXAccuracy = [WXConvert CGFloat:attributes[@"offsetXAccuracy"]];
+ }
+ _infinite = attributes[@"infinite"] ? [WXConvert BOOL:attributes[@"infinite"]] : YES;
+ self.cssNode->style.flex_direction = CSS_FLEX_DIRECTION_ROW;
+ }
+ return self;
+}
+
+- (UIView *)loadView
+{
+ return [[WXRecycleSliderView alloc] init];
+}
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+
+ _recycleSliderView = (WXRecycleSliderView *)self.view;
+ _recycleSliderView.delegate = self;
+ _recycleSliderView.scrollView.pagingEnabled = YES;
+ _recycleSliderView.exclusiveTouch = YES;
+ _recycleSliderView.scrollView.scrollEnabled = _scrollable;
+ _recycleSliderView.infinite = _infinite;
+ if (_autoPlay) {
+ [self _startAutoPlayTimer];
+ } else {
+ [self _stopAutoPlayTimer];
+ }
+}
+
+- (void)layoutDidFinish
+{
+ _recycleSliderView.currentIndex = _index;
+}
+
+- (void)viewDidUnload
+{
+ [_childrenView removeAllObjects];
+}
+
+- (void)insertSubview:(WXComponent *)subcomponent atIndex:(NSInteger)index
+{
+ if (subcomponent->_positionType == WXPositionTypeFixed) {
+ [self.weexInstance.rootView addSubview:subcomponent.view];
+ return;
+ }
+
+ // use _lazyCreateView to forbid component like cell's view creating
+ if(_lazyCreateView) {
+ subcomponent->_lazyCreateView = YES;
+ }
+
+ 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];
+ }
+
+ WXRecycleSliderView *recycleSliderView = (WXRecycleSliderView *)self.view;
+ if ([view isKindOfClass:[WXIndicatorView class]]) {
+ [recycleSliderView addSubview:view];
+ return;
+ }
+
+ subcomponent.isViewFrameSyncWithCalculated = NO;
+
+ if (index == -1) {
+ [recycleSliderView 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++;
+ }
+ }
+ [recycleSliderView insertItemView:view atIndex:index - offset];
+ }
+ [recycleSliderView layoutSubviews];
+ }
+}
+
+- (void)willRemoveSubview:(WXComponent *)component
+{
+ UIView *view = component.view;
+
+ if(self.childrenView && [self.childrenView containsObject:view]) {
+ [self.childrenView removeObject:view];
+ }
+
+ WXRecycleSliderView *recycleSliderView = (WXRecycleSliderView *)_view;
+ [recycleSliderView removeItemView:view];
+ [recycleSliderView setCurrentIndex:0];
+}
+
+- (void)updateAttributes:(NSDictionary *)attributes
+{
+ if (attributes[@"autoPlay"]) {
+ _autoPlay = [WXConvert BOOL:attributes[@"autoPlay"]];
+ if (_autoPlay) {
+ [self _startAutoPlayTimer];
+ } else {
+ [self _stopAutoPlayTimer];
+ }
+ }
+
+ if (attributes[@"interval"]) {
+ _interval = [WXConvert NSInteger:attributes[@"interval"]];
+ [self _stopAutoPlayTimer];
+
+ if (_autoPlay) {
+ [self _startAutoPlayTimer];
+ }
+ }
+
+ if (attributes[@"index"]) {
+ _index = [WXConvert NSInteger:attributes[@"index"]];
+ self.currentIndex = _index;
+ self.recycleSliderView.currentIndex = _index;
+ }
+
+ if (attributes[@"scrollable"]) {
+ _scrollable = attributes[@"scrollable"] ? [WXConvert BOOL:attributes[@"scrollable"]] : YES;
+ ((WXRecycleSliderView *)self.view).scrollView.scrollEnabled = _scrollable;
+ }
+
+ if (attributes[@"offsetXAccuracy"]) {
+ _offsetXAccuracy = [WXConvert CGFloat:attributes[@"offsetXAccuracy"]];
+ }
+ if (attributes[@"infinite"]) {
+ _infinite = [WXConvert BOOL:attributes[@"infinite"]];
+ }
+}
+
+- (void)addEvent:(NSString *)eventName
+{
+ if ([eventName isEqualToString:@"change"]) {
+ _sliderChangeEvent = YES;
+ }
+ if ([eventName isEqualToString:@"scroll"]) {
+ _sliderScrollEvent = YES;
+ }
+}
+
+- (void)removeEvent:(NSString *)eventName
+{
+ if ([eventName isEqualToString:@"change"]) {
+ _sliderChangeEvent = NO;
+ }
+ if ([eventName isEqualToString:@"scroll"]) {
+ _sliderScrollEvent = NO;
+ }
+}
+
+#pragma mark Public Methods
+
+-(void)setIndicatorView:(WXIndicatorView *)indicatorView
+{
+ NSAssert(_recycleSliderView, @"");
+ [_recycleSliderView setIndicator:indicatorView];
+}
+
+#pragma mark Private Methods
+
+- (void)_startAutoPlayTimer
+{
+ if (!self.autoTimer || ![self.autoTimer isValid]) {
+ __weak __typeof__(self) weakSelf = self;
+ self.autoTimer = [NSTimer wx_scheduledTimerWithTimeInterval:_interval/1000.0f block:^() {
+ [weakSelf _autoPlayOnTimer];
+ } repeats:YES];
+ [[NSRunLoop currentRunLoop] addTimer:self.autoTimer forMode:NSRunLoopCommonModes];
+ }
+}
+
+- (void)_stopAutoPlayTimer
+{
+ if (self.autoTimer && [self.autoTimer isValid]) {
+ [self.autoTimer invalidate];
+ self.autoTimer = nil;
+ }
+}
+
+- (void)_autoPlayOnTimer
+{
+ if (!_infinite && (_currentIndex == _recycleSliderView.itemViews.count - 1)) {
+ [self _stopAutoPlayTimer];
+ }else {
+ [self.recycleSliderView nextPage];
+ }
+}
+
+#pragma mark ScrollView Delegate
+
+- (void)recycleSliderView:(WXRecycleSliderView *)recycleSliderView didScroll:(UIScrollView *)scrollView
+{
+ if (_sliderScrollEvent) {
+ CGFloat width = scrollView.frame.size.width;
+ CGFloat XDeviation = 0;
+ if (_infinite) {
+ XDeviation = - (scrollView.contentOffset.x - width);
+ } else {
+ XDeviation = - (scrollView.contentOffset.x - width * _currentIndex);
+ }
+ CGFloat offsetXRatio = (XDeviation / width);
+ if (fabs(offsetXRatio - _lastOffsetXRatio) >= _offsetXAccuracy) {
+ _lastOffsetXRatio = offsetXRatio;
+ [self fireEvent:@"scroll" params:@{@"offsetXRatio":[NSNumber numberWithFloat:offsetXRatio]} domChanges:nil];
+ }
+ }
+}
+
+- (void)recycleSliderView:(WXRecycleSliderView *)recycleSliderView didScrollToItemAtIndex:(NSInteger)index
+{
+ self.currentIndex = index;
+ if (_sliderChangeEvent) {
+ [self fireEvent:@"change" params:@{@"index":@(index)} domChanges:@{@"attrs": @{@"index": @(index)}}];
+ }
+}
+
+- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
+{
+ [self _stopAutoPlayTimer];
+}
+
+- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
+{
+ if (_autoPlay) {
+ [self _startAutoPlayTimer];
+ }
+}
+
+@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/9f8771bd/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
index b4af2af..2647d61 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
@@ -8,7 +8,7 @@
#import "WXIndicatorComponent.h"
#import "WXSliderComponent.h"
-#import "WXRecycleSliderComponent.h"
+#import "WXCycleSliderComponent.h"
#import "WXConvert.h"
#import "WXSliderNeighborComponent.h"
#import "WXSDKInstance.h"
@@ -164,8 +164,8 @@
WXSliderComponent *parentSlider = (WXSliderComponent *)parent;
[parentSlider setIndicatorView:_indicatorView];
}
- if([parent isKindOfClass:[WXRecycleSliderComponent class]]) {
- WXRecycleSliderComponent *parentSlider = (WXRecycleSliderComponent *)parent;
+ if([parent isKindOfClass:[WXCycleSliderComponent class]]) {
+ WXCycleSliderComponent *parentSlider = (WXCycleSliderComponent *)parent;
[parentSlider setIndicatorView:_indicatorView];
}else if ([parent isKindOfClass:[WXSliderNeighborComponent class]]) {
WXSliderNeighborComponent *parentSlider = (WXSliderNeighborComponent *)parent;
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/9f8771bd/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
index 37c9e34..7d43bf0 100644
--- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
+++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
@@ -86,7 +86,7 @@
[self registerComponent:@"video" withClass:NSClassFromString(@"WXVideoComponent")];
[self registerComponent:@"indicator" withClass:NSClassFromString(@"WXIndicatorComponent")];
[self registerComponent:@"slider" withClass:NSClassFromString(@"WXSliderComponent")];
- [self registerComponent:@"recycleslider" withClass:NSClassFromString(@"WXRecycleSliderComponent")];
+ [self registerComponent:@"cycleslider" withClass:NSClassFromString(@"WXCycleSliderComponent")];
[self registerComponent:@"web" withClass:NSClassFromString(@"WXWebComponent")];
[self registerComponent:@"loading" withClass:NSClassFromString(@"WXLoadingComponent")];
[self registerComponent:@"loading-indicator" withClass:NSClassFromString(@"WXLoadingIndicator")];
[9/9] incubator-weex git commit: Merge branch '0.12-dev-newSlider' of
https://github.com/bluebird78999/incubator-weex into 0.12-dev
Posted by bo...@apache.org.
Merge branch '0.12-dev-newSlider' of https://github.com/bluebird78999/incubator-weex into 0.12-dev
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/51ba9880
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/51ba9880
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/51ba9880
Branch: refs/heads/0.12-dev
Commit: 51ba98801157fae6ae81b1cc363345ab56081000
Parents: 5b1126a 1f7a7db
Author: bobning <ni...@163.com>
Authored: Mon Apr 10 11:51:26 2017 +0800
Committer: bobning <ni...@163.com>
Committed: Mon Apr 10 11:51:26 2017 +0800
----------------------------------------------------------------------
ios/sdk/WeexSDK.xcodeproj/project.pbxproj | 8 +
.../Sources/Component/WXCycleSliderComponent.h | 18 +
.../Sources/Component/WXCycleSliderComponent.m | 594 +++++++++++++++++++
.../Sources/Component/WXIndicatorComponent.h | 8 +
.../Sources/Component/WXIndicatorComponent.m | 16 +-
.../Sources/Component/WXSliderComponent.m | 5 +-
.../Component/WXSliderNeighborComponent.h | 3 +
.../Component/WXSliderNeighborComponent.m | 5 +-
ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m | 1 +
9 files changed, 646 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
[2/9] incubator-weex git commit: * [ios] fix:edit the comments and
change the value to weex type
Posted by bo...@apache.org.
* [ios] fix:edit the comments and change the value to weex type
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/552f6f2a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/552f6f2a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/552f6f2a
Branch: refs/heads/0.12-dev
Commit: 552f6f2a24ab9ae66f49d192baeb817722ffdb58
Parents: b7bcdb1
Author: LiuHongfeng(GuJian) <La...@gmail.com>
Authored: Wed Apr 5 12:21:39 2017 +0800
Committer: LiuHongfeng(GuJian) <La...@gmail.com>
Committed: Wed Apr 5 12:21:39 2017 +0800
----------------------------------------------------------------------
.../Component/WXRecycleSliderComponent.m | 21 ++++++++++----------
1 file changed, 10 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/552f6f2a/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
index d4e1058..52f8607 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
@@ -83,7 +83,7 @@ typedef NS_ENUM(NSInteger, Direction) {
[self resetItemViewsFrame];
}
-#pragma mark --private methods--
+#pragma mark Private Methods
- (CGFloat)height {
return self.scrollView.frame.size.height;
}
@@ -104,14 +104,14 @@ typedef NS_ENUM(NSInteger, Direction) {
- (void)setCurrentIndex:(NSInteger)currentIndex
{
_currentIndex = currentIndex;
- if (_direction == DirectionRight) { // \u5982\u679c\u662f\u5411\u53f3\u6eda\u52a8
+ if (_direction == DirectionRight) {
self.nextItemFrame = CGRectMake(0, 0, self.width, self.height);
self.nextIndex = self.currentIndex - 1;
if (self.nextIndex < 0)
{
self.nextIndex = _itemViews.count - 1;
}
- }else if (_direction == DirectionLeft){ // \u5982\u679c\u662f\u5411\u5de6\u8fb9\u6eda\u52a8
+ }else if (_direction == DirectionLeft) {
self.nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
}
@@ -123,7 +123,7 @@ typedef NS_ENUM(NSInteger, Direction) {
}
}
-#pragma mark - \u8bbe\u7f6e\u6eda\u52a8\u65b9\u5411
+#pragma mark Scroll & Frames
- (void)setDirection:(Direction)direction {
//\u53d8\u6362\u65b9\u5411\u65f6\u8bbe\u7f6e\u4e00\u6b21\u5404view frame
if (_direction == direction) return;
@@ -285,15 +285,15 @@ typedef NS_ENUM(NSInteger, Direction) {
_lastOffsetXRatio = 0;
if (attributes[@"autoPlay"]) {
- _autoPlay = [attributes[@"autoPlay"] boolValue];
+ _autoPlay = [WXConvert BOOL:attributes[@"autoPlay"]];
}
if (attributes[@"interval"]) {
- _interval = [attributes[@"interval"] integerValue];
+ _interval = [WXConvert NSInteger:attributes[@"interval"]];
}
if (attributes[@"index"]) {
- _index = [attributes[@"index"] integerValue];
+ _index = [WXConvert NSInteger:attributes[@"index"]];
}
_scrollable = attributes[@"scrollable"] ? [WXConvert BOOL:attributes[@"scrollable"]] : YES;
@@ -402,7 +402,7 @@ typedef NS_ENUM(NSInteger, Direction) {
- (void)updateAttributes:(NSDictionary *)attributes
{
if (attributes[@"autoPlay"]) {
- _autoPlay = [attributes[@"autoPlay"] boolValue];
+ _autoPlay = [WXConvert BOOL:attributes[@"autoPlay"]];
if (_autoPlay) {
[self _startAutoPlayTimer];
} else {
@@ -411,8 +411,7 @@ typedef NS_ENUM(NSInteger, Direction) {
}
if (attributes[@"interval"]) {
- _interval = [attributes[@"interval"] integerValue];
-
+ _interval = [WXConvert NSInteger:attributes[@"interval"]];
[self _stopAutoPlayTimer];
if (_autoPlay) {
@@ -421,7 +420,7 @@ typedef NS_ENUM(NSInteger, Direction) {
}
if (attributes[@"index"]) {
- _index = [attributes[@"index"] integerValue];
+ _index = [WXConvert NSInteger:attributes[@"index"]];
self.currentIndex = _index;
self.recycleSliderView.currentIndex = _index;
}
[7/9] incubator-weex git commit: * [ios] remove
WXRecycleSliderComponent files
Posted by bo...@apache.org.
* [ios] remove WXRecycleSliderComponent files
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/10665be8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/10665be8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/10665be8
Branch: refs/heads/0.12-dev
Commit: 10665be8aea3de87ad7708f6323867156962af95
Parents: 9f8771b
Author: LiuHongfeng(GuJian) <La...@gmail.com>
Authored: Fri Apr 7 16:11:28 2017 +0800
Committer: LiuHongfeng(GuJian) <La...@gmail.com>
Committed: Fri Apr 7 16:11:28 2017 +0800
----------------------------------------------------------------------
.../Component/WXRecycleSliderComponent.h | 18 -
.../Component/WXRecycleSliderComponent.m | 593 -------------------
2 files changed, 611 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/10665be8/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.h b/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.h
deleted file mode 100644
index 5dd0798..0000000
--- a/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * Created by Weex.
- * Copyright (c) 2016, Alibaba, Inc. All rights reserved.
- *
- * This source code is licensed under the Apache Licence 2.0.
- * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
- */
-
-#import <Foundation/Foundation.h>
-#import "WXComponent.h"
-
-@class WXIndicatorView;
-
-@interface WXRecycleSliderComponent : WXComponent
-
-- (void)setIndicatorView:(WXIndicatorView *)indicatorView;
-
-@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/10665be8/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
deleted file mode 100644
index 48d9b73..0000000
--- a/ios/sdk/WeexSDK/Sources/Component/WXRecycleSliderComponent.m
+++ /dev/null
@@ -1,593 +0,0 @@
-/**
- * Created by Weex.
- * Copyright (c) 2016, Alibaba, Inc. All rights reserved.
- *
- * This source code is licensed under the Apache Licence 2.0.
- * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
- */
-
-#import "WXRecycleSliderComponent.h"
-#import "WXIndicatorComponent.h"
-#import "WXComponent_internal.h"
-#import "NSTimer+Weex.h"
-#import "WXSDKManager.h"
-#import "WXUtility.h"
-
-typedef NS_ENUM(NSInteger, Direction) {
- DirectionNone = 1 << 0,
- DirectionLeft = 1 << 1,
- DirectionRight = 1 << 2
-};
-
-@class WXRecycleSliderView;
-@class WXIndicatorView;
-
-@protocol WXRecycleSliderViewDelegate <UIScrollViewDelegate>
-
-- (void)recycleSliderView:(WXRecycleSliderView *)recycleSliderView didScroll:(UIScrollView *)scrollView;
-- (void)recycleSliderView:(WXRecycleSliderView *)recycleSliderView didScrollToItemAtIndex:(NSInteger)index;
-- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
-- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
-
-@end
-
-@interface WXRecycleSliderView : UIView <UIScrollViewDelegate>
-
-@property (nonatomic, strong) WXIndicatorView *indicator;
-@property (nonatomic, weak) id<WXRecycleSliderViewDelegate> delegate;
-
-@property (nonatomic, strong) UIScrollView *scrollView;
-@property (nonatomic, strong) NSMutableArray *itemViews;
-@property (nonatomic, assign) Direction direction;
-@property (nonatomic, assign) NSInteger currentIndex;
-@property (nonatomic, assign) NSInteger nextIndex;
-@property (nonatomic, assign) CGRect currentItemFrame;
-@property (nonatomic, assign) CGRect nextItemFrame;
-@property (nonatomic, assign) BOOL infinite;
-
-- (void)insertItemView:(UIView *)view atIndex:(NSInteger)index;
-- (void)removeItemView:(UIView *)view;
-
-@end
-
-@implementation WXRecycleSliderView
-
-- (id)initWithFrame:(CGRect)frame
-{
- self = [super initWithFrame:frame];
- if (self) {
- _currentIndex = 0;
- _itemViews = [[NSMutableArray alloc] init];
- _scrollView = [[UIScrollView alloc] init];
- _scrollView.backgroundColor = [UIColor clearColor];
- _scrollView.delegate = self;
- _scrollView.showsHorizontalScrollIndicator = NO;
- _scrollView.showsVerticalScrollIndicator = NO;
- _scrollView.scrollsToTop = NO;
- [self addSubview:_scrollView];
- }
- return self;
-}
-
-- (void)layoutSubviews
-{
- [super layoutSubviews];
- [self resetAllViewsFrame];
-}
-
-#pragma mark Private Methods
-- (CGFloat)height {
- return self.frame.size.height;
-}
-
-- (CGFloat)width {
- return self.frame.size.width;
-}
-
-- (UIView *)getItemAtIndex:(NSInteger)index
-{
- if (self.itemViews.count > index) {
- return [self.itemViews objectAtIndex:index];
- }else{
- return nil;
- }
-}
-
-- (void)setCurrentIndex:(NSInteger)currentIndex
-{
- if (currentIndex >= _itemViews.count || currentIndex < 0) {
- currentIndex = 0;
- }
- _currentIndex = currentIndex;
- if (_infinite) {
- if (_direction == DirectionRight) {
- self.nextItemFrame = CGRectMake(0, 0, self.width, self.height);
- self.nextIndex = self.currentIndex - 1;
- if (self.nextIndex < 0)
- {
- self.nextIndex = _itemViews.count - 1;
- }
- }else if (_direction == DirectionLeft) {
- self.nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
- self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
- }else {
- self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
- }
- [self resetAllViewsFrame];
- } else {
- [_scrollView setContentOffset:CGPointMake(_currentIndex * self.width, 0) animated:YES];
- }
- [self resetIndicatorPoint];
- if (self.delegate && [self.delegate respondsToSelector:@selector(recycleSliderView:didScrollToItemAtIndex:)]) {
- [self.delegate recycleSliderView:self didScrollToItemAtIndex:_currentIndex];
- }
-}
-
-- (void)resetIndicatorPoint
-{
- [self.indicator setPointCount:self.itemViews.count];
- [self.indicator setCurrentPoint:_currentIndex];
-}
-
-#pragma mark Scroll & Frames
-- (void)setDirection:(Direction)direction {
- if (_direction == direction) return;
- _direction = direction;
- if (_direction == DirectionNone) return;
- if (_direction == DirectionRight) {
- self.nextItemFrame = CGRectMake(0, 0, self.width, self.height);
- self.nextIndex = self.currentIndex - 1;
- if (self.nextIndex < 0)
- {
- self.nextIndex = _itemViews.count - 1;
- }
- UIView *view = [self getItemAtIndex:_nextIndex];
- if (view) {
- view.frame = _nextItemFrame;
- }
- }else if (_direction == DirectionLeft){
- self.nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
- self.nextIndex = (self.currentIndex + 1) % _itemViews.count;
- UIView *view = [self getItemAtIndex:_nextIndex];
- if (view) {
- view.frame = _nextItemFrame;
- }
- }
-}
-
-- (void)resetAllViewsFrame
-{
- if (_infinite && _itemViews.count > 1) {
- self.scrollView.frame = CGRectMake(0, 0, self.width, self.height);
- self.scrollView.contentOffset = CGPointMake(self.width, 0);
- if (self.itemViews.count > 1) {
- self.scrollView.contentSize = CGSizeMake(self.width * 3, 0);
- } else {
- self.scrollView.contentSize = CGSizeZero;
- }
- _currentItemFrame = CGRectMake(self.width, 0, self.width, self.height);
- for (int i = 0; i < self.itemViews.count; i++) {
- UIView *view = [self.itemViews objectAtIndex:i];
- if (i != self.currentIndex && i != self.nextIndex) {
- view.frame = CGRectMake(self.frame.size.width * 3, 0, self.width, self.height);;
- }
- }
- [self getItemAtIndex:_currentIndex].frame = _currentItemFrame;
- if (_itemViews.count == 2) {
- _nextItemFrame = CGRectMake(self.width * 2, 0, self.width, self.height);
- [self getItemAtIndex:_nextIndex].frame = _nextItemFrame;
- }
- } else {
- self.scrollView.frame = self.bounds;
- self.scrollView.contentSize = CGSizeMake(self.width * _itemViews.count, self.height);
- self.scrollView.contentOffset = CGPointMake(_currentIndex * self.width, 0);
- for (int i = 0; i < _itemViews.count; i ++) {
- UIView *view = [_itemViews objectAtIndex:i];
- view.frame = CGRectMake(i * self.width, 0, self.width, self.height);
- }
- [self.scrollView setContentOffset:CGPointMake(_currentIndex * self.width, 0) animated:NO];
- }
- [self resetIndicatorPoint];
-}
-
-- (void)nextPage {
- if (_itemViews.count > 1) {
- if (_infinite) {
- [self.scrollView setContentOffset:CGPointMake(self.width * 2, 0) animated:YES];
- } else {
- _currentIndex += 1;
- if (_currentIndex - 1 < _itemViews.count) {
- [self.scrollView setContentOffset:CGPointMake(_currentIndex * self.width, 0) animated:YES];
- }
- }
- }
-}
-
-- (void)resetScrollView {
- if (self.scrollView.contentOffset.x / self.width == 1)
- {
- return;
- }
- [self setCurrentIndex:self.nextIndex];
- self.scrollView.contentOffset = CGPointMake(self.width, 0);
-}
-
-#pragma mark Public Methods
-
-- (void)setIndicator:(WXIndicatorView *)indicator
-{
- _indicator = indicator;
- [_indicator setPointCount:self.itemViews.count];
- [_indicator setCurrentPoint:_currentIndex];
-}
-
-- (void)insertItemView:(UIView *)view atIndex:(NSInteger)index
-{
- if (![self.itemViews containsObject:view]) {
- view.tag = self.itemViews.count;
- if (index < 0) {
- [self.itemViews addObject:view];
- } else {
- [self.itemViews insertObject:view atIndex:index];
- }
- }
-
- if (![self.scrollView.subviews containsObject:view]) {
- if (index < 0) {
- [self.scrollView addSubview:view];
- } else {
- [self.scrollView insertSubview:view atIndex:index];
- }
- }
- [self layoutSubviews];
- [self setCurrentIndex:_currentIndex];
-}
-
-- (void)removeItemView:(UIView *)view
-{
- if ([self.itemViews containsObject:view]) {
- [self.itemViews removeObject:view];
- }
-
- if ([self.scrollView.subviews containsObject:view]) {
- [view removeFromSuperview];
- }
- [self layoutSubviews];
- [self setCurrentIndex:_currentIndex];
-}
-
-#pragma mark ScrollView Delegate
-
-- (void)scrollViewDidScroll:(UIScrollView *)scrollView
-{
- if (_infinite) {
- CGFloat offX = scrollView.contentOffset.x;
- self.direction = offX > self.width ? DirectionLeft : offX < self.width ? DirectionRight : DirectionNone;
- }
- if (self.delegate && [self.delegate respondsToSelector:@selector(recycleSliderView:didScroll:)]) {
- [self.delegate recycleSliderView:self didScroll:self.scrollView];
- }
-}
-
-- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
-{
- if (self.delegate && [self.delegate respondsToSelector:@selector(scrollViewWillBeginDragging:)]) {
- [self.delegate scrollViewWillBeginDragging:self.scrollView];
- }
-}
-
-- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
-{
- if (self.delegate && [self.delegate respondsToSelector:@selector(scrollViewDidEndDragging: willDecelerate:)]) {
- [self.delegate scrollViewDidEndDragging:self.scrollView willDecelerate:decelerate];
- }
-}
-
-- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
- if (_infinite) {
- [self resetScrollView];
- } else {
- NSInteger index = _scrollView.contentOffset.x / self.width;
- [self setCurrentIndex:index];
- }
-}
-
-- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
- if (_infinite) {
- [self resetScrollView];
- } else {
- NSInteger index = _scrollView.contentOffset.x / self.width;
- [self setCurrentIndex:index];
- }
-}
-
-@end
-
-@interface WXRecycleSliderComponent ()<WXRecycleSliderViewDelegate>
-
-@property (nonatomic, strong) WXRecycleSliderView *recycleSliderView;
-@property (nonatomic, strong) NSTimer *autoTimer;
-@property (nonatomic, assign) NSInteger currentIndex;
-@property (nonatomic, assign) BOOL autoPlay;
-@property (nonatomic, assign) NSUInteger interval;
-@property (nonatomic, assign) NSInteger index;
-@property (nonatomic, assign) CGFloat lastOffsetXRatio;
-@property (nonatomic, assign) CGFloat offsetXAccuracy;
-@property (nonatomic, assign) BOOL sliderChangeEvent;
-@property (nonatomic, assign) BOOL sliderScrollEvent;
-@property (nonatomic, assign) BOOL sliderScrollStartEvent;
-@property (nonatomic, assign) BOOL sliderScrollEndEvent;
-@property (nonatomic, assign) BOOL sliderStartEventFired;
-@property (nonatomic, strong) NSMutableArray *childrenView;
-@property (nonatomic, assign) BOOL scrollable;
-@property (nonatomic, assign) BOOL infinite;
-
-@end
-
-@implementation WXRecycleSliderComponent
-
-- (void) dealloc
-{
- [self _stopAutoPlayTimer];
-}
-
-- (instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDictionary *)styles attributes:(NSDictionary *)attributes events:(NSArray *)events weexInstance:(WXSDKInstance *)weexInstance
-{
- if (self = [super initWithRef:ref type:type styles:styles attributes:attributes events:events weexInstance:weexInstance]) {
- _sliderChangeEvent = NO;
- _sliderScrollEvent = NO;
- _interval = 3000;
- _childrenView = [NSMutableArray new];
- _lastOffsetXRatio = 0;
-
- if (attributes[@"autoPlay"]) {
- _autoPlay = [WXConvert BOOL:attributes[@"autoPlay"]];
- }
-
- if (attributes[@"interval"]) {
- _interval = [WXConvert NSInteger:attributes[@"interval"]];
- }
-
- if (attributes[@"index"]) {
- _index = [WXConvert NSInteger:attributes[@"index"]];
- }
- _scrollable = attributes[@"scrollable"] ? [WXConvert BOOL:attributes[@"scrollable"]] : YES;
- if (attributes[@"offsetXAccuracy"]) {
- _offsetXAccuracy = [WXConvert CGFloat:attributes[@"offsetXAccuracy"]];
- }
- _infinite = attributes[@"infinite"] ? [WXConvert BOOL:attributes[@"infinite"]] : YES;
- self.cssNode->style.flex_direction = CSS_FLEX_DIRECTION_ROW;
- }
- return self;
-}
-
-- (UIView *)loadView
-{
- return [[WXRecycleSliderView alloc] init];
-}
-
-- (void)viewDidLoad
-{
- [super viewDidLoad];
-
- _recycleSliderView = (WXRecycleSliderView *)self.view;
- _recycleSliderView.delegate = self;
- _recycleSliderView.scrollView.pagingEnabled = YES;
- _recycleSliderView.exclusiveTouch = YES;
- _recycleSliderView.scrollView.scrollEnabled = _scrollable;
- _recycleSliderView.infinite = _infinite;
- if (_autoPlay) {
- [self _startAutoPlayTimer];
- } else {
- [self _stopAutoPlayTimer];
- }
-}
-
-- (void)layoutDidFinish
-{
- _recycleSliderView.currentIndex = _index;
-}
-
-- (void)viewDidUnload
-{
- [_childrenView removeAllObjects];
-}
-
-- (void)insertSubview:(WXComponent *)subcomponent atIndex:(NSInteger)index
-{
- if (subcomponent->_positionType == WXPositionTypeFixed) {
- [self.weexInstance.rootView addSubview:subcomponent.view];
- return;
- }
-
- // use _lazyCreateView to forbid component like cell's view creating
- if(_lazyCreateView) {
- subcomponent->_lazyCreateView = YES;
- }
-
- 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];
- }
-
- WXRecycleSliderView *recycleSliderView = (WXRecycleSliderView *)self.view;
- if ([view isKindOfClass:[WXIndicatorView class]]) {
- [recycleSliderView addSubview:view];
- return;
- }
-
- subcomponent.isViewFrameSyncWithCalculated = NO;
-
- if (index == -1) {
- [recycleSliderView 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++;
- }
- }
- [recycleSliderView insertItemView:view atIndex:index - offset];
- }
- [recycleSliderView layoutSubviews];
- }
-}
-
-- (void)willRemoveSubview:(WXComponent *)component
-{
- UIView *view = component.view;
-
- if(self.childrenView && [self.childrenView containsObject:view]) {
- [self.childrenView removeObject:view];
- }
-
- WXRecycleSliderView *recycleSliderView = (WXRecycleSliderView *)_view;
- [recycleSliderView removeItemView:view];
- [recycleSliderView setCurrentIndex:0];
-}
-
-- (void)updateAttributes:(NSDictionary *)attributes
-{
- if (attributes[@"autoPlay"]) {
- _autoPlay = [WXConvert BOOL:attributes[@"autoPlay"]];
- if (_autoPlay) {
- [self _startAutoPlayTimer];
- } else {
- [self _stopAutoPlayTimer];
- }
- }
-
- if (attributes[@"interval"]) {
- _interval = [WXConvert NSInteger:attributes[@"interval"]];
- [self _stopAutoPlayTimer];
-
- if (_autoPlay) {
- [self _startAutoPlayTimer];
- }
- }
-
- if (attributes[@"index"]) {
- _index = [WXConvert NSInteger:attributes[@"index"]];
- self.currentIndex = _index;
- self.recycleSliderView.currentIndex = _index;
- }
-
- if (attributes[@"scrollable"]) {
- _scrollable = attributes[@"scrollable"] ? [WXConvert BOOL:attributes[@"scrollable"]] : YES;
- ((WXRecycleSliderView *)self.view).scrollView.scrollEnabled = _scrollable;
- }
-
- if (attributes[@"offsetXAccuracy"]) {
- _offsetXAccuracy = [WXConvert CGFloat:attributes[@"offsetXAccuracy"]];
- }
- if (attributes[@"infinite"]) {
- _infinite = [WXConvert BOOL:attributes[@"infinite"]];
- }
-}
-
-- (void)addEvent:(NSString *)eventName
-{
- if ([eventName isEqualToString:@"change"]) {
- _sliderChangeEvent = YES;
- }
- if ([eventName isEqualToString:@"scroll"]) {
- _sliderScrollEvent = YES;
- }
-}
-
-- (void)removeEvent:(NSString *)eventName
-{
- if ([eventName isEqualToString:@"change"]) {
- _sliderChangeEvent = NO;
- }
- if ([eventName isEqualToString:@"scroll"]) {
- _sliderScrollEvent = NO;
- }
-}
-
-#pragma mark Public Methods
-
--(void)setIndicatorView:(WXIndicatorView *)indicatorView
-{
- NSAssert(_recycleSliderView, @"");
- [_recycleSliderView setIndicator:indicatorView];
-}
-
-#pragma mark Private Methods
-
-- (void)_startAutoPlayTimer
-{
- if (!self.autoTimer || ![self.autoTimer isValid]) {
- __weak __typeof__(self) weakSelf = self;
- self.autoTimer = [NSTimer wx_scheduledTimerWithTimeInterval:_interval/1000.0f block:^() {
- [weakSelf _autoPlayOnTimer];
- } repeats:YES];
- [[NSRunLoop currentRunLoop] addTimer:self.autoTimer forMode:NSRunLoopCommonModes];
- }
-}
-
-- (void)_stopAutoPlayTimer
-{
- if (self.autoTimer && [self.autoTimer isValid]) {
- [self.autoTimer invalidate];
- self.autoTimer = nil;
- }
-}
-
-- (void)_autoPlayOnTimer
-{
- if (!_infinite && (_currentIndex == _recycleSliderView.itemViews.count - 1)) {
- [self _stopAutoPlayTimer];
- }else {
- [self.recycleSliderView nextPage];
- }
-}
-
-#pragma mark ScrollView Delegate
-
-- (void)recycleSliderView:(WXRecycleSliderView *)recycleSliderView didScroll:(UIScrollView *)scrollView
-{
- if (_sliderScrollEvent) {
- CGFloat width = scrollView.frame.size.width;
- CGFloat XDeviation = 0;
- if (_infinite) {
- XDeviation = - (scrollView.contentOffset.x - width);
- } else {
- XDeviation = - (scrollView.contentOffset.x - width * _currentIndex);
- }
- CGFloat offsetXRatio = (XDeviation / width);
- if (fabs(offsetXRatio - _lastOffsetXRatio) >= _offsetXAccuracy) {
- _lastOffsetXRatio = offsetXRatio;
- [self fireEvent:@"scroll" params:@{@"offsetXRatio":[NSNumber numberWithFloat:offsetXRatio]} domChanges:nil];
- }
- }
-}
-
-- (void)recycleSliderView:(WXRecycleSliderView *)recycleSliderView didScrollToItemAtIndex:(NSInteger)index
-{
- self.currentIndex = index;
- if (_sliderChangeEvent) {
- [self fireEvent:@"change" params:@{@"index":@(index)} domChanges:@{@"attrs": @{@"index": @(index)}}];
- }
-}
-
-- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
-{
- [self _stopAutoPlayTimer];
-}
-
-- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
-{
- if (_autoPlay) {
- [self _startAutoPlayTimer];
- }
-}
-
-@end
[8/9] incubator-weex git commit: * [ios] Relieve the dependency of
WXIndicatorComponent on the parent component .
Posted by bo...@apache.org.
* [ios] Relieve the dependency of WXIndicatorComponent on the parent component .
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/1f7a7dbf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/1f7a7dbf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/1f7a7dbf
Branch: refs/heads/0.12-dev
Commit: 1f7a7dbf57069bd82e1d7577e2a0d11be8264754
Parents: 10665be
Author: LiuHongfeng(GuJian) <La...@gmail.com>
Authored: Mon Apr 10 11:17:43 2017 +0800
Committer: LiuHongfeng(GuJian) <La...@gmail.com>
Committed: Mon Apr 10 11:17:43 2017 +0800
----------------------------------------------------------------------
.../Sources/Component/WXCycleSliderComponent.m | 5 +++--
.../Sources/Component/WXIndicatorComponent.h | 8 ++++++++
.../Sources/Component/WXIndicatorComponent.m | 21 +++++++-------------
.../Sources/Component/WXSliderComponent.m | 5 +++--
.../Component/WXSliderNeighborComponent.m | 5 ++++-
5 files changed, 25 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1f7a7dbf/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.m
index a8fc879..1db172a 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.m
@@ -303,7 +303,7 @@ typedef NS_ENUM(NSInteger, Direction) {
@end
-@interface WXCycleSliderComponent ()<WXRecycleSliderViewDelegate>
+@interface WXCycleSliderComponent () <WXRecycleSliderViewDelegate,WXIndicatorComponentDelegate>
@property (nonatomic, strong) WXRecycleSliderView *recycleSliderView;
@property (nonatomic, strong) NSTimer *autoTimer;
@@ -417,6 +417,7 @@ typedef NS_ENUM(NSInteger, Direction) {
WXRecycleSliderView *recycleSliderView = (WXRecycleSliderView *)self.view;
if ([view isKindOfClass:[WXIndicatorView class]]) {
+ ((WXIndicatorComponent *)subcomponent).delegate = self;
[recycleSliderView addSubview:view];
return;
}
@@ -512,7 +513,7 @@ typedef NS_ENUM(NSInteger, Direction) {
}
}
-#pragma mark Public Methods
+#pragma mark WXIndicatorComponentDelegate Methods
-(void)setIndicatorView:(WXIndicatorView *)indicatorView
{
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1f7a7dbf/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.h b/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.h
index faeae40..88347fd 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.h
+++ b/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.h
@@ -28,6 +28,14 @@ typedef enum
@end
+@protocol WXIndicatorComponentDelegate <NSObject>
+
+-(void)setIndicatorView:(WXIndicatorView *)indicatorView;
+
+@end
+
@interface WXIndicatorComponent : WXComponent
+@property (nonatomic, weak) id<WXIndicatorComponentDelegate> delegate;
+
@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1f7a7dbf/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
index 2647d61..39c081a 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXIndicatorComponent.m
@@ -7,10 +7,7 @@
*/
#import "WXIndicatorComponent.h"
-#import "WXSliderComponent.h"
-#import "WXCycleSliderComponent.h"
#import "WXConvert.h"
-#import "WXSliderNeighborComponent.h"
#import "WXSDKInstance.h"
@implementation WXIndicatorView
@@ -159,17 +156,13 @@
_indicatorView.lightColor = _itemSelectedColor;
_indicatorView.pointSize = _itemSize;
- WXComponent *parent = self.supercomponent;
- if([parent isKindOfClass:[WXSliderComponent class]]) {
- WXSliderComponent *parentSlider = (WXSliderComponent *)parent;
- [parentSlider setIndicatorView:_indicatorView];
- }
- if([parent isKindOfClass:[WXCycleSliderComponent class]]) {
- WXCycleSliderComponent *parentSlider = (WXCycleSliderComponent *)parent;
- [parentSlider setIndicatorView:_indicatorView];
- }else if ([parent isKindOfClass:[WXSliderNeighborComponent class]]) {
- WXSliderNeighborComponent *parentSlider = (WXSliderNeighborComponent *)parent;
- [parentSlider setIndicatorView:_indicatorView];
+
+}
+
+- (void)layoutDidFinish
+{
+ if (self.delegate && [self.delegate respondsToSelector:@selector(setIndicatorView:)]) {
+ [self.delegate setIndicatorView:_indicatorView];
}
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1f7a7dbf/ios/sdk/WeexSDK/Sources/Component/WXSliderComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXSliderComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXSliderComponent.m
index c85ba63..d3b5504 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXSliderComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXSliderComponent.m
@@ -327,7 +327,7 @@
@end
-@interface WXSliderComponent ()<WXSliderViewDelegate>
+@interface WXSliderComponent () <WXSliderViewDelegate,WXIndicatorComponentDelegate>
@property (nonatomic, strong) WXSliderView *sliderView;
@property (nonatomic, strong) NSTimer *autoTimer;
@@ -442,6 +442,7 @@
WXSliderView *sliderView = (WXSliderView *)self.view;
if ([view isKindOfClass:[WXIndicatorView class]]) {
+ ((WXIndicatorComponent *)subcomponent).delegate = self;
[sliderView addSubview:view];
return;
}
@@ -550,7 +551,7 @@
}
}
-#pragma mark Public Methods
+#pragma mark WXIndicatorComponentDelegate Methods
-(void)setIndicatorView:(WXIndicatorView *)indicatorView
{
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1f7a7dbf/ios/sdk/WeexSDK/Sources/Component/WXSliderNeighborComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXSliderNeighborComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXSliderNeighborComponent.m
index 830205e..9e2a50e 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXSliderNeighborComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXSliderNeighborComponent.m
@@ -1377,7 +1377,7 @@ NSComparisonResult sliderNeighorCompareViewDepth(UIView *view1, UIView *view2, W
@end
-@interface WXSliderNeighborComponent() {
+@interface WXSliderNeighborComponent () <WXIndicatorComponentDelegate>{
WXPixelType neighborSpace;
CGFloat neighborAlpha;
CGFloat neighborScale;
@@ -1487,6 +1487,7 @@ NSComparisonResult sliderNeighorCompareViewDepth(UIView *view1, UIView *view2, W
WXSliderNeighborView *sliderView = (WXSliderNeighborView *)self.view;
if ([view isKindOfClass:[WXIndicatorView class]]) {
+ ((WXIndicatorComponent *)subcomponent).delegate = self;
[sliderView addSubview:view];
return;
}
@@ -1586,6 +1587,8 @@ NSComparisonResult sliderNeighorCompareViewDepth(UIView *view1, UIView *view2, W
}
}
+#pragma mark WXIndicatorComponentDelegate Methods
+
- (void)setIndicatorView:(WXIndicatorView *)indicatorView
{
NSAssert(_sliderView, @"");