跳到主要内容
知仓学习社ZHICANG

lottie-animations

Lottie animation skill for integrating After Effects animations into iOS, Android, and cross-platform mobile apps with playback control, performance…

不碰外部(只输出文字)无严重或高危命中a5c-ai/babysitter

它会碰到什么

扫了多少2 个文本文件,21 KB
它会碰到什么不碰外部(只输出文字)
命中总数0 处
命中统计严重 0 · 高 0 · 中 0 · 低 0

这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。

技能内容

Lottie Animations Skill

Comprehensive Lottie animation integration for mobile platforms, enabling high-quality vector animations from After Effects in iOS, Android, React Native, and Flutter applications.

Overview

This skill provides capabilities for integrating Lottie animations into mobile applications, including animation playback control, performance optimization, interactive animations, and proper asset management across platforms.

Capabilities

Animation Integration

  • Import and validate Lottie JSON files
  • Configure lottie-ios for native iOS apps
  • Set up lottie-android for native Android apps
  • Integrate lottie-react-native for React Native
  • Configure lottie for Flutter apps

Playback Control

  • Implement play, pause, stop controls
  • Configure animation speed and direction
  • Set up loop modes (none, loop, autoReverse)
  • Implement progress-based playback
  • Handle animation completion callbacks

Interactive Animations

  • Implement gesture-driven animations
  • Configure animation markers/segments
  • Sync animations with scroll position
  • Implement drag-based animation control
  • Handle touch interaction with animation

Performance Optimization

  • Optimize animation file size
  • Configure rendering modes (software/hardware)
  • Implement animation caching
  • Handle memory management
  • Preload animations for smooth playback

Asset Management

  • Organize animation assets
  • Configure dynamic text replacement
  • Handle color theming
  • Manage animation versioning
  • Implement asset preloading

Prerequisites

iOS Development

# Podfile
pod 'lottie-ios'

# Or Swift Package Manager
# https://github.com/airbnb/lottie-ios.git

Android Development

// build.gradle
dependencies {
    implementation 'com.airbnb.android:lottie:6.3.0'
}

React Native

npm install lottie-react-native
# or
yarn add lottie-react-native

# iOS pods
cd ios && pod install

Flutter

# pubspec.yaml
dependencies:
  lottie: ^3.0.0

Usage Patterns

iOS (SwiftUI)

import SwiftUI
import Lottie

struct LottieView: UIViewRepresentable {
    let animationName: String
    let loopMode: LottieLoopMode
    let animationSpeed: CGFloat
    @Binding var isPlaying: Bool

    func makeUIView(context: Context) -> LottieAnimationView {
        let animationView = LottieAnimationView(name: animationName)
        animationView.contentMode = .scaleAspectFit
        animationView.loopMode = loopMode
        animationView.animationSpeed = animationSpeed
        return animationView
    }

    func updateUIView(_ animationView: LottieAnimationView, context: Context) {
        if isPlaying {
            animationView.play()
        } else {
            animationView.pause()
        }
    }
}

// Usage
struct ContentView: View {
    @State private var isPlaying = true

    var body: some View {
        VStack {
            LottieView(
                animationName: "loading",
                loopMode: .loop,
                animationSpeed: 1.0,
                isPlaying: $isPlaying
            )
            .frame(width: 200, height: 200)

            Button(isPlaying ? "Pause" : "Play") {
                isPlaying.toggle()
            }
        }
    }
}

iOS (UIKit)

import Lottie

class AnimationViewController: UIViewController {
    private var animationView: LottieAnimationView!

    override func viewDidLoad() {
        super.viewDidLoad()
        setupAnimation()
    }

    private func setupAnimation() {
        animationView = LottieAnimationView(name: "success")
        animationView.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
        animationView.center = view.center
        animationView.contentMode = .scaleAspectFit
        animationView.loopMode = .playOnce
        view.addSubview(animationView)
    }

    func playAnimation() {
        animationView.play { completed in
            if completed {
                print("Animation completed")
            }
        }
    }

    func playSegment(from: CGFloat, to: CGFloat) {
        animationView.play(fromProgress: from, toProgress: to, loopMode: .playOnce)
    }

