Skip to content

Instantly share code, notes, and snippets.

View Polenoso's full-sized avatar
🏠
Working from home

Aitor Pagán Polenoso

🏠
Working from home
View GitHub Profile
@Polenoso
Polenoso / PagedIndexViewModifier.swift
Created November 27, 2023 22:15
A View Modifier for a Paged Index View like, using ScrollToTargetBehavior
//
// PagedIndexViewModifier.swift
//
// Copyright© 2023 ApiumHub
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@Polenoso
Polenoso / LottieFileProvider.swift
Created May 19, 2021 09:35
Lottie Cache Medium Post
import Lottie // We need it because of the Animation Model
protocol LottieFileProviding: AnyObject {
func animation(forKey: String) -> Animation?
func setAnimationData(_ data: Data, forKey: String)
}
final class LottieFileProvider: LottieFileProviding {
static var shared = LottieFileProvider()
@Polenoso
Polenoso / AnimationPublic.swift
Created May 19, 2021 09:33
Lottie Cache Medium Post
//////////// AnimationPublic.swift
static func loadedFrom(url: URL,
closure: @escaping Animation.DownloadClosure,
animationCache: AnimationCacheProvider?) {
/// 1
if let animationCache = animationCache, let animation = animationCache.animation(forKey: url.absoluteString) {
closure(animation)
} else {
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
@Polenoso
Polenoso / AnimationView+Common.swift
Created May 19, 2021 09:30
Lottie CAche Medium post
extension AnimationView {
func setAnimation(from url: URL?,
cacheProvider: LottieFileProviding = LottieFileProvider.shared,
afterSetCompletion: @escaping (AnimationView) -> Void) {
guard let url = url else { return }
/// 1
if let animation = cacheProvider.animation(forKey: url.absoluteString) {
self.animation = animation
afterSetCompletion(self)
@Polenoso
Polenoso / AnimationContainerView.swift
Last active May 19, 2021 09:29
Lottie Cache Medium Post
import UIKit
import Lottie
final class AnimationContainerView: UIView {
// MARK: - Initializers
override init(frame: CGRect) {
super.init(frame: frame)
setupView()
setupConstraints()
}
@Polenoso
Polenoso / AnimationViewInitializers.swift
Last active May 10, 2021 14:24
Lottie Animation From URL
/**
Loads a Lottie animation asynchronously from the URL
- Parameter url: The url to load the animation from.
- Parameter imageProvider: An image provider for the animation's image data.
If none is supplied Lottie will search in the main bundle for images.
- Parameter closure: A closure to be called when the animation has loaded.
*/
convenience init(url: URL,
imageProvider: AnimationImageProvider? = nil,