mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 00:52:43 +02:00
Update for PR feedback.
URLPreviewManager becomes URLPreviewService. addVerticalWhitespaceToString used instead of heightForCellData multiple times. All newline characters removed.
This commit is contained in:
@@ -444,43 +444,7 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05;
|
||||
[self userInterfaceThemeDidChange];
|
||||
|
||||
// Observe URL preview updates.
|
||||
URLPreviewDidUpdateNotificationObserver = [NSNotificationCenter.defaultCenter addObserverForName:URLPreviewDidUpdateNotification object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull notification) {
|
||||
|
||||
// Ensure this is the correct room
|
||||
if (![(NSString*)notification.userInfo[@"roomId"] isEqualToString:self.roomDataSource.roomId])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the indexPath for the updated cell.
|
||||
NSString *updatedEventId = notification.userInfo[@"eventId"];
|
||||
NSInteger updatedEventIndex = [self.roomDataSource indexOfCellDataWithEventId:updatedEventId];
|
||||
NSIndexPath *updatedIndexPath = [NSIndexPath indexPathForRow:updatedEventIndex inSection:0];
|
||||
|
||||
// Store the content size and offset before reloading the cell
|
||||
CGFloat originalContentSize = self.bubblesTableView.contentSize.height;
|
||||
CGPoint contentOffset = self.bubblesTableView.contentOffset;
|
||||
|
||||
// Only update the content offset if the cell is visible or above the current visible cells.
|
||||
BOOL shouldUpdateContentOffset = NO;
|
||||
NSIndexPath *lastVisibleIndexPath = [self.bubblesTableView indexPathsForVisibleRows].lastObject;
|
||||
if (lastVisibleIndexPath && updatedIndexPath.row < lastVisibleIndexPath.row)
|
||||
{
|
||||
shouldUpdateContentOffset = YES;
|
||||
}
|
||||
|
||||
// Note: Despite passing in the index path, this reloads the whole table.
|
||||
[self dataSource:self.roomDataSource didCellChange:updatedIndexPath];
|
||||
|
||||
// Update the content offset to include any changes to the scroll view's height.
|
||||
if (shouldUpdateContentOffset)
|
||||
{
|
||||
CGFloat delta = self.bubblesTableView.contentSize.height - originalContentSize;
|
||||
contentOffset.y += delta;
|
||||
|
||||
self.bubblesTableView.contentOffset = contentOffset;
|
||||
}
|
||||
}];
|
||||
[self registerURLPreviewNotifications];
|
||||
|
||||
[self setupActions];
|
||||
}
|
||||
@@ -1556,6 +1520,47 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05;
|
||||
return myPower >= requiredPower;
|
||||
}
|
||||
|
||||
- (void)registerURLPreviewNotifications
|
||||
{
|
||||
URLPreviewDidUpdateNotificationObserver = [NSNotificationCenter.defaultCenter addObserverForName:URLPreviewDidUpdateNotification object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull notification) {
|
||||
|
||||
// Ensure this is the correct room
|
||||
if (![(NSString*)notification.userInfo[@"roomId"] isEqualToString:self.roomDataSource.roomId])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the indexPath for the updated cell.
|
||||
NSString *updatedEventId = notification.userInfo[@"eventId"];
|
||||
NSInteger updatedEventIndex = [self.roomDataSource indexOfCellDataWithEventId:updatedEventId];
|
||||
NSIndexPath *updatedIndexPath = [NSIndexPath indexPathForRow:updatedEventIndex inSection:0];
|
||||
|
||||
// Store the content size and offset before reloading the cell
|
||||
CGFloat originalContentSize = self.bubblesTableView.contentSize.height;
|
||||
CGPoint contentOffset = self.bubblesTableView.contentOffset;
|
||||
|
||||
// Only update the content offset if the cell is visible or above the current visible cells.
|
||||
BOOL shouldUpdateContentOffset = NO;
|
||||
NSIndexPath *lastVisibleIndexPath = [self.bubblesTableView indexPathsForVisibleRows].lastObject;
|
||||
if (lastVisibleIndexPath && updatedIndexPath.row < lastVisibleIndexPath.row)
|
||||
{
|
||||
shouldUpdateContentOffset = YES;
|
||||
}
|
||||
|
||||
// Note: Despite passing in the index path, this reloads the whole table.
|
||||
[self dataSource:self.roomDataSource didCellChange:updatedIndexPath];
|
||||
|
||||
// Update the content offset to include any changes to the scroll view's height.
|
||||
if (shouldUpdateContentOffset)
|
||||
{
|
||||
CGFloat delta = self.bubblesTableView.contentSize.height - originalContentSize;
|
||||
contentOffset.y += delta;
|
||||
|
||||
self.bubblesTableView.contentOffset = contentOffset;
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)refreshRoomTitle
|
||||
{
|
||||
NSMutableArray *rightBarButtonItems = nil;
|
||||
|
||||
Reference in New Issue
Block a user