@@ -62,6 +62,8 @@ final public class GalleryViewController : UIPageViewController, UIViewControlle
62
62
public var landedPageAtIndexCompletion : ( ( Int ) -> Void ) ?
63
63
/// If set, launched after all animations finish when the close button is pressed.
64
64
public var closedCompletion : ( ( ) -> Void ) ?
65
+ /// If set, launched after all animations finish when the close() method is invoked via public API.
66
+ public var programaticallyClosedCompletion : ( ( ) -> Void ) ?
65
67
/// If set, launched after all animations finish when the swipe-to-dismiss (applies to all directions and cases) gesture is used.
66
68
public var swipedToDismissCompletion : ( ( ) -> Void ) ?
67
69
@@ -190,7 +192,7 @@ final public class GalleryViewController : UIPageViewController, UIViewControlle
190
192
191
193
private func configureCloseButton( ) {
192
194
193
- closeButton? . addTarget ( self , action: #selector( GalleryViewController . close ) , forControlEvents: . TouchUpInside)
195
+ closeButton? . addTarget ( self , action: #selector( GalleryViewController . interactiveClose ) , forControlEvents: . TouchUpInside)
194
196
}
195
197
196
198
func createViewHierarchy( ) {
@@ -337,7 +339,17 @@ final public class GalleryViewController : UIPageViewController, UIViewControlle
337
339
338
340
// MARK: - Actions
339
341
340
- func close( ) {
342
+ public func close( ) {
343
+
344
+ closeWithAnimation ( programaticallyClosedCompletion)
345
+ }
346
+
347
+ func interactiveClose( ) {
348
+
349
+ closeWithAnimation ( closedCompletion)
350
+ }
351
+
352
+ func closeWithAnimation( completion: ( ( ) -> Void ) ? ) {
341
353
342
354
UIView . animateWithDuration ( 0.1 , animations: { [ weak self] in
343
355
@@ -355,26 +367,24 @@ final public class GalleryViewController : UIPageViewController, UIViewControlle
355
367
356
368
imageController. closeAnimation ( self ? . closeAnimationDuration ?? 0.2 , completion: { [ weak self] finished in
357
369
358
- self ? . innerClose ( )
370
+ self ? . postAnimationClose ( completion )
359
371
} )
360
372
}
361
373
}
362
374
else {
363
- self ? . innerClose ( )
375
+ self ? . postAnimationClose ( completion )
364
376
}
365
-
366
377
}
367
378
}
368
379
369
- func innerClose ( ) {
380
+ func postAnimationClose ( completion : ( ( ) -> Void ) ? ) {
370
381
371
382
self . modalTransitionStyle = . CrossDissolve
372
- self . dismissViewControllerAnimated ( true ) {
383
+ self . dismissViewControllerAnimated ( false ) {
373
384
374
385
self . applicationWindow!. windowLevel = UIWindowLevelNormal
386
+ completion ? ( )
375
387
}
376
-
377
- closedCompletion ? ( )
378
388
}
379
389
380
390
// MARK: - Image Controller Delegate
0 commit comments