Skip to content

Commit 3dd44cf

Browse files
jingpengpenfeizhou
authored andcommitted
iOS: impl scroll to item with top offset api
1 parent 79cef25 commit 3dd44cf

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

doric-iOS/Pod/Classes/Shader/DoricListNode.m

+12-1
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,18 @@ - (void)scrollToItem:(NSDictionary *)params {
663663
for (int i = 0; i <= scrolledPosition; i++) {
664664
[self calculateCellHeightItemNode:node atIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
665665
}
666-
[self.view scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:scrolledPosition inSection:0] atScrollPosition:UITableViewScrollPositionNone animated:animated];
666+
667+
if (params[@"topOffset"] != nil) {
668+
CGFloat topOffset = [params[@"topOffset"] floatValue];
669+
[self.view layoutIfNeeded];
670+
NSIndexPath *targetIndexPath = [NSIndexPath indexPathForRow:scrolledPosition inSection:0];
671+
CGRect rect = [self.view rectForRowAtIndexPath:targetIndexPath];
672+
CGPoint newContentOffset = CGPointMake(self.view.contentOffset.x, rect.origin.y + topOffset);
673+
674+
[self.view setContentOffset:newContentOffset animated:animated];
675+
} else {
676+
[self.view scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:scrolledPosition inSection:0] atScrollPosition:UITableViewScrollPositionNone animated:animated];
677+
}
667678
});
668679
} else {
669680
[self.doricContext.driver.registry onLog:DoricLogTypeError

0 commit comments

Comments
 (0)