Giter Club home page Giter Club logo

giffy's Introduction

Giffy

Giffy is a lightweight package that allows you to display animated GIF in SwiftUI views. Powered by the field-tested FLAnimatedImage, all your displayed animations will be very performant while being memory efficient.

Giffy can be used to display both GIF files stored locally and from remote URLs, providing a very familiar API that will feel right at home in a SwiftUI environment

Requirements

  • iOS 14.0 or later

Usage

Local Files

To display an animation from a local GIF file, use the Giffy component:

Giffy("cat")

Gravação de Tela 2023-05-01 às 12 36 15

If your GIF is stored on another bundle outside your project's main bundle, you can specify the Bundle to load the animation from.

// Loads an animation from the provided bundle
LottieView("cat", bundle: DesignSystem.Bundle.main)

Or if you want to use the path to your GIF file, you can simply pass it as well:

// Loads a GIF file from the provided path
LottieView(path: URL(string: "path/to/cat.gif")!)

Remote Files

If you want to display a GIF from the web, use the AsyncGiffy component. You can also setup a placeholder view to be displayed while the view is being loaded and a view to be displayed in place in case the GIF fails to load:

let url = URL(string: "https://media.giphy.com/media/RrVzUOXldFe8M/giphy.gif")!

AsyncGiffy(url: url) { phase in
    switch phase {
    case .loading:
        ProgressView()
    case .error:
        Text("Failed to load GIF")
    case .success(let giffy):
        giffy
    }
}

Gravação de Tela 2023-05-01 às 12 45 16

Features

Apart from displaying GIFs, you can also set an action to be executed each time an animation loops with the .onLoop(:) modifier:

@State let jumpCount = 0
VStack {
    AsyncGiffy(url: gifURL) { phase in
        switch phase {
        case .loading:
            ProgressView()
        case .error:
            Text("Failed to load GIF")
        case let .success(giffy):
            giffy
                .onLoop {
                    jumpCount += 2
                }
        }
    }
    Text("Jump count: \(jumpCount)")
}

Gravação de Tela 2023-05-01 às 12 51 21

Installation

Currently, Giffy can be installed through Swift Package Manager

To add this package to your project, go to File -> Swift Package Manager -> Add Package Dependency... in Xcode's menu and paste this Github page URL on the search bar

You can also add Giffy by adding it as a dependecy on your Package.swift file:

dependencies: [
    .package(url: "https://github.com/tfmart/Giffy.git", .upToNextMajor(from: "1.0.0"))
],
targets: [
    .target(name: "MyProject", dependencies: ["Giffy""])
]

giffy's People

Contributors

tfmart avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.