Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrolling like WhatsApp Chat where scrolling to top, scrolling further shows "Archived Chats"

Just not getting the proper search term, but my question is how can i achieve this tableview feature where i can scroll to top, but only on further scrolling to top, a row appears on top of the first row.

Similar feature where WhatsApp uses to show "Archived Chats", here scrolling to your chat list, further scrolling shows you Archived chats.

I am using swift 2.3

Thank you

like image 805
niravdesai21 Avatar asked Nov 07 '16 13:11

niravdesai21


People also ask

Why is WhatsApp showing archived messages on top?

You might have noticed a number next to the “Archived” text. It indicates how many archived individual or group chats have unread messages. If you are seeing the Archived box on top of the screen, it means that all your archived chats will always remain hidden and you will never see a new message from archived chats.

How do I get to the top of a WhatsApp chat without scrolling?

Less scrolling. Open the media file (probably an image) and click on the three horizontal dots on upper right corner and then click SHOW IN CHAT. It will take you to that time in the chat when the media file was shared. Now the very beginning of your chat won't be to far.

How do I move archived chats on WhatsApp from top to bottom?

You will be able to see the archived chats on the screen. Click the three dots at the top right corner and then select 'Archive settings'. Disable the 'Keep Chats Archived' option. After disabling the feature, the archived box will no longer be there on the top of the chat window.


1 Answers

Maybe a bit late, but here you have a workaround (objective-c) to replicate the whatsapp archived chats scroll further feature:

I use two booleans to determine if table view is at top position and if the archived chats row is visible.

@property (assign, nonatomic) BOOL isArchivedChatsRowVisible;
@property (assign, nonatomic) BOOL isScrollAtTop;

And with the scroll view delegate, using these bools, insert or remove a section for displaying the archive chats cell.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.y > 0 && self.isArchivedChatsRowVisible) {
        self.isScrollAtTop = NO;
        self.isArchivedChatsRowVisible = NO;
        [self.tableView beginUpdates];
        [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
        [self.tableView endUpdates];
    }

    if (self.isScrollAtTop && scrollView.contentOffset.y < 0 && !self.isArchivedChatsRowVisible) {
        self.isArchivedChatsRowVisible = YES;
        [self.tableView beginUpdates];
        [self.tableView insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationMiddle];
        [self.tableView endUpdates];
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {      
    self.isScrollAtTop = scrollView.contentOffset.y > 0 ? NO : YES;
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    if (scrollView.contentOffset.y > 0) {
        self.isScrollAtTop = NO;
    }
}

I hope it would be useful

like image 69
cmacera Avatar answered Oct 21 '22 20:10

cmacera