@@ -62,6 +62,7 @@ public final class AssSubtitlesView: PlatformView {
62
62
}
63
63
#endif
64
64
65
+ @MainActor
65
66
private func resizeCanvas( ) {
66
67
resizeImageAtLayout ( )
67
68
renderer. setCanvasSize ( bounds. size, scale: canvasScale)
@@ -75,6 +76,7 @@ public extension AssSubtitlesView {
75
76
/// - callback: Callback to call.
76
77
///
77
78
/// Calling this multiple times will override previous callbacks.
79
+ @MainActor
78
80
@discardableResult
79
81
func onImageChanged( _ callback: AssSubtitlesImageCallback ? ) -> Self {
80
82
imageCallback = callback
@@ -83,11 +85,13 @@ public extension AssSubtitlesView {
83
85
}
84
86
85
87
private extension AssSubtitlesView {
88
+ @MainActor
86
89
func configure( ) {
87
90
setupView ( )
88
91
subscribeToEvents ( )
89
92
}
90
93
94
+ @MainActor
91
95
func setupView( ) {
92
96
addSubview ( imageView)
93
97
#if canImport(UIKit)
@@ -99,6 +103,7 @@ private extension AssSubtitlesView {
99
103
#endif
100
104
}
101
105
106
+ @MainActor
102
107
func subscribeToEvents( ) {
103
108
renderer
104
109
. framesPublisher ( )
@@ -107,51 +112,46 @@ private extension AssSubtitlesView {
107
112
. store ( in: & cancellables)
108
113
}
109
114
115
+ @MainActor
110
116
func handleFrameChanged( _ image: ProcessedImage ? ) {
111
- UI { [ weak self] in
112
- guard let self else { return }
113
- if let image {
114
- resizeImageView ( for: image)
115
- #if canImport(UIKit)
116
- imageView. image = PlatformImage ( cgImage: image. image)
117
- #elseif canImport(AppKit)
118
- imageView. image = PlatformImage ( cgImage: image. image, size: image. imageRect. size)
119
- #endif
120
- imageView. isHidden = false
121
- } else {
122
- imageView. isHidden = true
123
- imageView. image = nil
124
- }
125
- if let imageCallback {
126
- let dialogues = renderer. dialogues ( at: renderer. currentOffset)
127
- imageCallback ( self , imageView, image, dialogues)
128
- }
117
+ if let image {
118
+ resizeImageView ( for: image)
119
+ #if canImport(UIKit)
120
+ imageView. image = PlatformImage ( cgImage: image. image)
121
+ #elseif canImport(AppKit)
122
+ imageView. image = PlatformImage ( cgImage: image. image, size: image. imageRect. size)
123
+ #endif
124
+ imageView. isHidden = false
125
+ } else {
126
+ imageView. isHidden = true
127
+ imageView. image = nil
128
+ }
129
+ if let imageCallback {
130
+ let dialogues = renderer. dialogues ( at: renderer. currentOffset)
131
+ imageCallback ( self , imageView, image, dialogues)
129
132
}
130
133
}
131
134
135
+ @MainActor
132
136
func resizeImageView( for image: ProcessedImage ) {
133
- UI { [ weak self] in
134
- guard let self else { return }
135
- lastRenderBounds = bounds
136
- imageView. frame = imageFrame ( for: image. imageRect)
137
- }
137
+ lastRenderBounds = bounds
138
+ imageView. frame = imageFrame ( for: image. imageRect)
138
139
}
139
140
141
+ @MainActor
140
142
func resizeImageAtLayout( ) {
141
- UI { [ weak self] in
142
- guard let self else { return }
143
- if lastRenderBounds. isEmpty || bounds. isEmpty || imageView. image == nil { return }
144
- let ratioX = 1 / ( lastRenderBounds. width / bounds. width)
145
- let ratioY = 1 / ( lastRenderBounds. height / bounds. height)
146
- let newOrigin = CGPoint ( x: imageView. frame. origin. x * ratioX, y: imageView. frame. origin. y * ratioY)
147
- let newSize = CGSize ( width: imageView. frame. width * ratioX, height: imageView. frame. height * ratioY)
148
- let newFrame = CGRect ( origin: newOrigin, size: newSize) . integral
149
- CATransaction . begin ( )
150
- imageView. frame = newFrame
151
- CATransaction . commit ( )
152
- }
143
+ if lastRenderBounds. isEmpty || bounds. isEmpty || imageView. image == nil { return }
144
+ let ratioX = 1 / ( lastRenderBounds. width / bounds. width)
145
+ let ratioY = 1 / ( lastRenderBounds. height / bounds. height)
146
+ let newOrigin = CGPoint ( x: imageView. frame. origin. x * ratioX, y: imageView. frame. origin. y * ratioY)
147
+ let newSize = CGSize ( width: imageView. frame. width * ratioX, height: imageView. frame. height * ratioY)
148
+ let newFrame = CGRect ( origin: newOrigin, size: newSize) . integral
149
+ CATransaction . begin ( )
150
+ imageView. frame = newFrame
151
+ CATransaction . commit ( )
153
152
}
154
153
154
+ @MainActor
155
155
func imageFrame( for rect: CGRect ) -> CGRect {
156
156
#if canImport(UIKit)
157
157
rect
0 commit comments