    func setProgress(_ progress: CGFloat) {
        animationView.currentProgress = progress
    }
}

Android (Kotlin - Jetpack Compose)

import com.airbnb.lottie.compose.*

@Composable
fun LottieAnimationScreen() {
    val composition by rememberLottieComposition(
        LottieCompositionSpec.RawRes(R.raw.loading)
    )
    val progress by animateLottieCompositionAsState(
        composition = composition,
        iterations = LottieConstants.IterateForever
    )

    LottieAnimation(
        composition = composition,
        progress = { progress },
        modifier = Modifier.size(200.dp)
    )
}

// Controllable animation
@Composable
fun ControllableLottieAnimation() {
    val composition by rememberLottieComposition(
        LottieCompositionSpec.RawRes(R.raw.success)
    )
    var isPlaying by remember { mutableStateOf(false) }
    val progress by animateLottieCompositionAsState(
        composition = composition,
        isPlaying = isPlaying,
        restartOnPlay = true
    )

    Column(horizontalAlignment = Alignment.CenterHorizontally) {
        LottieAnimation(
            composition = composition,
            progress = { progress },
            modifier = Modifier.size(200.dp)
        )

        Button(onClick = { isPlaying = true }) {
            Text("Play")
        }
    }
}

// Progress-based animation
@Composable
fun ScrollSyncedAnimation(scrollProgress: Float) {
    val composition by rememberLottieComposition(
        LottieCompositionSpec.RawRes(R.raw.scroll_animation)
    )

    LottieAnimation(
        composition = composition,
        progress = { scrollProgress },
        modifier = Modifier.fillMaxWidth()
    )
}

Android (XML Views)

import com.airbnb.lottie.LottieAnimationView
import com.airbnb.lottie.LottieDrawable

class AnimationActivity : AppCompatActivity() {
    private lateinit var animationView: LottieAnimationView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_animation)

        animationView = findViewById(R.id.animation_view)
        setupAnimation()
    }

    private fun setupAnimation() {
        animationView.apply {
            setAnimation(R.raw.loading)
            repeatCount = LottieDrawable.INFINITE
            speed = 1.0f
        }
    }

    fun playAnimation() {
        animationView.playAnimation()
    }

    fun pauseAnimation() {
        animationView.pauseAnimation()
    }

    fun setProgress(progress: Float) {
        animationView.progress = progress
    }

    fun playSegment(startFrame: Int, endFrame: Int) {
        animationView.setMinAndMaxFrame(startFrame, endFrame)
        animationView.playAnimation()
    }
}

React Native

import React, { useRef, useState } from 'react';
import { View, Button, StyleSheet } from 'react-native';
import LottieView from 'lottie-react-native';

const AnimationScreen = () => {
  const animationRef = useRef(null);
  const [isPlaying, setIsPlaying] = useState(false);

  const playAnimation = () => {
    animationRef.current?.play();
    setIsPlaying(true);
  };

  const pauseAnimation = () => {
    animationRef.current?.pause();
    setIsPlaying(false);
  };

  const resetAnimation = () => {
    animationRef.current?.reset();
    setIsPlaying(false);
  };

  return (
    <View style={styles.container}>
      <LottieView
        ref={animationRef}
        source={require('./animations/success.json')}
        style={styles.animation}
        autoPlay={false}
        loop={false}
        onAnimationFinish={() => setIsPlaying(false)}
      />

      <View style={styles.controls}>
        <Button
          title={isPlaying ? 'Pause' : 'Play'}
          onPress={isPlaying ? pauseAnimation : playAnimation}
        />
        <Button title="Reset" onPress={resetAnimation} />
      </View>
    </View>
  );
};

// Progress-controlled animation
const ScrollAnimation = ({ scrollProgress }) => {
  return (
    <LottieView
      source={require('./animations/scroll-animation.json')}
      progress={scrollProgress}
      style={styles.animation}
    />
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  animation: {
    width: 200,
    height: 200,
  },
  controls: {
    flexDirection: 'row',
    marginTop: 20,
  },
});

export default AnimationScreen;

Flutter

import 'package:flutter/material.dart';
import 'package:lottie/lottie.dart';

class AnimationScreen extends StatefulWidget {
  @override
  _AnimationScreenState createState() => _AnimationScreenState();
}

