         self.navigationBarHidden = !navigationBarHidden
     }
     
+    private func onBackPressed() {
+        if let backButtonAction = backButtonAction {
+            backButtonAction()
+        } else {
+            if navigationController != nil {
+                navigationController?.popViewControllerAnimated(true)
+            } else {
+                dismissViewControllerAnimated(true, completion: nil)
+            }
+        }
+    }
+    
     //MARK: - Observation
     
     private var galleryIndexObservationEnabled: Bool = false {

        let backNavigationItem = UINavigationItem()
        var backItem = self.backItem
        if backItem == nil {
            backItem = UIBarButtonItem(barButtonSystemItem: .Done, target: self, action: #selector(onBackPressed))
        }
        backNavigationItem.backBarButtonItem = backItem
        navigationBar.setItems([backNavigationItem, navigationItem], animated: false)

            navigationController.setNavigationBarHidden(true, animated: true)
        } else {
            navigationController.setNavigationBarHidden(originalNavigationBarHidden, animated: true)
        }
    }
    
