eBay/NMessenger

[question] how to change colour of an already added bubble

Closed this issue · 7 comments

messageNode.contentNode?.backgroundBubble?.bubbleColor = UIColor.green

messageNode.setNeedsLayout()
messageNode.contentNode?.setNeedsLayout()

This works only for the first time.
The Bubble.createLayer() and Bubble.sizeToBounds() overrides are invoked twice as expected.

[VHMessageNode] setNewMessageMode | Optional("6EDD890C-0A2F-4F6E-A973-B5F578C810C2")
[XMPP] [message] [SEND] : - XMPPFramework's @objc(xmppStream:didSendMessage:) invoked
VHBubbleCenterTriangle.sizeToBounds 
VHBubbleCenterTriangle.createLayer

VHBubbleCenterTriangle.sizeToBounds
VHBubbleCenterTriangle.createLayer
[VHMessageNode] setMessageSentMode | Optional("6EDD890C-0A2F-4F6E-A973-B5F578C810C2")

Some logs.

P.S. Strange that the second pair of ["sizeToBounds" , "createLayer"] is invoked prior to setMessageSentMode and not afterwards.

I've replaced setNeedsLayout() with setNeedsDisplay() and the changes took effect.

Could you please provide any example for this? I am trying to achieve the same thing. I am trying to change the appearance of already Laidout message node. But it is not taking effect.

@pvsantosh , please share a snippet of your code.

Here is what worked for me according to my previous comment :

messageNode.contentNode?.backgroundBubble?.bubbleColor = UIColor.green
messageNode.setNeedsDisplay()
messageNode.contentNode?..setNeedsDisplay()

@dodikk, Thank you for responding. I am trying to update the appearance in the Datasource array. and trying to reload in override open func animateLayoutTransition(_ context: ASContextTransitioning) method's .added case completion block in MessageGroup.swift(inside pod codebase).

let idxPath = IndexPath(row: self.messages.count - 2, section: 0)
if var newMessage = self.messages[self.messages.count-1] as? MessageNode {
    newMessage.contentNode?.backgroundBubble = newMessage.contentNode?.bubbleConfiguration.getMiddleBubble()
    newMessage.isIncomingMessage = self.isIncomingMessage
    newMessage.messageOffset = 0
    newMessage.contentNode?.backgroundBubble?.bubbleColor = .red
    newMessage.contentNode?.setNeedsDisplay()
    self.messages[idxPath] = newMessage
}
self.messageTable.reloadRows(at: [idxPath], with: animation)

After I reload It is still showing the old color of the bubble. In the snippet, MiddleBubble is another bubble I created similar to StackedBubble. Is my approach correct? or Should I do this from some other class?

messageNode.contentNode?.backgroundBubble?.bubbleColor = UIColor.green
messageNode.setNeedsDisplay()
messageNode.contentNode?..setNeedsDisplay()

I have done this but bubble color is not changed. I am override func sendText(_ text: String, isIncomingMessage: Bool) -> GeneralMessengerCell in this function I have added the above code.

Is my approach correct?

Even though NMessenger is based on AsyncDisplayKit (rebranded as Texture), some things might still need to be performed on main thread. I have not figured out the exact rules but just try dispatching the mentioned code to the main queue.
Just an idea.

P.S. Sorry, it's really hard to tell if your approach is correct. I've described in the issues and comments all the things I've figured out already.