Skip to content

ysfzrn/react-native-gif-player

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Native Gif View Component

React Native Gif/Animated WebP View Component.


These buttons are only for the "example app", not inside the library, react-native-gif-player is just a view component

React Native's Image component can display GIFs but lacks a stop feature. react-native-gif-player comes with a stop feature and additional capabilities.

react-native-gif-player is a wrapper around UIImage(iOS) and Fresco (Android).

Features

  • STOP
  • Local/Remote GIF Support.
  • Local/Remote Image Support.
  • Local/Remote Animated WebP Support (iOS has a performance issue with long animated WebP)..
  • Watching Frames
  • Jump to Frame
  • Loop Count (if you want infinite loop, you can assign 0 to loopCount prop)
  • Old/New Architecture Support

Usage

yarn add react-native-gif-player
cd ios && pod install
import { GifPlayerView } from 'react-native-gif-player';

const App = () => {
  const handleOnFrame = (event: any) => {
    const { frameNumber } = event?.nativeEvent || {};
  };

  const handleOnError = (event: any) => {
    setState({ loading: false, error: event?.nativeEvent?.error });
  };

  const handleLoad = (event: any) => {
    const { duration, frameCount } = event?.nativeEvent || {};
  };

  const jumpToFrame = () => {
    gifPlayerRef.current.jumpToFrame(0);
  }

  return (
    <GifPlayerView
      ref={gifPlayerRef}
      style={styles.box}
      source={{ uri: gifSource }}
      paused={paused}
      loopCount={loopCount}
      onStart={handleStart}
      onStop={handleStop}
      onEnd={handleEnd}
      onFrame={handleOnFrame}
      onError={handleOnError}
      onLoad={handleLoad}
    />

    ...
    <View style={styles.footerBottom}>
      <IconButton
        width={40}
        height={33}
        icon={ResetIcon}
        onPress={() => {
          if (gifPlayerRef.current !== null) {
            gifPlayerRef.current.jumpToFrame(0);
          }
        }}
      />
      <IconButton
        width={60}
        height={60}
        icon={paused ? PauseIcon : PlayIcon}
        onPress={() => {
          setState({ paused: !paused });
        }}
      />
      <IconButton
        width={40}
        height={37}
        icon={NextIcon}
        onPress={async () => {
          setState({ loading: true });
          await randomGif();
          setState({ paused: false });
        }}
      />
      <IconButton
        width={40}
        height={40}
        icon={LoopIcon}
        tintColor={loopCount === 0 ? '#388e3c' : 'white'}
        onPress={() => {
          setState({ loopCount: loopCount === 0 ? 1 : 0 });
        }}
      />
    </View>
    ...

  );
};

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library