class _AnimationScreenState extends State<AnimationScreen>
    with SingleTickerProviderStateMixin {
  late final AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Lottie.asset(
              'assets/animations/success.json',
              controller: _controller,
              width: 200,
              height: 200,
              onLoaded: (composition) {
                _controller.duration = composition.duration;
              },
            ),
            SizedBox(height: 20),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                ElevatedButton(
                  onPressed: () => _controller.forward(),
                  child: Text('Play'),
                ),
                SizedBox(width: 10),
                ElevatedButton(
                  onPressed: () => _controller.stop(),
                  child: Text('Stop'),
                ),
                SizedBox(width: 10),
                ElevatedButton(
                  onPressed: () => _controller.reset(),
                  child: Text('Reset'),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

// Looping animation
class LoadingAnimation extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Lottie.asset(
      'assets/animations/loading.json',
      width: 100,
      height: 100,
      repeat: true,
    );
  }
}

// Network animation
class NetworkAnimation extends StatelessWidget {
  final String url;

  const NetworkAnimation({required this.url});

  @override
  Widget build(BuildContext context) {
    return Lottie.network(
      url,
      width: 200,
      height: 200,
      frameRate: FrameRate.max,
    );
  }
}

Integration with Babysitter SDK

Task Definition Example

const lottieIntegrationTask = defineTask({
  name: 'lottie-animation-setup',
  description: 'Integrate Lottie animations into mobile app',

  inputs: {
    platform: { type: 'string', required: true, enum: ['ios', 'android', 'react-native', 'flutter'] },
    projectPath: { type: 'string', required: true },
    animationFiles: { type: 'array', items: { type: 'string' } },
    features: {
      type: 'array',
      items: { type: 'string', enum: ['playback_control', 'progress_sync', 'gestures', 'theming'] }
    }
  },

  outputs: {
    integratedAnimations: { type: 'array' },
    componentCode: { type: 'string' },
    optimizationReport: { type: 'object' }
  },

  async run(inputs, taskCtx) {
    return {
      kind: 'skill',
      title: `Integrate Lottie for ${inputs.platform}`,
      skill: {
        name: 'lottie-animations',
        context: {
          operation: 'integrate',
          platform: inputs.platform,
          projectPath: inputs.projectPath,
          animations: inputs.animationFiles,
          features: inputs.features
        }
      },
      io: {
        inputJsonPath: `tasks/${taskCtx.effectId}/input.json`,
        outputJsonPath: `tasks/${taskCtx.effectId}/result.json`
      }
    };
  }
});

Animation Optimization

File Size Optimization

# Use LottieFiles optimizer
npx @nicolo-ribaudo/lottie-optimize animation.json -o optimized.json

# Or use online tools:
# https://lottiefiles.com/tools/lottie-optimizer

Performance Tips

  1. Reduce complexity: Simplify paths and shapes in After Effects
  2. Limit layers: Fewer layers = better performance
  3. Avoid masks: Use shape layers instead when possible
  4. Cache compositions: Reuse loaded animations
  5. Use hardware acceleration: Enable when available
  6. Preload animations: Load before display needed

Memory Management

// iOS - Clear cache when needed
LottieAnimationView.clearCache()

// Load from cache
let animation = LottieAnimation.named("loading", animationCache: LRUAnimationCache.sharedCache)
// Android - Configure cache
val cacheComposition = LottieCompositionFactory
    .fromRawRes(context, R.raw.animation)
    .addListener { composition ->
        // Animation loaded
    }

Best Practices

  1. Optimize Before Integration: Use LottieFiles optimizer
  2. Lazy Load: Load animations only when needed
  3. Cache Animations: Reuse loaded compositions
  4. Handle Errors: Gracefully handle loading failures
  5. Test Performance: Profile on low-end devices
  6. Accessibility: Provide alternatives for motion-sensitive users

References

想直接用这个技能?

本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。

它属于哪个仓库

星标★ 1,796
本站分层T1
该仓技能数2115
原文件路径library/specializations/mobile-development/skills/lottie-animations/SKILL.md

同一个仓库里的其他技能

看这个仓库的全部 2115 个技能