Skip to content

Commit 34b91ce

Browse files
caldaiago849
authored andcommitted
Support using SwiftUI LottieView with strict concurrency enabled (airbnb#2126)
1 parent 2d54bd8 commit 34b91ce

37 files changed

+85
-31
lines changed

Example/Example.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@
359359
MARKETING_VERSION = 1.0;
360360
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
361361
MTL_FAST_MATH = YES;
362+
OTHER_SWIFT_FLAGS = "-warnings-as-errors -enable-upcoming-feature StrictConcurrency -warn-concurrency -enable-actor-data-race-checks";
362363
PRODUCT_BUNDLE_IDENTIFIER = com.airbnb.Example;
363364
PRODUCT_NAME = "$(TARGET_NAME)";
364365
SDKROOT = auto;
@@ -407,6 +408,7 @@
407408
MACOSX_DEPLOYMENT_TARGET = 13.0;
408409
MARKETING_VERSION = 1.0;
409410
MTL_FAST_MATH = YES;
411+
OTHER_SWIFT_FLAGS = "-warnings-as-errors -enable-upcoming-feature StrictConcurrency -warn-concurrency -enable-actor-data-race-checks";
410412
PRODUCT_BUNDLE_IDENTIFIER = com.airbnb.Example;
411413
PRODUCT_NAME = "$(TARGET_NAME)";
412414
SDKROOT = auto;
@@ -443,6 +445,7 @@
443445
);
444446
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
445447
MTL_FAST_MATH = YES;
448+
OTHER_SWIFT_FLAGS = "-enable-upcoming-feature StrictConcurrency -warn-concurrency";
446449
PRODUCT_BUNDLE_IDENTIFIER = com.airbnb.lottie.example.iOS;
447450
PRODUCT_NAME = "$(TARGET_NAME)";
448451
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
@@ -472,6 +475,7 @@
472475
"@executable_path/Frameworks",
473476
);
474477
MTL_FAST_MATH = YES;
478+
OTHER_SWIFT_FLAGS = "-enable-upcoming-feature StrictConcurrency -warn-concurrency";
475479
PRODUCT_BUNDLE_IDENTIFIER = com.airbnb.lottie.example.iOS;
476480
PRODUCT_NAME = "$(TARGET_NAME)";
477481
SWIFT_VERSION = 5.0;

Example/Example/RemoteAnimationDemoView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import SwiftUI
66

77
// MARK: - AnimationListView
88

