-
Notifications
You must be signed in to change notification settings - Fork 270
[wish] images and text within a single content node out of box #143
Comments
I've managed to subclass A pull request will follow but here is the code : import Foundation
import AsyncDisplayKit
open class CollectionViewWithTextContentNode: CollectionViewContentNode
{
public var textMessageNode: ASTextNode?
public var timestampNode : ASTextNode?
override open func layoutSpecThatFits(
_ constrainedSize: ASSizeRange)
-> ASLayoutSpec
{
guard let textMessageNodeUnwrap = self.textMessageNode,
let timestampNodeUnwrap = self.timestampNode
else
{
return super.layoutSpecThatFits(constrainedSize)
}
// ====
//
let cellsLayout = super.layoutSpecThatFits(constrainedSize)
let imagesPaddingInsets =
UIEdgeInsets(
top: 4,
left: 15,
bottom: 15,
right: 4)
let imagesPadding =
ASInsetLayoutSpec(
insets: imagesPaddingInsets,
child: cellsLayout)
// ==== timestampNode
//
let timespampPaddingInsets =
UIEdgeInsets(
top: 10,
left: 15,
bottom: 0,
right: 0)
let timestampPadding =
ASInsetLayoutSpec(
insets: timespampPaddingInsets,
child: timestampNodeUnwrap)
// ==== textMessageNode
//
let labelPaddingInsets =
UIEdgeInsets(
top: 5,
left: 15,
bottom: 0,
right: 0)
let labelPadding =
ASInsetLayoutSpec(
insets: labelPaddingInsets,
child: textMessageNodeUnwrap)
// ====
//
let result =
ASStackLayoutSpec(
direction: .vertical,
spacing: 5,
justifyContent: .start,
alignItems: .start,
children: [timestampPadding, labelPadding, imagesPadding])
return result
}
} |
also using `defer` keyrowd for safer `imageListGuard.unlock`
Implemented in #146 |
hi @dodikk, I see that you're using tabBarController with NMessenger. I have question regarding that: |
@ignotusverum , unfortunately, I have not reproduced the described issue.
Please check the P.S. I believe, you should create a separate github issue and continue the discussion there. Some screenshots or code of your chat view setup would be helpful (but again, not in this github issue). |
also using `defer` keyrowd for safer `imageListGuard.unlock`
A better implementation to avoid ugly inheritance #170 class VHMessageContentNode: ContentNode {
public var textNode: ASTextNode?
public var timestampNode: ASTextNode?
public var attachmentsNode: CollectionViewContentNode?
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let children: [ASLayoutElement?] = [self.timestampNode,
self.textNode,
self.attachmentsNode]
let stackSpec = ASStackLayoutSpec(direction: .vertical,
spacing: 5,
justifyContent: .start,
alignItems: .start,
children: children.flatMap { $0 })
let insets = UIEdgeInsets(top: 10, left: 15, bottom: 10, right: 15)
let insetSpec = ASInsetLayoutSpec(insets: insets,
child: stackSpec)
return insetSpec
}
} |
@dodikk can you share how to use this VHMessageContentNode in example app provided in this lib. |
@iOSUser110 , you should take the steps below :
// create an instance
//
let contentNode = VHMessageContentNode()
// setup the fields
//
contentNode.textNode = ...;
contentNode.timestampNode = ...;
// create a message node with the content node
//
let messageNode = VHMessageNode(content: contentNode)
// put the node to NMessenger instance
//
nmessengerView. addMessages([messageNode], scrollsToMessage: false) |
@iOSUser110 , actually, the steps are the same as for the built-in |
@iOSUser110 , please keep in mind that So, unfortunately, you'll have to copy-paste this code to your app codebase. P.S. Not sure if the class will ever make it to the codebase as not all users might need a timestamp. So I left the example code snippet in this ticket. |
Often there is a case when a message bubble should contain both
So far, each user is forced to implement that as a
CustomNode
. HavingUICollectionView
inside an AsyncDisplayKit node might hit the performance. On the other hand, AsyncDisplayKit might be hard to deal with for some users.It would be nice to have such node out of box in the NMessenger.
Or a snippet in the README, at least.
The text was updated successfully, but these errors were encountered: