Skip to content

[Android] Image can disappear when going back to the page. #14471

Closed

Description

@ziomek64

Description

First things first please rename the title of this issue to the more correct one as I didn't know how to title it.

I'm experiencing a problem, might be xaml or shell related. The images dissapear when moving between tabs. If I have Image with its source set on the page on the moment the app is building and debugging it will stay there when changing tabs but when Image is loaded on runtime like when I pull data from API (being binded), (Or add image url in xaml and hot reload) it will dissapear when changing tabs.

When I switched .net run time for all platforms from .net 7 to .net 6 it seems to fix it so the issue might be related to that somehow? That's the only discovery I've made so far. Also this issue doesn't seem to persist on other platforms at least it doesn't on Windows. I don't have any apple devices.

Video shows that when adding an image before hand works fine when switching tabs. But there is a bug when adding an image in runtime. This doesn't happen on .net 6.

2023-03-24_09-20-38.mp4

Steps to Reproduce

  1. Make fresh project
  2. Try to add picture on runtime and switch tabs.

Link to public reproduction project repository

https://github.com/ziomek64/TabBarPhotoTest

Version with bug

7.0 (current)

Last version that worked well

6.0.424

Affected platforms

Android

Affected platform versions

Android

Did you find any workaround?

Use maui on .net 6

Relevant log output

No response

