Giter Club home page Giter Club logo

react-native-animated-webp's Introduction

๐Ÿ’ƒ๐Ÿป react-native-animated-webp

example animated player
npm version weekly downloads npm bundle size
NPM

Display and control Animated WebP images in React Native the hacky way

๐Ÿ“ฆ Installation

๐Ÿ‘‹ PeerDependencies first

This module uses react-native-fast-image for rendering images, so you should install it first besides with react and react-native.

npm install react-native-fast-image
# Or using yarn
yarn add react-native-fast-image

๐Ÿ™Œ The package

npm install react-native-animated-webp
# Or using yarn
yarn add react-native-animated-webp

๐Ÿญ For Android

Add dependencies for fresco, which adds native support for Animated WebP at android/app/build.gradle.

Since FastImage is not working well for Animated WebP(maybe issue of Glide?), we internally use the native Image component for android platforms.

dependencies {
+  implementation 'com.facebook.fresco:fresco:2.0.0'
+  implementation 'com.facebook.fresco:animated-webp:+'
+  implementation 'com.facebook.fresco:webpsupport:+'

  implementation fileTree(dir: "libs", include: ["*.jar"])
  implementation "com.facebook.react:react-native:+"  // From node_modules

  if (enableHermes) {
      def hermesPath = "../../node_modules/hermes-engine/android/";
      debugImplementation files(hermesPath + "hermes-debug.aar")
      releaseImplementation files(hermesPath + "hermes-release.aar")
  } else {
      implementation jscFlavor
  }
}

๏ฃฟ For iOS

Add the following three lines inside your project's ios/{YourAppName}/AppDelegate.m file for Animated WebP support.

+ #import "SDImageCodersManager.h"
+ #import <SDWebImageWebPCoder/SDImageWebPCoder.h>

๏นฃ (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // . . .

+    [SDImageCodersManager.sharedManager addCoder:SDImageWebPCoder.sharedCoder];

    // . . .
}

๐Ÿฅ Usage

import React, { useRef } from 'react';
import { Button, View } from 'react-native';
import AnimatedPlayer, { IAnimatedPlayerReference } from 'react-native-animated-webp';

import thumbnailImage from '../assets/thumbnail.png';
import animatedWebPImage from '../assets/animated.webp';

const App: React.FC = () => {
  const playerRef = useRef<IAnimatedPlayerReference>();

  const onPressButton = () => {
    if(!playerRef.current?.isPlaying) {
      playerRef.current?.play(() => console.log('callback after play ended'));
    }
  };

  return (
    <View style={{ flex: 1 }}>
      <AnimatedPlayer
        ref={playerRef}
        thumbnailSource={thumbnailImage}
        animatedSource={animatedWebPImage}
        duration={500}
        autoplay={false}
        loop={false}
      />
      <Button
        title="Click Me"
        onPress={onPressButton}
      />
    </View>
  );
};

react-native-animated-webp's People

Contributors

dependabot[bot] avatar junhoyeo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  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.