BulletinBoard
BulletinBoard copied to clipboard
assertIsPrepared() being called randomly
Problem Description: My app would randomly crash due to assertIsPrepared() being called. Is this a known bug or am I doing something wrong?
fileprivate func assertIsPrepared() {
precondition(isPrepared, "You must call the `prepare` function before interacting with the bulletin.")
}
Steps to reproduce: This is what I call when a button is pressed:
bulletinManager.backgroundViewStyle = .none
bulletinManager.backgroundColor = UIColor(red:0.30, green:0.69, blue:0.94, alpha:1.00)
bulletinManager.showBulletin(above: self)
The crash seems random.
Environment:
- Device: N/A
- OS: iOS12
- Version of BulletinBoard: 2.0.2
I'm having this issue when I hit the close button. Often happens the second time I present the Bulletin, sometimes during the first time.
I'm having this issue when I hit the close button. Often happens the second time I present the Bulletin, sometimes during the first time.
Yes, it happens when the bulletin board gets dismissed, it doesn't happen to me that often though.
I would love to investigate this issue. Could you paste your code how you initialize the manager and the rootItem?
Sent with GitHawk
Here's how it's initialised:
let page = BLTNPageItem(title: "STATS")
lazy var bulletinManager: BLTNItemManager = {
page.image = UIImage(named: "milestoneIcon")
page.appearance.titleFontSize = 18
page.appearance.titleTextColor = .gray
page.appearance.descriptionTextColor = .white
page.actionButtonTitle = "Pat on the back ✋"
page.actionHandler = { (item: BLTNActionItem) in
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.success)
self.bulletinManager.dismissBulletin()
}
let rootItem: BLTNItem = page
return BLTNItemManager(rootItem: rootItem)
}()
And here is how I presented it:
bulletinManager.backgroundViewStyle = .none
bulletinManager.backgroundColor = UIColor(red: 46/255, green: 58/255, blue: 67/255, alpha: 1.00)
bulletinManager.showBulletin(above: self)
I noticed that there is tap gesture recognized in the whole page, and that selector calls dismissIfPossible()
, which eventually calls dismissBulletin()
setting isPrepared = false
. Then the close button selector kicks in and calls dismissBulletin() again, failing the assertIsPrepared
condition
As your current implementation, for the closeButton
to show, you are requiring that
isDismissable = true && requiresCloseButton = true
, so for this implementation I will suggest to simply remove the target for the close button, as it will close either way as it is pressing inside the page. Removing the following line in BulletinViewController will fix it
closeButton.addTarget(self, action: #selector(closeButtonTapped), for: .touchUpInside)
A better feature would be to be able to have isDismissable = false
and only dismiss the page with the close button, there it would make sense to have the closeButton
target