I was wondering which was the correct approach to setting a minimum width for some bubbles. I've tried overriding the applyLayoutAttributes: in my custom cell, but I need access to my datasource to know which cell should have a minimum width. I've been tinkering with messageBubbleLeftRightMargin in cellForItemAtIndexPath: but with no results. Any pointers would be great
EDIT
My Message model (which conforms to ) has a flag which tells me if the bubble needs to have a minimum width
In my custom cell, I can override the custom layout, but I don't have access to the datasource, hence I have no access to that flag
-(void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
JSQMessagesCollectionViewLayoutAttributes *customAttributes = (JSQMessagesCollectionViewLayoutAttributes *)layoutAttributes;
// I need access to my <JSQMessageData> for the condition
if (condition) {
if(customAttributes.messageBubbleContainerViewWidth <175){
customAttributes.messageBubbleContainerViewWidth = 175;
}
}
[super applyLayoutAttributes:customAttributes];
}
I also tried in my JSQMessagesViewController subclass to access the leftright constraint, but to no avail
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
/**
* Override point for customizing cells
*/
JSQMessagesCollectionViewCell *cell = (JSQMessagesCollectionViewCell *)[super collectionView:collectionView cellForItemAtIndexPath:indexPath];
BLMessage *message = [self.visibleMessagesArray objectAtIndex:indexPath.item];
JSQMessagesCollectionViewLayoutAttributes *customAttributes = [JSQMessagesCollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
if(message.isEphemeral){
//random number to see if it had an effect
self.collectionView.collectionViewLayout.messageBubbleLeftRightMargin = 200;
//I also tried modifying the customAttributes
//customAttributes.messageBubbleContainerViewWidth = 175;
}
return cell;
}
I'm kind of new to the UICollectionViewFlowLayout and such, I may be missing some core concepts