xamarin-range-slider icon indicating copy to clipboard operation
xamarin-range-slider copied to clipboard

Doesn't work on iOS with forms

Open hktari opened this issue 7 years ago • 22 comments

slider not visible on iOS and after suggested code is added:

#if NETFX_CORE [assembly: Xamarin.Forms.Platform.WinRT.ExportRenderer(, typeof(Xamarin.RangeSlider.Forms.RangeSliderRenderer))] #else [assembly: Xamarin.Forms.ExportRenderer(typeof(Xamarin.RangeSlider.Forms.RangeSlider), typeof(Xamarin.RangeSlider.Forms.RangeSliderRenderer))] #endif

NullReferenceException thrown

project: Test.zip

hktari avatar Jan 10 '18 10:01 hktari

Thanks @hktari Apparently, range slider ios package is not compatible with new iOS projects. I will try to fix it asap.

halkar avatar Jan 23 '18 09:01 halkar

Hello @halkar! Did you find a solution? I'm still digging around source to fix this and use the range slider on my new iOS project :)

jeedee avatar Mar 18 '18 19:03 jeedee

I got this exception:

Loaded assembly: /.........../Xamarin.RangeSlider.Common.dll [External] Unhandled Exception:

System.NullReferenceException: Object reference not set to an instance of an object

But from source code, Xamarin.RangeSlider.Common.dll doesn't contain anything, just an enum type.

I compiled the source code with samples, and it works....

the latest nuget version, is the same of the actual source code??

Magic73 avatar Mar 29 '18 09:03 Magic73

I just noticed that on iOS sample, inside the main.cs you put:

public class Application
{
    // This is the main entry point of the application.
    static void Main(string[] args)
    {
        // if you want to use a different Application Delegate class from "AppDelegate"
        // you can specify it here.
        UIApplication.Main(args, null, "AppDelegate");

        var t = typeof(RangeSliderRenderer); // <---- This line!!!!
    }
}

Magic73 avatar Mar 29 '18 09:03 Magic73

Ok, I found a strange issue: I have to add Xamarin.RangeSlider nuget package too. I added only Xamarin.Forms.RangeSlider. (but this is enough for Droid and UWP)

Now, I got the same exception, but with more detials:

Unhandled Exception:

System.NullReferenceException: Object reference not set to an instance of an object

[0:] Eccezione non gestita: MonoTouch - System.NullReferenceException: Object reference not set to an instance of an object at Xamarin.RangeSlider.RangeSliderControl.get_LowerHandleImageNormal () [0x00096] in <394d04d792de4791b21e337580082f54>:0 at Xamarin.RangeSlider.RangeSliderControl.get_IntrinsicContentSize () [0x0000a] in <394d04d792de4791b21e337580082f54>:0 at Xamarin.RangeSlider.RangeSliderControl.AddSubviews () [0x00010] in <394d04d792de4791b21e337580082f54>:0 at Xamarin.RangeSlider.RangeSliderControl.ConfigureView () [0x000de] in <394d04d792de4791b21e337580082f54>:0 at Xamarin.RangeSlider.RangeSliderControl..ctor (CoreGraphics.CGRect frame) [0x0001d] in <394d04d792de4791b21e337580082f54>:0 at Xamarin.RangeSlider.Forms.RangeSliderRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs1[TElement] e) [0x0001e] in <521f210d41874847a6d12b7429bff1d6>:0 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x00118] in :0 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <bc5a3d4303744676b3b36f4254bb697d>:0 at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00014] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:193 at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0002a] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:77 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:45 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x000cc] in :0 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <bc5a3d4303744676b3b36f4254bb697d>:0 at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00014] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:193 at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0002a] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:77 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:45 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x000cc] in :0 at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in :0 at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00014] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:193 at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0002a] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:77 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:45 at Xamarin.Forms.Platform.iOS.PageRenderer.ViewDidLoad () [0x00086] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:123 at (wrapper managed-to-native) ObjCRuntime.Messaging:IntPtr_objc_msgSendSuper (intptr,intptr) at UIKit.UIViewController.get_View () [0x00030] in /Users/builder/data/lanes/5665/db807ec9/source/xamarin-macios/src/build/ios/native/UIKit/UIViewController.g.cs:2983 at Xamarin.Forms.Platform.iOS.PageRenderer.get_NativeView () [0x00000] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:41 at Xamarin.Forms.Platform.iOS.PageRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x0004f] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:56 at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00014] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:193 at Xamarin.Forms.Platform.iOS.Platform.AddChild (Xamarin.Forms.VisualElement view) [0x00027] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:327 at Xamarin.Forms.Platform.iOS.Platform.WillAppear () [0x0003c] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:313 at Xamarin.Forms.Platform.iOS.PlatformRenderer.ViewWillAppear (System.Boolean animated) [0x00010] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\PlatformRenderer.cs:167 at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr) at UIKit.UIWindow.MakeKeyAndVisible () [0x00008] in /Users/builder/data/lanes/5665/db807ec9/source/xamarin-macios/src/build/ios/native/UIKit/UIWindow.g.cs:259 at Xamarin.Forms.Platform.iOS.FormsApplicationDelegate.SetMainPage () [0x00006] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\FormsApplicationDelegate.cs:159 at Xamarin.Forms.Platform.iOS.FormsApplicationDelegate.FinishedLaunching (UIKit.UIApplication uiApplication, Foundation.NSDictionary launchOptions) [0x00028] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\FormsApplicationDelegate.cs:45 at ScalextricArcPro.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x0001f] in : : :

Magic73 avatar Mar 29 '18 10:03 Magic73

So the issue is inside this:

    public override CGSize IntrinsicContentSize => new CGSize(NoIntrinsicMetric,
        Math.Max(LowerHandleImageNormal.Size.Height, UpperHandleImageNormal.Size.Height) + SpaceAboveThumbs);

it seems that LowerHandleImageNormal is null, and LowenHandleImageNormal is:

private UIImage LowerHandleImageNormal
       {
           get
           {
               if (_lowerHandleImageNormal != null)
                   return _lowerHandleImageNormal;
               if (IS_PRE_IOS7())
               {
                   var image = ImageFromBundle(Enabled ? @"slider-default-handle" : @"slider-default-handle-disabled");
                   _lowerHandleImageNormal = image.ImageWithAlignmentRectInsets(new UIEdgeInsets(0, 2, 0, 2));
               }
               else
               {
                   var image = ImageFromBundle(Enabled ? @"slider-default7-handle" : @"slider-default7-handle-disabled");
                   _lowerHandleImageNormal = image.ImageWithAlignmentRectInsets(new UIEdgeInsets(-1, 8, 1, 8));
               }

               return _lowerHandleImageNormal;
           }
       }

and I'm on iOS 11, so that if the "else" branch which cause the null reference exception.

I ran the Samples demo and it works, I took the Sample example and inserted it into my project as first page.. and I got the exception.

Magic73 avatar Mar 29 '18 10:03 Magic73

Ok.. now I just copied all the slider*.png into my Resorce folder of the iOS project, and now it works.

@halkar , may you fix it? (also the missing nuget dependency from Xamarin.RangeSlider)

Magic73 avatar Mar 29 '18 10:03 Magic73

Is this fixed yet? Because, Still I'm getting the error.

mhdshbk avatar Apr 19 '18 07:04 mhdshbk

No, I need time to fix it (and I don't have it). @Magic73 mentioned a workaround which you can use.

halkar avatar Apr 25 '18 09:04 halkar

PR #138 looks like it would fix this bug, can we merge the change and release a new version @halkar?

joshlperry avatar Aug 13 '18 11:08 joshlperry

@Pezzman unfortunately it doesn't

halkar avatar Aug 16 '18 12:08 halkar

@Magic73 thank you, your work around worked for me

KevinAble avatar Aug 28 '18 17:08 KevinAble

Did you resolve the issue that was preventing the Xamarin.Forms version from working in iOS? Based on the comments, it does not appear so.

DavidSilverlight avatar Sep 24 '18 17:09 DavidSilverlight

I use it on all of the three Platform.

Magic73 avatar Sep 24 '18 17:09 Magic73

From following the comments, I am understanding that you were able to implement a workaround successfully, and all 3 platforms work for you, but that workaround did not fix it for everybody. Is that correct?

DavidSilverlight avatar Sep 24 '18 17:09 DavidSilverlight

I can't even reference this properly on iOS my refs have a yellow exclaimation mark and in code R# cannot find the RangeSlider class ... odd.

jamsoft avatar Sep 26 '18 13:09 jamsoft

Resolution

  1. Clone this repo.
  2. Copy all the slider*.png files into Resources directory of the IOS project.
  3. Make sure this line is present in the app delegate.cs
[assembly: Xamarin.Forms.ExportRenderer(typeof(Xamarin.RangeSlider.Forms.RangeSlider), typeof(Xamarin.RangeSlider.Forms.RangeSliderRenderer))]
  1. Also ensure the following is present
var t1 = typeof(Xamarin.RangeSlider.RangeSliderControl);
var t2 = typeof(RangeSliderRenderer);
  1. Clean and re-build the solution.
  2. Good to GO.
screen shot 2018-11-04 at 6 36 12 pm

navkar avatar Nov 04 '18 23:11 navkar

thanks @navkar that worked for us!

aarcoraci avatar Nov 23 '18 14:11 aarcoraci

Can you create a sample project for the solution and when do you update the repository ?

omersezer avatar Dec 02 '18 10:12 omersezer

Thanks

It is working for me also

AshishRanjanPM avatar Sep 13 '19 10:09 AshishRanjanPM

Thanks It's working for me :)

wondercrazy15 avatar Jul 04 '20 09:07 wondercrazy15

Please where i can get the Png slider files

abdo-012 avatar Mar 22 '23 10:03 abdo-012