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

Cannot access disposed object #9

Open
alexrainman opened this issue Jan 13, 2016 · 5 comments
Open

Cannot access disposed object #9

alexrainman opened this issue Jan 13, 2016 · 5 comments

Comments

@alexrainman
Copy link

Chris, i discovered and issue with your implementation and a way to fix it. Sometimes the Renderer is collected when you close the screen, then, when you open it again and you try to swipe, it crash because Element is null.

The fix?

Android renderer:

void ElementPropertyChanged(object sender, PropertyChangedEventArgs e) {
    if (e.PropertyName == "Renderer") {
        _scrollView = (HorizontalScrollView)typeof(ScrollViewRenderer)
        .GetField ("hScrollView", BindingFlags.NonPublic | BindingFlags.Instance)
        .GetValue (this);
        _scrollView.HorizontalScrollBarEnabled = false;
        _scrollView.Touch += HScrollViewTouch;
    }

    if (Element == null) return; // this fix the issue

    if (e.PropertyName == CarouselLayout.SelectedIndexProperty.PropertyName && !_motionDown) {
        ScrollToIndex (((CarouselLayout)this.Element).SelectedIndex);
    }
}

iOS renderer:

void ElementPropertyChanged(object sender, PropertyChangedEventArgs e) {

    if (Element == null) return; // this fix the issue

    if (e.PropertyName == CarouselLayout.SelectedIndexProperty.PropertyName && !Dragging) {
        ScrollToSelection (false);
    }
}

Thanks for sharing this.

@DennisWelu
Copy link

@alexrainman Ran into the issue as well and verified your changes fix it, thanks!

@alexrainman
Copy link
Author

@DennisWelu the only cons this carousel has that it loads all the pages on startup and that is really slow in Android. I was working on one implementation myself https://github.com/alexrainman/CarouselView but Xamarin came with their own on version 2.2-pre-release and i have been working close with them helping to make it work as expected. It's close the be released.

@DennisWelu
Copy link

I'm glad you said something! I was just contemplating the way in which I was going to add virtualization to it... I'll check out the pre-release instead. Thanks again!

@chrisriesgo
Copy link
Owner

Yeah, the version that Xamarin is working on might be better suited -- especially concerning virtualization. My intention was to handle those concerns over time, but just never did. Thanks for the feedback :)

@chrisriesgo
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants