From 9f3724a9279b209d682c809b3e3b3f13f67420d2 Mon Sep 17 00:00:00 2001 From: wwwcg Date: Fri, 20 Sep 2024 20:33:32 +0800 Subject: [PATCH] feat(ios): add initialContentIndex prop for ListView (#4029) --- ios/sdk/component/listview/HippyBaseListView.h | 1 + ios/sdk/component/listview/HippyBaseListView.m | 7 +++++++ ios/sdk/component/listview/HippyBaseListViewManager.m | 1 + 3 files changed, 9 insertions(+) diff --git a/ios/sdk/component/listview/HippyBaseListView.h b/ios/sdk/component/listview/HippyBaseListView.h index 5abdea93e3f..b43356e16ba 100644 --- a/ios/sdk/component/listview/HippyBaseListView.h +++ b/ios/sdk/component/listview/HippyBaseListView.h @@ -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; diff --git a/ios/sdk/component/listview/HippyBaseListView.m b/ios/sdk/component/listview/HippyBaseListView.m index 0d4bbc4fc22..ccd462ec877 100644 --- a/ios/sdk/component/listview/HippyBaseListView.m +++ b/ios/sdk/component/listview/HippyBaseListView.m @@ -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; diff --git a/ios/sdk/component/listview/HippyBaseListViewManager.m b/ios/sdk/component/listview/HippyBaseListViewManager.m index b03eb190800..01598cda229 100644 --- a/ios/sdk/component/listview/HippyBaseListViewManager.m +++ b/ios/sdk/component/listview/HippyBaseListViewManager.m @@ -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)