-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |