Skip to content

Commit

Permalink
[Feat/#104] DSKit에서 Lottie 사용을 위한 스텐실파일 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoe0929 committed Nov 26, 2024
1 parent 0224bb0 commit b33adb0
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions HMH_Tuist_iOS/Tuist/ResourceSynthesizers/Lottie.stencil
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// swiftformat:disable all
// swiftlint:disable all
{% if files %}
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
{% set documentPrefix %}{{param.documentName|default:"Document"}}{% endset %}
import Foundation
#if canImport(Lottie)
import Lottie
// MARK: - Animations Assets
{{accessModifier}} extension AnimationAsset {
{% for file in files %}
static let {{file.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = Self(named: "{{file.name}}")
{% endfor %}
}
// MARK: - Animation Helpers
{{accessModifier}} extension AnimationAsset {
/// All the available animation. Can be used to preload them
static let allAnimations: [Self] = [
{% for file in files %}
Self.{{file.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}},
{% endfor %}
]
}
// MARK: - Structures
{{accessModifier}} struct AnimationAsset: Hashable {
{{accessModifier}} fileprivate(set) var name: String
{{accessModifier}} let animation: LottieAnimation?
{{accessModifier}} init(named name: String) {
self.name = name
if let url = Bundle.module.url(forResource: name, withExtension: "json") {
self.animation = LottieAnimation.filepath(url.path)
} else {
self.animation = nil
}
}
// MARK: Hashable Conformance
{{accessModifier}} static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.name == rhs.name
}
{{accessModifier}} func hash(into hasher: inout Hasher) {
hasher.combine(self.name)
}
}
// MARK: - Preload Helpers
{{accessModifier}} extension AnimationAsset {
/// Preloads all the Lottie Animations to avoid performance issues when loading them
static func preload() -> Void {
for animationAsset in Self.allAnimations {
_ = animationAsset.animation
}
}
}
// swiftformat:enable all
// swiftlint:enable all
#endif
{% else %}
// No files found
{% endif %}

0 comments on commit b33adb0

Please sign in to comment.