Activity

  1. added
    t/bug
    on Apr 8, 2023
  2. ghost added
    legacy-area-controls
    on Apr 10, 2023
  3. added
    area-controls-shell
    and removed
    legacy-area-controls
    on Apr 10, 2023
  4. added this to the Backlog milestone on Apr 10, 2023
  5. janseris commented on Apr 10, 2023

    @janseris

    Isn't this XAML Hot Reload issue?

  6. ziomek64 commented on Apr 10, 2023

    @ziomek64
    Author

    Isn't this XAML Hot Reload issue?

    I don't think so, because this happens when I have image source binded. When I pull data it works fine, but If I go from this page and come back the image is not there. But when a new image with new source is loaded it again works until I leave the page

  7. changed the title [-][Android] Image can dissapear when going back to the page.[/-] [+][Android] Image can disappear when going back to the page.[/+] on Apr 10, 2023
  8. kirakosyan commented on Apr 12, 2023

    @kirakosyan

    DevEx claims that the bug in their control is related to this. Information in the discussion can be useful
    https://supportcenter.devexpress.com/ticket/details/t1155623/dxcollectionview-does-not-show-images-in-its-items-when-its-parent-tab-is-switched

  9. mtmgoliath commented on May 4, 2023

    @mtmgoliath

    I have managed to find a work-around.

    I seems that when setting the URL to just a string property in the VM and binding the Image Source to it then the image disappears.

    Instead set/bind to a property inside an object in the VM.

       //Create separate model
      public class Banner
      {
          public string Image { get; set; }
          public string Text { get; set; }
      }
      
      //In the VM create property for object
      public Banner HeadlineBanner { get; set; }
      
      
      //Then in the VM set properties on page appearing event
      [RelayCommand]
      public async void PageAppearing()
      {
          try
          {
              await Task.Run(async () =>
              {
                  //Get details from api service
                  var headlineBanner = new HeadlineBanner();
                  headlineBanner.Image = _apiService.ImageUrl;
                  headlineBanner.Text = _apiService.Text;
                
                  //Set the object
                  HeadlineBanner = headlineBanner;
              });
    
          }
          catch (Exception ex)
          {
              Crashes.TrackError(ex);
          }
      }
    

    Then in the view bind to object's properties

    <Image Source="{Binding HeadlineBanner.Image}" />
    <Label Text="{Binding HeadlineBanner.Text}" />
    

    I also found that I was having trouble if binding to a ContentView, instead of directly writing out the layout in the View.

    Hopefully this helps get your app out the door!

  10. ziomek64 commented on May 4, 2023

    @ziomek64
    Author

    I have managed to find a work-around.

    I seems that when setting the URL to just a string property in the VM and binding the Image Source to it then the image disappears.

    Instead set/bind to a property inside an object in the VM.

       //Create separate model
      public class Banner
      {
          public string Image { get; set; }
          public string Text { get; set; }
      }
      
      //In the VM create property for object
      public Banner HeadlineBanner { get; set; }
      
      
      //Then in the VM set properties on page appearing event
      [RelayCommand]
      public async void PageAppearing()
      {
          try
          {
              await Task.Run(async () =>
              {
                  //Get details from api service
                  var headlineBanner = new HeadlineBanner();
                  headlineBanner.Image = _apiService.ImageUrl;
                  headlineBanner.Text = _apiService.Text;
                
                  //Set the object
                  HeadlineBanner = headlineBanner;
              });
    
          }
          catch (Exception ex)
          {
              Crashes.TrackError(ex);
          }
      }
    

    Then in the view bind to object's properties

    <Image Source="{Binding HeadlineBanner.Image}" />
    <Label Text="{Binding HeadlineBanner.Text}" />
    

    I also found that I was having trouble if binding to a ContentView, instead of directly writing out the layout in the View.

    Hopefully this helps get your app out the door!

    I honestly would prefer to stay at .net 6 and wait for the fix as I have too much to change. But somebody will use it for sure. I don't need it as I didn't use any new features from 7

  11. ziomek64 commented on May 4, 2023

    @ziomek64
    Author

    I have managed to find a work-around.

    I seems that when setting the URL to just a string property in the VM and binding the Image Source to it then the image disappears.

    Instead set/bind to a property inside an object in the VM.

       //Create separate model
      public class Banner
      {
          public string Image { get; set; }
          public string Text { get; set; }
      }
      
      //In the VM create property for object
      public Banner HeadlineBanner { get; set; }
      
      
      //Then in the VM set properties on page appearing event
      [RelayCommand]
      public async void PageAppearing()
      {
          try
          {
              await Task.Run(async () =>
              {
                  //Get details from api service
                  var headlineBanner = new HeadlineBanner();
                  headlineBanner.Image = _apiService.ImageUrl;
                  headlineBanner.Text = _apiService.Text;
                
                  //Set the object
                  HeadlineBanner = headlineBanner;
              });
    
          }
          catch (Exception ex)
          {
              Crashes.TrackError(ex);
          }
      }
    

    Then in the view bind to object's properties

    <Image Source="{Binding HeadlineBanner.Image}" />
    <Label Text="{Binding HeadlineBanner.Text}" />
    

    I also found that I was having trouble if binding to a ContentView, instead of directly writing out the layout in the View.

    Hopefully this helps get your app out the door!

    I honestly don't know how do they expect people to update to newer version when bugs like that make it impossible to use maui

  12. 90 remaining items

  13. added a commit that references this issue on Jul 21, 2024
  14. added a commit that references this issue on Jul 21, 2024
  15. ziomek64 commented on Jul 29, 2024

    @ziomek64
    Author

    This will make it in .net 8?

  16. moved this from Todo to In Progress in MAUI SDK Ongoingon Jul 30, 2024
  17. moved this from In Progress to Done in MAUI SDK Ongoingon Aug 6, 2024
  18. ziomek64 commented on Aug 6, 2024

    @ziomek64
    Author
  19. ziomek64 commented on Aug 9, 2024

    @ziomek64
    Author
  20. devMotcho commented on Sep 10, 2024

    @devMotcho

    After many hours i found a Solution for this by using Caching the others didnt work on my case:

    1. Adding FFImageLoading.Maui to your project;
    2. Initializing it on builder at MauiProgram.cs:
    builder
        .UseMauiApp<App>()
        .UseFFImageLoading()
    
    1. Adding the namespace to the Page where we want to render the image
      xmlns:ff="clr-namespace:FFImageLoading.Maui;assembly=FFImageLoading.Maui"

    2. Now we can use ff:CachedImage instead of Image

    <ff:CachedImage
        Source="your_image.png"
        CacheDuration="1"
        RetryCount="3"
        RetryDelay="600"
        DownsampleToViewSize="True" />
    

    CacheDuration="1": Cache the image for 1 day.
    RetryCount="3" and RetryDelay="600": Retry loading 3 times with a 600ms delay if it fails.
    DownsampleToViewSize="True": Resize the image to fit the view, saving memory.

    Enjoy. Stay positive!

  21. ziomek64 commented on Sep 10, 2024

    @ziomek64
    Author

    After many hours i found a Solution for this by using Caching the others didnt work on my case:

    1. Adding FFImageLoading.Maui to your project;
    2. Initializing it on builder at MauiProgram.cs:
    builder
        .UseMauiApp<App>()
        .UseFFImageLoading()
    
    1. Adding the namespace to the Page where we want to render the image
      xmlns:ff="clr-namespace:FFImageLoading.Maui;assembly=FFImageLoading.Maui"

    2. Now we can use ff:CachedImage instead of Image

    <ff:CachedImage
        Source="your_image.png"
        CacheDuration="1"
        RetryCount="3"
        RetryDelay="600"
        DownsampleToViewSize="True" />
    

    CacheDuration="1": Cache the image for 1 day.
    RetryCount="3" and RetryDelay="600": Retry loading 3 times with a 600ms delay if it fails.
    DownsampleToViewSize="True": Resize the image to fit the view, saving memory.

    Enjoy. Stay positive!

    This is fixed though in newest Maui XDDD

  22. devMotcho commented on Sep 10, 2024

    @devMotcho

    Well i had a problem in my app where in a Page i have 2 ObservableCollections Category and Product and a DishOfTheDay Dish all the images from the Observables had no bug but the DishOfTheDay image when changing tabs and coming back wasnt rendered anymore it would be render only if refresh the page (calling api again)

  23. ziomek64 commented on Sep 10, 2024

    @ziomek64
    Author

    Well i had a problem in my app where in a Page i have 2 ObservableCollections Category and Product and a DishOfTheDay Dish all the images from the Observables had no bug but the DishOfTheDay image when changing tabs and coming back wasnt rendered anymore it would be render only if refresh the page (calling api again)

    Use newest Maui. No need to install packages

  24. locked and limited conversation to collaborators on Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-imagearea-controls-shellfixed-in-8.0.80fixed-in-9.0.0-rc.1.24453.9has-workaroundmigration-compatibilityp/1partner/cat 😻platform/androidpotential-regressions/triageds/verifiedt/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions