Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support paint on canvas using RenderLottie #195

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pacowong
Copy link

Motivation

I would like to render Lottie via Flame engine. After investigation, it requires the renderer to paint on Canvas directly. You can refer flame_svg as an example. Since _drawable in RenderLottie is private and Dart does not support internal variables, it cannot be accessed outside. Therefore, the necessary changes are made in the library.

Implementation Notes

Simply decouple paint on PaintintContext from paint on Canvas.

  @override
  void paint(PaintingContext context, Offset offset) {
    paintOnCanvas(context.canvas, offset);
  }

  void paintOnCanvas(Canvas canvas, Offset offset) {
    if (_drawable == null) return;

    _drawable!.draw(canvas, offset & size,
        fit: _fit, alignment: _alignment.resolve(TextDirection.ltr));
  }

@xvrh
Copy link
Owner

xvrh commented Feb 14, 2022

I'm ok to accept this if it enables new use-cases.

Also you might be interested to use directly the LottieDrawable class (which has a draw method).
Here is an example: https://github.com/xvrh/lottie-flutter/blob/master/example/lib/examples/custom_draw.dart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants