Reactions
Reactions copied to clipboard
does not work after i call view from tabbar
when i go to the rection view from tabbar it give me error (Fatal error: Unexpectedly found nil while unwrapping an Optional value) and some warnings like ([framework] CUICatalog: Invalid asset name supplied:
[1771:665213] Could not load the "" image referenced from a nib in the bundle with identifier " ")
Without more details I couldn't be able to help you.
Do you keep weak references of the reactions selector?
For this kind of issue I suggest you to use stackoverflow, you'll have help faster.
@yannickl Hey Yannick, this is happening on iPhone X as well (not on iPhone 7 Plus though).
class HomeCell: UITableViewCell {
var postID: Int?
let reactionIDs = ["like", "love", "haha", "wow", "sad", "angry"]
var reactionDelegate: HomeCellDelegate?
@IBOutlet weak var profileImageView: UIImageView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var photoImageView: UIImageView!
@IBOutlet weak var buttonsView: UIView!
@IBOutlet weak var usernameLabel: UILabel!
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var reactionButton: ReactionButton!
// We have to know what the last focused reaction was, since selectorReaction is null at the beginning
private var lastFocusedReaction: Reaction?
override func awakeFromNib() {
super.awakeFromNib()
containerView.layer.cornerRadius = 20
containerView.layer.shadowOpacity = 0.2 // opacity, 20%
containerView.layer.shadowColor = UIColor.black.cgColor
containerView.layer.shadowRadius = 2 // HALF of blur
containerView.layer.shadowOffset = CGSize(width: 0, height: 2) // Spread x, y
containerView.layer.masksToBounds = false
setupReactionButton()
}
private func setupReactionButton() {
//let likeReaction = Reaction(id: "like", title: "Like", color: .blue, icon: #imageLiteral(resourceName: "like"))
let reactionSelector = ReactionSelector()
reactionButton.reaction = Reaction.facebook.like
// reactionSelector.feedbackDelegate = self
reactionSelector.reactions = Reaction.facebook.all
// React to reaction change
// This one takes a value from ReactionSelector
reactionButton.addTarget(self, action: #selector(reactionChanged), for: .valueChanged)
// And this one from ReactionButton
reactionButton.addTarget(self, action: #selector(reactionChanged), for: .touchUpInside)
// To attach a selector
reactionButton.reactionSelector = reactionSelector
// The last focused reaction is empty, so we'll make it the first of the reactions
lastFocusedReaction = reactionSelector.reactions.first
}
override func layoutSubviews() {
super.layoutSubviews()
buttonsView.roundCorners(corners: [.bottomLeft, .bottomRight], radius: 20)
profileImageView.layer.cornerRadius = profileImageView.frame.height / 2
profileImageView.layer.masksToBounds = true
}
@objc func reactionChanged(_ sender: AnyObject) {
guard let reaction = self.reactionButton.reactionSelector?.selectedReaction else {
// No reaction here. This happens when tapping the button.
// We'll use the selected state to know if the content was liked or unliked (or other reaction).
if let reaction = lastFocusedReaction, let index = reactionIDs.index(of: reaction.id) {
if (reactionButton.isSelected) {
reactionDelegate?.didChangeReaction(reactionNumber: index + 1, postID: postID ?? 0)
// The current reaction was selected (liked, loved, wow-ed, etc.)
// Here you'll want to inform the delegate that a reaction was chosen
}
else {
// The content was unliked, un-haha-ed, un-wow-ed, whatever.
// Check lastFocusedReaction for the correct reaction that was deselected.
// Here you'll want to inform the delegate that a reaction was chosen
reactionDelegate?.didChangeReaction(reactionNumber: 0, postID: postID ?? 0)
}
}
// Nothing to do here.
return;
}
lastFocusedReaction = reaction
// Reaction was selected through ReactionSelector()
if (reactionButton.isSelected) {
if let lastFocusedReaction = lastFocusedReaction, let index = reactionIDs.index(of: lastFocusedReaction.id) {
reactionDelegate?.didChangeReaction(reactionNumber: index + 1, postID: postID ?? 0)
}
// Here you'll want to inform the delegate that a reaction was selected
}
else {
// Here you'll want to inform the delegate that a reaction was de-selected
reactionDelegate?.didChangeReaction(reactionNumber: 0, postID: postID ?? 0)
}
}
}
This is the line that gives the error:
private static func imageWithName(_ name: String) -> UIImage {
return UIImage(named: name, in: .reactionsBundle(), compatibleWith: nil)!
}
This is a little weird, would you mind taking a look at the code? It looks like the app can't find the reactions bundle.
@csr thank you for reporting this. Is it reproductible on the simulator? It happens every time with the iPhone X (and only with the iPhone X in your case)?
How do you import the library? Using Cocoapods?
we’re importing it with CocoaPods, yes it works on the simulator fine, just not on iPhone X.