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

Commit 72440a8

Browse files
blackteachinesecxfeng1
authored andcommitted
[WEEX-657][iOS] Add a feature to control the offset of list attach to the bottom` (#1813)
I have add a '_isContentAttachBottom' attribute in WXListComponent to controll whether open this feature. The Weex Component can pass the ‘_isContentAttachBottom’ variable from js to native by 'initWithRef' and 'updateAttributes' function. The '_isContentAttachBottom' variable will be analysed to a bool type and cached in WXTableView object. When the WXTableView object is called the 'setFrame' function,if the '_isContentAttachBottom' variable is true , then the 'contentOffset' function of WXTableView object will be triggered to keep the content offset at the bottom.When the WXTableView object is running the transition animation, the 'setFrame' will be call every 16 msec . So when the animation is excuting,the content offset of list will be alaways attached to the bottom . feature: 657
1 parent 6e5d3bf commit 72440a8

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

ios/sdk/WeexSDK/Sources/Component/WXListComponent.mm

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
#import "WXRefreshComponent.h"
3333
#import "WXLoadingComponent.h"
3434

35+
@interface WXListComponent () <UITableViewDataSource, UITableViewDelegate, WXCellRenderDelegate, WXHeaderRenderDelegate>
36+
37+
@property (nonatomic, assign) NSUInteger currentTopVisibleSection;
38+
// Set whether the content offset position all the way to the bottom
39+
@property (assign, nonatomic) BOOL contentAttachBottom;
40+
41+
@end
42+
3543
@interface WXTableView : UITableView
3644

3745
@end
@@ -79,6 +87,18 @@ - (void)setContentOffset:(CGPoint)contentOffset
7987
[super setContentOffset:contentOffset];
8088
}
8189

90+
- (void)setFrame:(CGRect)frame {
91+
[super setFrame:frame];
92+
if (![self.wx_component isKindOfClass:[WXListComponent class]]) return;
93+
BOOL contentAttachBottom = [(WXListComponent *)self.wx_component contentAttachBottom];
94+
if (contentAttachBottom) {
95+
CGFloat offsetHeight = self.contentSize.height - CGRectGetHeight(self.bounds);
96+
if (offsetHeight >= 0) {
97+
[self setContentOffset:CGPointMake(0, offsetHeight) animated:NO];
98+
}
99+
}
100+
}
101+
82102
@end
83103

84104
// WXText is a non-public is not permitted
@@ -114,12 +134,6 @@ - (NSString *)description
114134
}
115135
@end
116136

117-
@interface WXListComponent () <UITableViewDataSource, UITableViewDelegate, WXCellRenderDelegate, WXHeaderRenderDelegate>
118-
119-
@property (nonatomic, assign) NSUInteger currentTopVisibleSection;
120-
121-
@end
122-
123137
@implementation WXListComponent
124138
{
125139
__weak UITableView * _tableView;
@@ -144,6 +158,7 @@ - (instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDict
144158
_completedSections = [NSMutableArray array];
145159
_reloadInterval = attributes[@"reloadInterval"] ? [WXConvert CGFloat:attributes[@"reloadInterval"]]/1000 : 0;
146160
_updataType = [WXConvert NSString:attributes[@"updataType"]]?:@"insert";
161+
_contentAttachBottom = [WXConvert BOOL:attributes[@"contentAttachBottom"]];
147162
[self fixFlicker];
148163
}
149164

@@ -198,6 +213,9 @@ - (void)updateAttributes:(NSDictionary *)attributes
198213
if (attributes[@"updataType"]) {
199214
_updataType = [WXConvert NSString:attributes[@"updataType"]];
200215
}
216+
if (attributes[@"contentAttachBottom"]) {
217+
_contentAttachBottom = [WXConvert BOOL:attributes[@"contentAttachBottom"]];
218+
}
201219
}
202220

203221
- (void)setContentSize:(CGSize)contentSize

0 commit comments

Comments
 (0)