@@ -4,6 +4,7 @@ extension UIImageView {
4
4
5
5
// Data holder tap recognizer
6
6
private class TapWithDataRecognizer : UITapGestureRecognizer {
7
+ var from : UIViewController ?
7
8
var imageDatasource : ImageDataSource ?
8
9
var initialIndex : Int = 0
9
10
var options : [ ImageViewerOption ] = [ ]
@@ -16,15 +17,17 @@ extension UIImageView {
16
17
}
17
18
18
19
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)
21
23
}
22
24
23
25
public func setupImageViewer(
24
26
url: URL ,
25
27
initialIndex: Int = 0 ,
26
28
placeholder: UIImage ? = nil ,
27
- options: [ ImageViewerOption ] = [ ] ) {
29
+ options: [ ImageViewerOption ] = [ ] ,
30
+ from: UIViewController ? = nil ) {
28
31
29
32
let datasource = SimpleImageDatasource (
30
33
imageItems: [ url ] . compactMap {
@@ -33,13 +36,15 @@ extension UIImageView {
33
36
setup (
34
37
datasource: datasource,
35
38
initialIndex: initialIndex,
36
- options: options)
39
+ options: options,
40
+ from: from)
37
41
}
38
42
39
43
public func setupImageViewer(
40
44
images: [ UIImage ] ,
41
45
initialIndex: Int = 0 ,
42
- options: [ ImageViewerOption ] = [ ] ) {
46
+ options: [ ImageViewerOption ] = [ ] ,
47
+ from: UIViewController ? = nil ) {
43
48
44
49
let datasource = SimpleImageDatasource (
45
50
imageItems: images. compactMap {
@@ -48,14 +53,16 @@ extension UIImageView {
48
53
setup (
49
54
datasource: datasource,
50
55
initialIndex: initialIndex,
51
- options: options)
56
+ options: options,
57
+ from: from)
52
58
}
53
59
54
60
public func setupImageViewer(
55
61
urls: [ URL ] ,
56
62
initialIndex: Int = 0 ,
57
63
options: [ ImageViewerOption ] = [ ] ,
58
- placeholder: UIImage ? = nil ) {
64
+ placeholder: UIImage ? = nil ,
65
+ from: UIViewController ? = nil ) {
59
66
60
67
let datasource = SimpleImageDatasource (
61
68
imageItems: urls. compactMap {
@@ -64,24 +71,28 @@ extension UIImageView {
64
71
setup (
65
72
datasource: datasource,
66
73
initialIndex: initialIndex,
67
- options: options)
74
+ options: options,
75
+ from: from)
68
76
}
69
77
70
78
public func setupImageViewer(
71
79
datasource: ImageDataSource ,
72
80
initialIndex: Int = 0 ,
73
- options: [ ImageViewerOption ] = [ ] ) {
81
+ options: [ ImageViewerOption ] = [ ] ,
82
+ from: UIViewController ? = nil ) {
74
83
75
84
setup (
76
85
datasource: datasource,
77
86
initialIndex: initialIndex,
78
- options: options)
87
+ options: options,
88
+ from: from)
79
89
}
80
90
81
91
private func setup(
82
92
datasource: ImageDataSource ? ,
83
93
initialIndex: Int = 0 ,
84
- options: [ ImageViewerOption ] = [ ] ) {
94
+ options: [ ImageViewerOption ] = [ ] ,
95
+ from: UIViewController ? = nil ) {
85
96
86
97
var _tapRecognizer : TapWithDataRecognizer ?
87
98
gestureRecognizers? . forEach {
@@ -105,6 +116,7 @@ extension UIImageView {
105
116
_tapRecognizer!. imageDatasource = datasource
106
117
_tapRecognizer!. initialIndex = initialIndex
107
118
_tapRecognizer!. options = options
119
+ _tapRecognizer!. from = from
108
120
addGestureRecognizer ( _tapRecognizer!)
109
121
}
110
122
@@ -117,7 +129,7 @@ extension UIImageView {
117
129
imageDataSource: sender. imageDatasource,
118
130
options: sender. options,
119
131
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 )
122
134
}
123
135
}
0 commit comments