Skip to content
This repository has been archived by the owner on Aug 14, 2019. It is now read-only.

[Springiness] Loading earlier messages results in garbled messages when using springiness #522

Closed
kartikthapar opened this issue Oct 2, 2014 · 9 comments
Labels

Comments

@kartikthapar
Copy link

Consider the following implementation in the example code —

- (void)collectionView:(JSQMessagesCollectionView *)collectionView
                header:(JSQMessagesLoadEarlierHeaderView *)headerView
didTapLoadEarlierMessagesButton:(UIButton *)sender
{
    // get earlier messages for example
    JSQMessage *message = [[JSQMessage alloc] initWithText:@"Hello" sender:kJSQDemoAvatarNameCook date:[NSDate date]];
    [self.messages insertObject:message atIndex:0];

    [self.collectionView.collectionViewLayout invalidateLayoutWithContext:[JSQMessagesCollectionViewFlowLayoutInvalidationContext context]];
    [self.collectionView reloadData];

    NSLog(@"Load earlier messages!");
}

The same issue doesn't come up when I disable springiness.

@kartikthapar
Copy link
Author

I have a really f'd up fix for this and I have no clue why this is happening (first instinct I guess —)

- (void)collectionView:(JSQMessagesCollectionView *)collectionView
                header:(JSQMessagesLoadEarlierHeaderView *)headerView
didTapLoadEarlierMessagesButton:(UIButton *)sender
{
    self.collectionView.collectionViewLayout.springinessEnabled = NO;
    // < add message to messages, etc>
    self.collectionView.collectionViewLayout.springinessEnabled = YES;
    NSLog(@"Load earlier messages!");
}

Works when springiness is enabled in viewDidAppear:.

Again, no clue why this works.

@jessesquires jessesquires changed the title Loading earlier messages results in garbled messages when using springiness [Springiness] Loading earlier messages results in garbled messages when using springiness Oct 2, 2014
@jessesquires
Copy link
Owner

Thanks @kartikthapar - as noted in the docs and in the demo, springiness is still an experimental feature.

This workaround makes perfect sense.

  1. Turn off UIDynamics (also invalidates the layout)
  2. Load new data
  3. Turn on UIDynamics (also invalidates the layout)

@kartikthapar
Copy link
Author

I guess I should read the fucking documentation. Thanks!

@jessesquires
Copy link
Owner

Hahaha 😆 👍

@jessesquires
Copy link
Owner

Hey @kartikthapar - some recent changes may have fixed this. Can you pull the latest from develop and see?

@kartikthapar
Copy link
Author

I'll have an update on this shorty.

@kartikthapar
Copy link
Author

I just added a simple text message —

JSQMessage *newMessage = [[JSQTextMessage alloc] initWithSenderId:kJSQDemoAvatarDisplayNameSquires
                                                senderDisplayName:kJSQDemoAvatarDisplayNameSquires
                                                             date:[NSDate date]
                                                             text:@"It Works (?)"];

[self.demoData.messages insertObject:newMessage atIndex:0];

[self.collectionView.collectionViewLayout invalidateLayoutWithContext:[JSQMessagesCollectionViewFlowLayoutInvalidationContext context]];
[self.collectionView reloadData];

and this seems to work absolutely fine. Thanks!

@jessesquires
Copy link
Owner

Awesome! thanks @kartikthapar !

@iphoneandroidtesting
Copy link

Hello @kartikthapar After tap on 'load earlier message',how can i show messages before "LoadEarlierMessages" button ,like as a facebook comments view.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants