Skip to content

thewoowon/motionx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

motionx

Unified Motion Engine for React & React Native

One component for all animation formats: Lottie, GIF, MP4, WebM

npm version License: MIT

🎯 Why motionx?

Stop juggling multiple animation libraries. motionx provides a single <Motion> component that works across all formats and platforms.

Before (Multiple Libraries) After (motionx)
lottie-react-native βœ… One Component
lottie-web βœ… One API
react-native-video βœ… React + RN
Custom GIF handlers βœ… Auto-detect format

πŸš€ Installation

npm install @thewoowon/motionx
# or
yarn add @thewoowon/motionx

πŸ“¦ Quick Start

import { Motion } from '@thewoowon/motionx';

function App() {
  return (
    <Motion
      source={require('./animation.json')}
      autoPlay
      loop
      width={200}
      height={200}
      onFinish={() => console.log('Done!')}
      fallback={<div>Loading...</div>}
    />
  );
}

That's it! motionx automatically detects the format and renders it correctly.


✨ Features

  • 🎨 Unified API - One component for all formats
  • πŸ”„ Auto-detection - Automatically detects Lottie, GIF, MP4, WebM
  • πŸ“± Cross-platform - Works on React Web & React Native
  • ⚑ Zero config - Just pass the source
  • 🎭 Fallback support - Show loading states easily
  • 🎬 Full control - loop, autoPlay, speed, callbacks
  • πŸ“¦ Tiny - Minimal dependencies

🎬 Supported Formats

Format Web React Native Notes
Lottie (JSON) βœ… βœ… Full support
GIF βœ… βœ… Native rendering
MP4 βœ… ⚠️ RN needs react-native-video
WebM βœ… ❌ Web only

πŸ“– API Reference

Props

interface MotionProps {
  // Source (required)
  source: string | object | number;

  // Playback
  loop?: boolean;           // Default: false
  autoPlay?: boolean;       // Default: true
  speed?: number;           // Default: 1.0

  // Size
  width?: number;
  height?: number;

  // UI
  fallback?: ReactNode;     // Loading/error state
  style?: CSSProperties | ViewStyle;
  className?: string;       // Web only

  // Callbacks
  onPlay?: () => void;
  onPause?: () => void;
  onFinish?: () => void;
  onError?: (error: Error) => void;

  // Testing
  testID?: string;
}

πŸ”₯ Examples

Lottie Animation

<Motion
  source={require('./logo.json')}
  autoPlay
  loop
  width={300}
  height={300}
/>

From URL

<Motion
  source="https://assets.lottiefiles.com/packages/lf20_example.json"
  autoPlay
  fallback={<Spinner />}
/>

GIF

<Motion
  source={require('./loading.gif')}
  width={100}
  height={100}
/>

Video (MP4)

<Motion
  source="https://example.com/video.mp4"
  autoPlay
  loop
  width={640}
  height={360}
  onError={(err) => console.error(err)}
/>

React Native

import { Motion } from '@thewoowon/motionx';
import { View } from 'react-native';

<View>
  <Motion
    source={require('./splash.json')}
    autoPlay
    loop
    width={200}
    height={200}
    style={{ marginTop: 20 }}
  />
</View>

🎯 How It Works

  1. Format Detection - Automatically detects format from file extension or content
  2. Platform Detection - Chooses Web or React Native renderer
  3. Optimized Rendering - Uses the best library for each format:
    • Lottie: lottie-web (Web) / lottie-react-native (RN)
    • GIF: <img> (Web) / <Image> (RN)
    • Video: <video> (Web) / react-native-video (RN)*

*Note: React Native video requires installing react-native-video separately


πŸ› οΈ Advanced Usage

Custom Styling

<Motion
  source={require('./hero.json')}
  autoPlay
  loop
  style={{
    borderRadius: 16,
    boxShadow: '0 4px 20px rgba(0,0,0,0.1)',
    background: '#f5f5f5',
  }}
/>

Controlled Playback

function ControlledAnimation() {
  const [playing, setPlaying] = useState(false);

  return (
    <>
      <Motion
        source={require('./click.json')}
        autoPlay={playing}
        loop={false}
        onFinish={() => setPlaying(false)}
      />
      <button onClick={() => setPlaying(true)}>
        Play
      </button>
    </>
  );
}

Error Handling

<Motion
  source={unknownSource}
  fallback={<div>Failed to load animation</div>}
  onError={(error) => {
    console.error('Animation error:', error);
    analytics.track('animation_error', { error });
  }}
/>

πŸ“± React Native Setup

For React Native projects, ensure you have the peer dependencies:

npm install lottie-react-native
# For video support (optional)
npm install react-native-video

Then link native modules:

cd ios && pod install

🎭 TypeScript Support

Full TypeScript support included:

import { Motion, MotionProps, MotionFormat } from '@thewoowon/motionx';

const props: MotionProps = {
  source: './animation.json',
  autoPlay: true,
  loop: true,
};

πŸ—ΊοΈ Roadmap

v0.1 (Current)

  • βœ… Lottie, GIF, MP4, WebM support
  • βœ… React & React Native
  • βœ… Auto format detection
  • βœ… Unified API

v0.2 (Coming Soon)

  • Rive support
  • SpriteSheet animations
  • Frame control (seek, progress)
  • Animation preloading

v0.3+

  • Skeleton animations
  • SVG animations
  • Canvas-based rendering
  • Performance optimizations

🀝 Contributing

Contributions welcome! Please read CONTRIBUTING.md first.


πŸ“„ License

MIT Β© eternalgridx


πŸ’‘ Philosophy

"μ• λ‹ˆλ©”μ΄μ…˜μ€ 파일 포맷이 μ•„λ‹ˆλΌ 'Motion' κ°œλ…μ΄λ‹€."

motionxλŠ” κ°œλ°œμžκ°€ κ΅¬ν˜„μ— μ§‘μ€‘ν•˜λ„λ‘, 포맷의 λ³΅μž‘ν•¨μ„ μˆ¨κΉλ‹ˆλ‹€.

λ””μžμ΄λ„ˆκ°€ 파일만 던져주면, κ°œλ°œμžλŠ” <Motion>만 μ“°λ©΄ λ©λ‹ˆλ‹€. 끝.

About

Unified Motion Engine for React & React Native

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published