9+
@MainActor
910
struct RemoteAnimationsDemoView: View {
1011

1112
struct Item: Hashable {

Lottie.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3229,6 +3229,7 @@
32293229
MARKETING_VERSION = 1.0;
32303230
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
32313231
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
3232+
OTHER_SWIFT_FLAGS = "-warnings-as-errors";
32323233
PRODUCT_BUNDLE_IDENTIFIER = com.airbnb.Lottie;
32333234
PRODUCT_NAME = Lottie;
32343235
SKIP_INSTALL = YES;
@@ -3262,6 +3263,7 @@
32623263
MARKETING_VERSION = 1.0;
32633264
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
32643265
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
3266+
OTHER_SWIFT_FLAGS = "-warnings-as-errors";
32653267
PRODUCT_BUNDLE_IDENTIFIER = com.airbnb.Lottie;
32663268
PRODUCT_NAME = Lottie;
32673269
SKIP_INSTALL = YES;
@@ -3334,6 +3336,7 @@
33343336
MARKETING_VERSION = 1.0;
33353337
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
33363338
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
3339+
OTHER_SWIFT_FLAGS = "-warnings-as-errors";
33373340
PRODUCT_BUNDLE_IDENTIFIER = com.airbnb.Lottie;
33383341
PRODUCT_NAME = Lottie;
33393342
SDKROOT = macosx;
@@ -3368,6 +3371,7 @@
33683371
MARKETING_VERSION = 1.0;
33693372
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
33703373
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
3374+
OTHER_SWIFT_FLAGS = "-warnings-as-errors";
33713375
PRODUCT_BUNDLE_IDENTIFIER = com.airbnb.Lottie;
33723376
PRODUCT_NAME = Lottie;
33733377
SDKROOT = macosx;
@@ -3400,6 +3404,7 @@
34003404
MARKETING_VERSION = 1.0;
34013405
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
34023406
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
3407+
OTHER_SWIFT_FLAGS = "-warnings-as-errors";
34033408
PRODUCT_BUNDLE_IDENTIFIER = com.airbnb.Lottie;
34043409
PRODUCT_NAME = Lottie;
34053410
SDKROOT = appletvos;
@@ -3434,6 +3439,7 @@
34343439
MARKETING_VERSION = 1.0;
34353440
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
34363441
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
3442+
OTHER_SWIFT_FLAGS = "-warnings-as-errors";
34373443
PRODUCT_BUNDLE_IDENTIFIER = com.airbnb.Lottie;
34383444
PRODUCT_NAME = Lottie;
34393445
SDKROOT = appletvos;

Rakefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ namespace :build do
99

1010
desc 'Builds the Lottie package for iOS'
1111
task :iOS do
12-
xcodebuild('build -scheme "Lottie (iOS)" -destination generic/platform=iOS -workspace Lottie.xcworkspace')
12+
xcodebuild('build -scheme "Lottie (iOS)" -destination generic/platform=iOS -workspace Lottie.xcworkspace OTHER_SWIFT_FLAGS="-warnings-as-errors"')
1313
end
1414

1515
desc 'Builds the Lottie package for macOS'
1616
task :macOS do
17-
xcodebuild('build -scheme "Lottie (macOS)" -destination generic/platform=macOS -workspace Lottie.xcworkspace')
17+
xcodebuild('build -scheme "Lottie (macOS)" -destination generic/platform=macOS -workspace Lottie.xcworkspace OTHER_SWIFT_FLAGS="-warnings-as-errors"')
1818
end
1919

2020
desc 'Builds the Lottie package for tvOS'
2121
task :tvOS do
22-
xcodebuild('build -scheme "Lottie (tvOS)" -destination generic/platform=tvOS -workspace Lottie.xcworkspace')
22+
xcodebuild('build -scheme "Lottie (tvOS)" -destination generic/platform=tvOS -workspace Lottie.xcworkspace OTHER_SWIFT_FLAGS="-warnings-as-errors"')
2323
end
2424
end
2525

Sources/Private/Model/Assets/Asset.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import Foundation
99

10+
// MARK: - Asset
11+
1012
public class Asset: Codable, DictionaryInitializable {
1113

1214
// MARK: Lifecycle
@@ -41,3 +43,9 @@ public class Asset: Codable, DictionaryInitializable {
4143
case id
4244
}
4345
}
46+
47+
// MARK: Sendable
48+
49+
/// Since `Asset` isn't `final`, we have to use `@unchecked Sendable` instead of `Sendable.`
50+
/// All `Asset` subclasses are immutable `Sendable` values.
51+
extension Asset: @unchecked Sendable { }

Sources/Private/Model/Assets/AssetLibrary.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99

10-
final class AssetLibrary: Codable, AnyInitializable {
10+
final class AssetLibrary: Codable, AnyInitializable, Sendable {
1111

1212
// MARK: Lifecycle
1313

Sources/Private/Model/Keyframes/KeyframeGroup.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ extension KeyframeGroup: Hashable where T: Hashable {
203203
}
204204
}
205205

206+
// MARK: Sendable
207+
208+
extension KeyframeGroup: Sendable where T: Sendable { }
209+
206210
extension Keyframe {
207211
/// Creates a copy of this `Keyframe` with the same timing data, but a different value
208212
func withValue<Value>(_ newValue: Value) -> Keyframe<Value> {

Sources/Private/Model/Layers/LayerModel.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,9 @@ extension Array where Element == LayerModel {
226226
}
227227
}
228228
}
229+
230+
// MARK: - LayerModel + Sendable
231+
232+
/// Since `LayerModel` isn't `final`, we have to use `@unchecked Sendable` instead of `Sendable.`
233+
/// All `LayerModel` subclasses are immutable `Sendable` values.
234+
extension LayerModel: @unchecked Sendable { }

Sources/Private/Model/Objects/Marker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99

1010
/// A time marker
11-
final class Marker: Codable, DictionaryInitializable {
11+
final class Marker: Codable, Sendable, DictionaryInitializable {
1212

1313
// MARK: Lifecycle
1414

Sources/Private/Model/ShapeItems/GradientFill.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99

1010
// MARK: - GradientType
1111

12-
enum GradientType: Int, Codable {
12+
enum GradientType: Int, Codable, Sendable {
1313
case none
1414
case linear
1515
case radial

0 commit comments

Comments
 (0)