From 33c681031d08b3cce3f6c15b302dd9d038839e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Wed, 11 Aug 2021 15:50:10 +0800 Subject: [PATCH] fix: iOS List scroll to row inaccurate --- doric-iOS/Pod/Classes/Shader/DoricListNode.m | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricListNode.m b/doric-iOS/Pod/Classes/Shader/DoricListNode.m index 160e80da..6bcad401 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricListNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricListNode.m @@ -431,7 +431,19 @@ - (void)removeDidScrollBlock:(__nonnull DoricDidScrollBlock)didScrollListener { - (void)scrollToItem:(NSDictionary *)params { BOOL animated = [params[@"animated"] boolValue]; NSUInteger scrolledPosition = [params[@"index"] unsignedIntegerValue]; - [self.view scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:scrolledPosition inSection:0] atScrollPosition:UITableViewScrollPositionNone animated:animated]; + + if (scrolledPosition < self.itemCount && scrolledPosition >= 0) { + for (int i = 0; i <= scrolledPosition; i++) { + [self tableView:self.view cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]; + } + + dispatch_async(dispatch_get_main_queue(), ^{ + [self.view scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:scrolledPosition inSection:0] atScrollPosition:UITableViewScrollPositionNone animated:animated]; + }); + } else { + [self.doricContext.driver.registry onLog:DoricLogTypeError + message:[NSString stringWithFormat:@"scrollToItem Error:%@", @"scrolledPosition range error"]]; + } } @end