lucacivale / Maui.BottomSheet

Native BottomSheets in .Net Maui!
MIT License
36 stars 4 forks source link

Donet 9.0 android lottianimation not playing in bottomsheet #20

Open Th3L0x opened 1 week ago

Th3L0x commented 1 week ago

Lottianimation (using SkiaSharp SkLottiView) in a bottomsheet does not start playing.

Th3L0x commented 3 days ago

Has this happened to anyone else?

lucacivale commented 3 days ago

@Th3L0x Can you provide a small repro for me? Does this happen also with .net 8?

Th3L0x commented 3 days ago

Sure, currently I'm not at home so I couldnt check if its working or not, but you will get the idea. As I remember this happened on dotnet 8.0 as well. BottomSheetTest.zip

lucacivale commented 2 days ago

@Th3L0x thanks, but your sample isn't working. Could you provide me something working?

Th3L0x commented 2 days ago

Sorry, I think the deploying was not enabled in debug mode. I put a red background where the animation should be, it is also on the MainPage, and it works there.

BottomSheetTest.zip

lucacivale commented 1 day ago

@Th3L0x found the reason. SKLottieView.Window is null and therefore the animation does not start playing. I'm not sure if I want to release a new bug fix release since im working on a new major release. Is it possible that you set the Window until the new version is released? Either window.AddLogicalChild(lottieView) or set the window on the top view of your content.

Th3L0x commented 21 hours ago

Thank you, I'm not sure if this is what you meant for but this way its working:

 //BOTTOMSHEET BUG, will fixed in next release
 private ScrollView? _scrollView;
 private void ScrollView_BindingContextChanged(object sender, EventArgs e)
 {
     try
     {
         if (sender is ScrollView view && Shell.Current.CurrentPage?.Window != null)
         {
             _scrollView = view;
             var lottiPrompt = view.FindByName<SKLottieView>("lottiPrompt");
             var lottiLoad = view.FindByName<SKLottieView>("lottiLoad");
             if (lottiPrompt != null)
             {
                 Shell.Current.CurrentPage?.Window.AddLogicalChild(lottiPrompt);
                 lottiPrompt.BindingContext = this.BindingContext;
             }
             if (lottiLoad != null)
             {
                 Shell.Current.CurrentPage?.Window.AddLogicalChild(lottiLoad);
                 lottiLoad.BindingContext = this.BindingContext;
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex);
     }
 }

 private void BottomSheet_Closed(object sender, EventArgs e)
 {
     try
     {
         if (_scrollView != null && Shell.Current.CurrentPage?.Window != null)
         {
             var lottiPrompt = _scrollView.FindByName<SKLottieView>("lottiPrompt");
             var lottiLoad = _scrollView.FindByName<SKLottieView>("lottiLoad");
             if (lottiPrompt != null)
             {
                 Shell.Current.CurrentPage?.Window.RemoveLogicalChild(lottiPrompt);
             }
             if (lottiLoad != null)
             {
                 Shell.Current.CurrentPage?.Window.RemoveLogicalChild(lottiLoad);
             }
             _scrollView = null;
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex);
     }
 }
 //BOTTOMSHEET BUG, will fixed in next release