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

Port to C# #3

Open
alexrainman opened this issue May 27, 2015 · 17 comments
Open

Port to C# #3

alexrainman opened this issue May 27, 2015 · 17 comments

Comments

@alexrainman
Copy link

Can you do it?

@alexrainman
Copy link
Author

Hi, i ported this to C# myself and it works. A few things left to the side bacause i'm not an expert on Swift and it seems are not needed on Xamarin ( init(), DMDynamicPageViewControllerDelegate protocol). I still get "Index out of bounds" if i try to delete a Child when List is empty but i can handle that. Here is the link: https://gist.github.com/alexrainman/df03bd8d03a21783237d

Take a look, and maybe you can improve it.

Thank you!

@nsobadzhiev
Copy link
Owner

Oh, cool! I appreciate that and hope people will find it useful.
I'm not very good with C# so I cannot help much here, though.

@alexrainman
Copy link
Author

It's very useful as there's not default ViewPager on iOS/Xamarin/C# so, i hope people use it :)

@nsobadzhiev
Copy link
Owner

I should add a README file to the project and include a link to your port so that people are able to find it more easily. If that's OK with you, of course...

@alexrainman
Copy link
Author

Of course you can :)

@alexrainman
Copy link
Author

Hi Nik, i made a change to the port. CurrentPage wasn't updating so, i changed ScrollView Scrolled event to this:

[Foundation.Export ("scrollViewDidScroll:")]
public void Scrolled (UIScrollView scrollView)
{
// Update the page when more than 50% of the previous/next page is visible
var page = Math.Floor((containerScrollView.ContentOffset.X - pageWidth / 2) / pageWidth) + 1;

/*if (CurrentPage != (int)page) {
    // Check the page to avoid "index out of bounds" exception.
    if (page >= 0 && (int)page < ViewControllers.Count)
    {
        //self.notifyDelegateDidSwitchPage()
    }
}*/

// Check whether the current view controller is fully presented.
if ((int)containerScrollView.ContentOffset.X % (int)pageWidth == 0)
{
    CurrentPage = (int)page;
    //FullySwitchedPage = CurrentPage;
}

}

By the way, what "index out of bounds" code does?

@alexrainman
Copy link
Author

Hi Nik,
There's something this thing needs. It needs to behave like android viewpager and recycle rendered screens. That means that only 3 screens will be rendered at a time: previous, current and next.

Can you implement it on yours so i can port it to C#?

Thanks.

@alexrainman
Copy link
Author

maybe you can take a look at this: http://stackoverflow.com/questions/14755782/releasing-unused-pages-in-uipageviewcontroller and we can work it out together :)

@nsobadzhiev
Copy link
Owner

That sounds like a nice idea!

And you know what's going to be a good way to achieve that? Those "lazy" variables that Swift inherits from functional programming. We can make the viewControllers array generate it's next/previous item "on-demand". That's going to be sweet.

However, I'm not sure you will be able to easily port to C#. Does it have similar functionality?

@alexrainman
Copy link
Author

C# supports Lazy, i don't know if that's the equivalent. Can you give an example?

@nsobadzhiev
Copy link
Owner

I was referring to Swift lazy collections.
But now that I think about it, it's not going to help us all that much. Maybe it would be better to just use a data source like the conventional UIPageViewController.

@alexrainman
Copy link
Author

How can i add a listener to this thing so, when i am at the last controller, if i swipe/drag from right to left, load more items?

@alexrainman
Copy link
Author

Take a look at this, it may help you with the loading and recycling views. The code seems to be complicated comparing with yours: https://github.com/nicklockwood/SwipeView

@alexrainman
Copy link
Author

I was able to load more with this code:

[Foundation.Export ("scrollViewWillBeginDragging:")]
public void DraggingStarted (UIKit.UIScrollView scrollView)
{
_contentOffsetX = scrollView.ContentOffset.X;
}

[Foundation.Export ("scrollViewDidEndDragging:willDecelerate:")]
public async void DraggingEnded (UIKit.UIScrollView scrollView, bool willDecelerate)
{
if (_contentOffsetX < scrollView.ContentOffset.X) {
}
}

@nsobadzhiev
Copy link
Owner

I've pushed some changes in a new branch - dataSourceFeature. It's far from ready, but it outlines my basic idea.

@alexrainman
Copy link
Author

K, i will take a look, Tanke

@alexrainman
Copy link
Author

Nik,

I added this line of code to your library ViewDidLoad event to solve dragging problem when only 1 view:

containerScrollView.AlwaysBounceHorizontal = true;

I think we may create this thing inheriting from UIViewPageController that already has the view reusing functionality that we need. You may add your logic to Add/Remove views.

What do you think?

Tanke.

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

2 participants