iOS: impl scroll to item with top offset api

This commit is contained in:
王劲鹏 2023-08-03 19:03:17 +08:00 committed by osborn
parent 79cef25191
commit 3dd44cf9f7

View File

@ -663,7 +663,18 @@ - (void)scrollToItem:(NSDictionary *)params {
for (int i = 0; i <= scrolledPosition; i++) {
[self calculateCellHeightItemNode:node atIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
}
if (params[@"topOffset"] != nil) {
CGFloat topOffset = [params[@"topOffset"] floatValue];
[self.view layoutIfNeeded];
NSIndexPath *targetIndexPath = [NSIndexPath indexPathForRow:scrolledPosition inSection:0];
CGRect rect = [self.view rectForRowAtIndexPath:targetIndexPath];
CGPoint newContentOffset = CGPointMake(self.view.contentOffset.x, rect.origin.y + topOffset);
[self.view setContentOffset:newContentOffset animated:animated];
} else {
[self.view scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:scrolledPosition inSection:0] atScrollPosition:UITableViewScrollPositionNone animated:animated];
}
});
} else {
[self.doricContext.driver.registry onLog:DoricLogTypeError