Skip to content

Commit

Permalink
feat(ios): add initialContentIndex prop for ListView
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Sep 12, 2024
1 parent 611006c commit 96af473
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions ios/sdk/component/listview/HippyBaseListView.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

@property (nonatomic, assign) NSUInteger preloadItemNumber;
@property (nonatomic, assign) CGFloat initialContentOffset;
@property (nonatomic, assign) NSUInteger initialContentIndex;
@property (nonatomic, assign) BOOL manualScroll;
@property (nonatomic, assign) BOOL bounces;
@property (nonatomic, assign) BOOL showScrollIndicator;
Expand Down
7 changes: 7 additions & 0 deletions ios/sdk/component/listview/HippyBaseListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ - (void)reloadData {
});
self.initialContentOffset = 0;
}
if (self.initialContentIndex > 0) {
NSUInteger initialContentIndex = self.initialContentIndex;
dispatch_async(dispatch_get_main_queue(), ^{
[self scrollToIndex:initialContentIndex animated:NO];
});
self.initialContentIndex = 0;
}

if (!_isInitialListReady) {
_isInitialListReady = YES;
Expand Down
1 change: 1 addition & 0 deletions ios/sdk/component/listview/HippyBaseListViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ @implementation HippyBaseListViewManager
HIPPY_EXPORT_VIEW_PROPERTY(preloadItemNumber, NSUInteger)
HIPPY_EXPORT_VIEW_PROPERTY(bounces, BOOL)
HIPPY_EXPORT_VIEW_PROPERTY(initialContentOffset, CGFloat)
HIPPY_EXPORT_VIEW_PROPERTY(initialContentIndex, NSUInteger)
HIPPY_EXPORT_VIEW_PROPERTY(editable, BOOL)
HIPPY_EXPORT_VIEW_PROPERTY(showScrollIndicator, BOOL)
HIPPY_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL)
Expand Down

0 comments on commit 96af473

Please sign in to comment.