Skip to content

Commit

Permalink
✨ Added support for Lottie
Browse files Browse the repository at this point in the history
  • Loading branch information
vegidio committed Mar 22, 2023
1 parent c314f75 commit 3bcb6c8
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/iOS-SAK-Package.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,34 @@
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Test"
BuildableName = "Test"
BlueprintName = "Test"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SAKTest"
BuildableName = "SAKTest"
BlueprintName = "SAKTest"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down Expand Up @@ -160,6 +188,16 @@
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SAKViewTest"
BuildableName = "SAKViewTest"
BlueprintName = "SAKViewTest"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
5 changes: 5 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ let package = Package(
],
path: "Source/View"
),
.testTarget(
name: "SAKViewTest",
dependencies: ["SAKView"],
path: "Tests/View"
),

// Test
.target(
Expand Down
48 changes: 48 additions & 0 deletions Source/View/Lottie.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// Lottie.swift
// iOS Swiss Army Knife
//
// Created by Vinicius Egidio on 2023-03-20.
//

import Foundation
import Lottie
import SwiftUI

public struct Lottie: UIViewRepresentable {
private let name: String
private let contentMode: UIView.ContentMode
private let loopMode: LottieLoopMode

public init(
name: String,
contentMode: UIView.ContentMode = .scaleAspectFit,
loopMode: LottieLoopMode = .loop
) {
self.name = name
self.contentMode = contentMode
self.loopMode = loopMode
}

public func makeUIView(context _: UIViewRepresentableContext<Lottie>) -> UIView {
let view = UIView(frame: .zero)
let animationView = LottieAnimationView()
let animation = LottieAnimation.asset(name)

animationView.animation = animation
animationView.contentMode = contentMode
animationView.loopMode = loopMode
animationView.play()
animationView.translatesAutoresizingMaskIntoConstraints = false

view.addSubview(animationView)
NSLayoutConstraint.activate([
animationView.heightAnchor.constraint(equalTo: view.heightAnchor),
animationView.widthAnchor.constraint(equalTo: view.widthAnchor)
])

return view
}

public func updateUIView(_: UIViewType, context _: Context) {}
}
16 changes: 16 additions & 0 deletions Tests/View/ViewTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// ViewTest.swift
// iOS Swiss Army Knife
//
// Created by Vinicius Egidio on 2023-03-20.
//

import Foundation
import SAKView
import XCTest

class ViewTest: XCTestCase {
func testPerformSnapshot() {
XCTAssertTrue(true)
}
}

0 comments on commit 3bcb6c8

Please sign in to comment.