halkar / xamarin-range-slider

Range slider for Xamarin and Xamarin.Forms
https://www.nuget.org/packages/Xamarin.Forms.RangeSlider/
MIT License
89 stars 51 forks source link

Doesn't work on iOS with forms #115

Open hktari opened 6 years ago

hktari commented 6 years ago

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

halkar commented 6 years ago

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

jeedee commented 6 years ago

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 :)

Magic73 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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)

mhdshbk commented 6 years ago

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

halkar commented 6 years ago

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

joshlperry commented 6 years ago

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

halkar commented 6 years ago

@Pezzman unfortunately it doesn't

KevinAble commented 6 years ago

@Magic73 thank you, your work around worked for me

DavidSilverlight commented 6 years ago

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.

Magic73 commented 6 years ago

I use it on all of the three Platform.

DavidSilverlight commented 6 years ago

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?

jamsoft commented 6 years ago

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.

navkar commented 6 years ago

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
aarcoraci commented 5 years ago

thanks @navkar that worked for us!

omersezer commented 5 years ago

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

AshishRanjanPM commented 5 years ago

Thanks

It is working for me also

wondercrazy15 commented 4 years ago

Thanks It's working for me :)

abdo-012 commented 1 year ago

Please where i can get the Png slider files