{"action":"created","issue":{"url":"https://api.github.com/repos/scihant/CTShowcase/issues/9","repository_url":"https://api.github.com/repos/scihant/CTShowcase","labels_url":"https://api.github.com/repos/scihant/CTShowcase/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/scihant/CTShowcase/issues/9/comments","events_url":"https://api.github.com/repos/scihant/CTShowcase/issues/9/events","html_url":"https://github.com/scihant/CTShowcase/issues/9","id":243184733,"number":9,"title":"dismissHandler() getting called twice.","user":{"login":"SirVeryBritish","id":10279069,"avatar_url":"https://avatars4.githubusercontent.com/u/10279069?v=4","gravatar_id":"","url":"https://api.github.com/users/SirVeryBritish","html_url":"https://github.com/SirVeryBritish","followers_url":"https://api.github.com/users/SirVeryBritish/followers","following_url":"https://api.github.com/users/SirVeryBritish/following{/other_user}","gists_url":"https://api.github.com/users/SirVeryBritish/gists{/gist_id}","starred_url":"https://api.github.com/users/SirVeryBritish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SirVeryBritish/subscriptions","organizations_url":"https://api.github.com/users/SirVeryBritish/orgs","repos_url":"https://api.github.com/users/SirVeryBritish/repos","events_url":"https://api.github.com/users/SirVeryBritish/events{/privacy}","received_events_url":"https://api.github.com/users/SirVeryBritish/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-07-15T16:21:22Z","updated_at":"2017-07-15T17:44:54Z","closed_at":null,"body":"First of all, thank you so much for this project. It saved myself a lot of time! During integration into my current project I found some weird behaviour, which I would label a bug. \r\n\r\nIn my projects I have two UINavigationController, the first one being \"the base of operation\", the second one comes from the top like a curtain with some UIViewController on it's stack. On the second one I'm using your CTShowcaseViews as a chain, for a tutorial like:\r\n\r\n````swift\r\nlet showcase = CTShowcaseView(title: \"title\", message: \"message\",\r\nkey: nil) { () -> () in\r\n//chained CTShowcaseViews\r\n}\r\n````\r\n\r\nEverything goes as expected UNTIL the end, where I call for a closing transition which moves the second UINavigationController together with its UIViewControllers from the screen, moving direction upwards. Some CTShowcaseViews handlers invoked again and since I used them as a chain, you can imagine what a mess it was to have the animation on the UIViewControllers from the first UINavigationController, actually I was impressed that it did not crash.\r\n\r\nAfter debugging I have the theory, since I use a transition, which calls dismiss on the top UIViewController from the second UINavigationController, that this invokes the dismiss() again in the CTShowcaseView. Since the dismissHandler didn't get cleared earlier, it's calling it again.\r\n\r\nI propose this change, to prevent the dismissHandler from being called twice in such situations:\r\n\r\n````swift\r\n\r\n@objc open class CTShowcaseView: UIView {\r\n//...\r\n    open func dismiss() {\r\n        UIView.animate(withDuration: CTGlobalConstants.DefaultAnimationDuration, animations: { () -> Void in\r\n            self.alpha = 0\r\n        }, completion: { (finished) -> Void in\r\n            self.removeFromSuperview()\r\n            self.dismissHandler?()\r\n            self.dismissHandler = nil //clears the dismissHandler, after being invoked once.\r\n        })\r\n    }\r\n//...\r\n}\r\n````\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/scihant/CTShowcase/issues/comments/315550406","html_url":"https://github.com/scihant/CTShowcase/issues/9#issuecomment-315550406","issue_url":"https://api.github.com/repos/scihant/CTShowcase/issues/9","id":315550406,"user":{"login":"scihant","id":3991481,"avatar_url":"https://avatars7.githubusercontent.com/u/3991481?v=4","gravatar_id":"","url":"https://api.github.com/users/scihant","html_url":"https://github.com/scihant","followers_url":"https://api.github.com/users/scihant/followers","following_url":"https://api.github.com/users/scihant/following{/other_user}","gists_url":"https://api.github.com/users/scihant/gists{/gist_id}","starred_url":"https://api.github.com/users/scihant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scihant/subscriptions","organizations_url":"https://api.github.com/users/scihant/orgs","repos_url":"https://api.github.com/users/scihant/repos","events_url":"https://api.github.com/users/scihant/events{/privacy}","received_events_url":"https://api.github.com/users/scihant/received_events","type":"User","site_admin":false},"created_at":"2017-07-15T17:44:54Z","updated_at":"2017-07-15T17:44:54Z","body":"Thanks for the feedback and the pull request. \r\nThere are only two cases that might cause the dismiss handler to get called:\r\n\r\n- The user taps on the showcase\r\n- The user creates a showcase with a visible region that's less than %75 of the total area of the showcase. \r\n\r\nThis means that dismissing a ViewController stack with or without any animation shouldn't cause the dismiss handler to be called. But you're saying that it gets called, which makes me wonder the exact scenario that causes this behavior.  Would it be possible for you to send me a bare-bones project that  demonstrates this problem? Your pull request would certainly solve it, but I think it would be better if I could take a detailed look and find out the root cause of the problem because it might be causing other problems as well. \r\n\r\nRight now it seems that it shouldn't have happened in the first place. If I don't find a root cause that requires a more complicated fix, I'll merge your pull request since it won't break anything anyway.\r\n\r\nThanks."}}
{"actor":{"display_login":"scihant"}}