@@ -4,6 +4,7 @@ extension UIImageView {
44
55 // Data holder tap recognizer
66 private class TapWithDataRecognizer : UITapGestureRecognizer {
7+ var from : UIViewController ?
78 var imageDatasource : ImageDataSource ?
89 var initialIndex : Int = 0
910 var options : [ ImageViewerOption ] = [ ]
@@ -16,15 +17,17 @@ extension UIImageView {
1617 }
1718
1819 public func setupImageViewer(
19- options: [ ImageViewerOption ] = [ ] ) {
20- setup ( datasource: nil , options: options)
20+ options: [ ImageViewerOption ] = [ ] ,
21+ from: UIViewController ? = nil ) {
22+ setup ( datasource: nil , options: options, from: from)
2123 }
2224
2325 public func setupImageViewer(
2426 url: URL ,
2527 initialIndex: Int = 0 ,
2628 placeholder: UIImage ? = nil ,
27- options: [ ImageViewerOption ] = [ ] ) {
29+ options: [ ImageViewerOption ] = [ ] ,
30+ from: UIViewController ? = nil ) {
2831
2932 let datasource = SimpleImageDatasource (
3033 imageItems: [ url ] . compactMap {
@@ -33,13 +36,15 @@ extension UIImageView {
3336 setup (
3437 datasource: datasource,
3538 initialIndex: initialIndex,
36- options: options)
39+ options: options,
40+ from: from)
3741 }
3842
3943 public func setupImageViewer(
4044 images: [ UIImage ] ,
4145 initialIndex: Int = 0 ,
42- options: [ ImageViewerOption ] = [ ] ) {
46+ options: [ ImageViewerOption ] = [ ] ,
47+ from: UIViewController ? = nil ) {
4348
4449 let datasource = SimpleImageDatasource (
4550 imageItems: images. compactMap {
@@ -48,14 +53,16 @@ extension UIImageView {
4853 setup (
4954 datasource: datasource,
5055 initialIndex: initialIndex,
51- options: options)
56+ options: options,
57+ from: from)
5258 }
5359
5460 public func setupImageViewer(
5561 urls: [ URL ] ,
5662 initialIndex: Int = 0 ,
5763 options: [ ImageViewerOption ] = [ ] ,
58- placeholder: UIImage ? = nil ) {
64+ placeholder: UIImage ? = nil ,
65+ from: UIViewController ? = nil ) {
5966
6067 let datasource = SimpleImageDatasource (
6168 imageItems: urls. compactMap {
@@ -64,24 +71,28 @@ extension UIImageView {
6471 setup (
6572 datasource: datasource,
6673 initialIndex: initialIndex,
67- options: options)
74+ options: options,
75+ from: from)
6876 }
6977
7078 public func setupImageViewer(
7179 datasource: ImageDataSource ,
7280 initialIndex: Int = 0 ,
73- options: [ ImageViewerOption ] = [ ] ) {
81+ options: [ ImageViewerOption ] = [ ] ,
82+ from: UIViewController ? = nil ) {
7483
7584 setup (
7685 datasource: datasource,
7786 initialIndex: initialIndex,
78- options: options)
87+ options: options,
88+ from: from)
7989 }
8090
8191 private func setup(
8292 datasource: ImageDataSource ? ,
8393 initialIndex: Int = 0 ,
84- options: [ ImageViewerOption ] = [ ] ) {
94+ options: [ ImageViewerOption ] = [ ] ,
95+ from: UIViewController ? = nil ) {
8596
8697 var _tapRecognizer : TapWithDataRecognizer ?
8798 gestureRecognizers? . forEach {
@@ -105,6 +116,7 @@ extension UIImageView {
105116 _tapRecognizer!. imageDatasource = datasource
106117 _tapRecognizer!. initialIndex = initialIndex
107118 _tapRecognizer!. options = options
119+ _tapRecognizer!. from = from
108120 addGestureRecognizer ( _tapRecognizer!)
109121 }
110122
@@ -117,7 +129,7 @@ extension UIImageView {
117129 imageDataSource: sender. imageDatasource,
118130 options: sender. options,
119131 initialIndex: sender. initialIndex)
120-
121- vc ? . present ( imageCarousel, animated: false , completion: nil )
132+ let presentFromVC = sender . from ?? vc
133+ presentFromVC ? . present ( imageCarousel, animated: false , completion: nil )
122134 }
123135}
0 commit comments