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

Images don't load in Xamarin.Forms 4 when using Visual=Material #19

Closed
mikescandy opened this issue Dec 11, 2018 · 13 comments
Closed

Images don't load in Xamarin.Forms 4 when using Visual=Material #19

mikescandy opened this issue Dec 11, 2018 · 13 comments
Labels
bug Something isn't working

Comments

@mikescandy
Copy link

As described in xamarin/Xamarin.Forms#4674, when using XF4 and setting the ContentPage Visual to Material, images don't load.
The visual code uses ContextThemeWrapper to apply Material themes to controls, but in GlideExtensions.cs:

 if (imageView.Context is Activity activity)
else
return;

Without the else images are loaded correctly.

@jonathanpeppers jonathanpeppers added the bug Something isn't working label Dec 12, 2018
@mikescandy
Copy link
Author

I'm trying to produce a minimal case for this but I can't... (these bugs are killing me! 🤬🤬🤬)
I'll keep on trying....

@mikescandy
Copy link
Author

Got it! Please find a repro at https://github.com/mikescandy/glidex/tree/wrapbug . I forgot that to trigger the issue I had to:

  • upgrade to XF4
  • upgrade to Support Libraries v28.0.0-preview8
  • target Android 9.0
    BUT
    not for the binding project. I think there's a different Xamarin android bug there
    Anyway, this shows the issue (and it might be a good starting point if/when you plan to update to the latest libs)

@jonathanpeppers
Copy link
Owner

So I started a branch here to try all the new stuff: https://github.com/jonathanpeppers/glidex/compare/xf-4.0-pre

Main thing I saw was ImageCell broke the moment I upgraded to 4.x: #21

I'll look at what might be happening when glidex.csproj has a TargetFrameworkVersion=v8.1.

@mikescandy
Copy link
Author

mikescandy commented Dec 13, 2018

I think I saw an issue on xamarin.android that could be related to the binding project not compilinig, I'll see if I can link it here.
edit: dotnet/android#2465 (hey, look who created the issue 😅 )

@jonathanpeppers
Copy link
Owner

If the binding project had:

<PackageReference Include="Xamarin.Android.Support.v4" Version="28.0.0-preview9" />

Then you have to use TargetFrameworkVersion=v9.0, right?

@mikescandy
Copy link
Author

mikescandy commented Dec 13, 2018

no, I think support 28 can multitarget https://blog.xamarin.com/multi-targeting-with-android-support-library-v28/

@jonathanpeppers
Copy link
Owner

It is working for me, could it be that you have -preview8 in your example, and I have -preview9?

The other thing is I'm using a master build of Xamarin.Android + VS 2019: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android-builds-master/656/PublishUrls/

@mikescandy
Copy link
Author

I think the issue is fixed in master. I'll see if I can try that tomorrow too.

@jonathanpeppers
Copy link
Owner

The only thing I remember is this: dotnet/android#2424

I think you would get a build error on incremental builds, though.

@jonathanpeppers
Copy link
Owner

Oh sorry @mikescandy I didn't read!

I think I saw an issue on xamarin.android that could be related to the binding project not compilinig, > > I'll see if I can link it here.
edit: dotnet/android#2465 (hey, look who created the issue 😅 )

If that's the issue, yeah I fixed it in xamarin-android/master. Here is a workaround: 861719f

I think we can close this, unless you are seeing this in the Android device log:

} else {
Forms.Warn ("Context `{0}` is not an Android.App.Activity, aborting image load for `{1}`.", imageView.Context, source);
return;

@mikescandy
Copy link
Author

mikescandy commented Dec 14, 2018

I do see

12-14 15:01:10.569 W/glidex  ( 3824): Context `android.view.ContextThemeWrapper@f0bca8f` is not an Android.App.Activity, aborting image load for `Uri: https://growtix-melupufoagt.stackpathdns.com/media/big//34/28/23/5a9f03c2-3734-4486-bd04-2d45ac1c102e.png`.

@jonathanpeppers
Copy link
Owner

Ok I searched XF for ContextThemeWrapper, and looks like this would happen with <Image/> inside a <Frame/>:

<Frame>
    <Image WidthRequest="80" HeightRequest="80" Source="trump.png" />
</Frame>

MaterialFrameRenderer has a ContextThemeWrapper as its Context, and it would "pass it on" to its children.

@mikescandy
Copy link
Author

That's how I triggered it in https://github.com/mikescandy/glidex/tree/wrapbug

jonathanpeppers added a commit that referenced this issue Dec 14, 2018
Fixes: #19
Context: https://github.com/xamarin/Xamarin.Forms/blob/94e6621f72cf3b19585253427aae4b70ba66af55/Xamarin.Forms.Platform.Android/Material/MaterialFrameRenderer.cs#L41

The problem surfaces when:
- Using Xamarin.Forms 4.x preview
- Enable `Visual="Material"` on the current page
- Use an `<Image/>` inside a `<Frame/>`

Since a `ContextThemeWrapper` is the `Context` of the `ImageView`, it
was hitting this `else`:

    else {
        Forms.Warn ("Context `{0}` is not an Android.App.Activity, aborting image load for `{1}`.", imageView.Context, source);
    }

I reworked this code so it also checks in `Forms.Context` to find the
`Activity` instance.
jonathanpeppers added a commit that referenced this issue Dec 14, 2018
Fixes: #19
Context: https://github.com/xamarin/Xamarin.Forms/blob/94e6621f72cf3b19585253427aae4b70ba66af55/Xamarin.Forms.Platform.Android/Material/MaterialFrameRenderer.cs#L41

The problem surfaces when:
- Using Xamarin.Forms 4.x preview
- Enable `Visual="Material"` on the current page
- Use an `<Image/>` inside a `<Frame/>`

Since a `ContextThemeWrapper` is the `Context` of the `ImageView`, it
was hitting this `else`:

    else {
        Forms.Warn ("Context `{0}` is not an Android.App.Activity, aborting image load for `{1}`.", imageView.Context, source);
    }

I reworked this code so it also checks in `Forms.Context` to find the
`Activity` instance.
jonathanpeppers added a commit that referenced this issue Dec 14, 2018
Fixes: #19
Context: https://github.com/xamarin/Xamarin.Forms/blob/94e6621f72cf3b19585253427aae4b70ba66af55/Xamarin.Forms.Platform.Android/Material/MaterialFrameRenderer.cs#L41

The problem surfaces when:
- Using Xamarin.Forms 4.x preview
- Enable `Visual="Material"` on the current page
- Use an `<Image/>` inside a `<Frame/>`

Since a `ContextThemeWrapper` is the `Context` of the `ImageView`, it
was hitting this `else`:

    else {
        Forms.Warn ("Context `{0}` is not an Android.App.Activity, aborting image load for `{1}`.", imageView.Context, source);
    }

I reworked this code so it also checks in `Forms.Context` to find the
`Activity` instance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants