GithubHelp home page GithubHelp logo

nwestfall / calligraphy.xamarin Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 3.0 159 KB

Use custom fonts in Android! Port of https://github.com/InflationX/Calligraphy

License: Apache License 2.0

C# 100.00%
android calligraphy font typeface xamarin xamarin-android xamarin-android-library

calligraphy.xamarin's Issues

CalligraphyFactory.OnViewCreatedInternal throws an InvalidCastException on Android 10

After updating to the latest Nuget release with Android 10 support, one of the workflows in our app was experiencing a crash with the following stacktrace:

ERROR : System.InvalidCastException: Specified cast is not valid.
at Calligraphy.Xamarin.CalligraphyFactory.OnViewCreatedInternal (Android.Views.View view, Android.Content.Context context, Android.Util.IAttributeSet attrs) [0x000db] in <636ad58454d34da899ec75f85f329bd1>:0
at Calligraphy.Xamarin.CalligraphyFactory.OnViewCreated (Android.Views.View view, Android.Content.Context context, Android.Util.IAttributeSet attrs) [0x00026] in <636ad58454d34da899ec75f85f329bd1>:0
at Calligraphy.Xamarin.CalligraphyLayoutInflater.OnCreateView (System.String name, Android.Util.IAttributeSet attrs) [0x0004d] in <636ad58454d34da899ec75f85f329bd1>:0
at Android.Views.LayoutInflater.n_OnCreateView_Ljava_lang_String_Landroid_util_AttributeSet_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_name, System.IntPtr native_attrs) [0x00017] in <7d2292394f8c488b97f5bc2a0ac0240d>:0 
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.35(intptr,intptr,intptr,intptr)

I did some digging and found the culprit:

if (CalligraphyUtils.CanCheckForV7Toolbar() && view?.GetType()?.IsAssignableFrom(typeof(Android.Support.V7.Widget.Toolbar)) == true)
ApplyFontToToolbar((Android.Support.V7.Widget.Toolbar)view);

In my case, we had some custom views of type Android.Views.View which it was trying to cast into a Android.Support.V7.Widget.Toolbar.

Because IsAssignableFrom() returns true when the current type is in the same hierarchy as the given type, a custom view of type Android.Views.View will pass the type check since Android.Support.V7.Widget.Toolbar inherits from Android.Views.View. I wasn't sure if there was a reason why the type check is being performed with IsAssignableFrom() specifically, since everywhere else in the function it just uses the is operator.

Because of this, I've made two PRs which both fix this issue but in different ways:
#11
#12

#11 changes the type checking implementation to just use the is operator and check it against the Toolbar type explicitly.
#12 is a more conservative fix which will just catch the exception if it's thrown, and then skip that view. This does not change the type checking implementation and still utilizes IsAssignableFrom() if that is to be preserved.

Whichever PR is more suitable is up to you and you're free to close the other ๐Ÿ™‚

After upgrade of Visual Studio Community to 16.6.0

Hi, i was using your package and had no problems till this updagre.
AFter this upgrade started to have some diferences bettwen the old version, before upgrade, and the new version, after upgrade.
Can u please help me?

Problem with many devices

hi; thank for your job
but still not work in for example samsung note3 android 5.0 and nokia and many huawi devices

Custom fonts not taking affect after switching to Calligraphy.Xamarin

Hi,

I switched to using your project after I had to upgrade my project to API Level 29. I was previously using Callygraphy.Xamarin, which I believe is deprecated and doesn't support Android 10.

My project builds but I don't see my fonts coming up. I even added the config code to OnCreate() per your instructions. Is this a drop-in replacement or do I have to make more code changes? All of my fonts are under my projects "Asset/fonts" folder.

Thanks,
Jeff

Add logging

Still having an issue with an app that won't change the font. Works with binding, but not this port. Will be adding logging to see how it runs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.