Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Open up the CollectionView implementation on Android #6090

Closed
krdmllr opened this issue May 4, 2019 · 5 comments
Closed

Open up the CollectionView implementation on Android #6090

krdmllr opened this issue May 4, 2019 · 5 comments

Comments

@krdmllr
Copy link
Contributor

krdmllr commented May 4, 2019

Pretty much everything in the CollectionView Android implementation is internal and/or sealed. Making these classes accessible would give more room for customizations.

I'm talking about these classes: https://github.com/xamarin/Xamarin.Forms/tree/master/Xamarin.Forms.Platform.Android

I would like to override the ItemsViewAdapter OnBindViewHolder method but in order to do that I basicly have to copy the whole folder in my solution to use my own adapter. If the classes would be public, I could extend from the ItemsViewAdapter and override the required methods in the ItemsViewRenderer.

@samhouts
Copy link
Member

samhouts commented May 6, 2019

@krdmllr We're definitely planning to open these up before CollectionView is stable. Any API that we haven't opened yet is subject to change significantly as we continue development. @hartez Are any of these ready to be opened yet, with the caveat that this preview API may not even exist as new builds are released? Thanks!

@hartez
Copy link
Contributor

hartez commented May 6, 2019

@krdmllr We're definitely planning to open these up before CollectionView is stable. Any API that we haven't opened yet is subject to change significantly as we continue development. @hartez Are any of these ready to be opened yet, with the caveat that this preview API may not even exist as new builds are released? Thanks!

We can consider anything and everything for opening up, with the caveat that anything public may change before we take this out of Preview. But we're being very careful about how we open things up because once an API becomes public, changing it becomes a problem.

@krdmllr Can you be more specific about which classes you're looking to use? I don't want to blindly mark everything public, but if you tell me what's blocking your implementation we can take a look.

@krdmllr
Copy link
Contributor Author

krdmllr commented May 6, 2019

Hi, first of all thank you for the fast and really nice response!
@hartez as I wrote, I wanted to override the ItemsViewAdapter.OnBindViewHolder. Unfortunatly, ItemsViewAdapter has an internal constructor which makes this impossible if I dont overlook something here. If I just copy the complete source code of the ItemsViewAdapter I ran into more issues since most classes that are used in the implementation are internal aswell.

To give you an insight on my specific use case: I try to implement a staggered collection view with 2 columns where some items span trough both columns horizontally. Creating a staggered collection view was really easy because you can override SelectLayoutManager like this:

protected override LayoutManager SelectLayoutManager(IItemsLayout layoutSpecification)
        {
            switch (layoutSpecification)
            {
                case GridItemsLayout gridItemsLayout:
                    var gridOrientation = gridItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal ?
                        StaggeredGridLayoutManager.Horizontal :
                        StaggeredGridLayoutManager.Vertical;
                    return new StaggeredGridLayoutManager(gridItemsLayout.Span, gridOrientation);
                case ListItemsLayout listItemsLayout:
                    var orientation = listItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal
                        ? LinearLayoutManager.Horizontal
                        : LinearLayoutManager.Vertical;

                    return new LinearLayoutManager(Context, orientation, false);
            }

            // Fall back to plain old vertical list
            // TODO hartez 2018/08/30 19:34:36 Log a warning when we have to fall back because of an unknown layout	
            return new LinearLayoutManager(Context);
        }

To get an item that spans trough all columns, the internet tells me that I should do this:

public final void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {

    StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) viewHolder.itemView.getLayoutParams();
    layoutParams.setFullSpan(true);
}

Which is the part where I can`t proceed without basicly copying the complete folder into my sourcee code because I cant extend the ItemsViewAdapter.

Edit: The complete code is here btw: https://github.com/krdmllr/Xappy/blob/master/Xappy/Xappy.Android/Renderers/XappyCollectionViewRenderer.cs

@krdmllr krdmllr mentioned this issue May 27, 2019
9 tasks
@pauldipietro pauldipietro added this to the 4.3.0 milestone Jul 24, 2019
@samhouts samhouts added inactive Issue is older than 6 months and needs to be retested help wanted We welcome community contributions to any issue, but these might be a good place to start! up-for-grabs We welcome community contributions to any issue, but these might be a good place to start! labels Nov 2, 2019
@samhouts samhouts removed this from the 4.3.0 milestone Nov 5, 2019
@samhouts samhouts removed help wanted We welcome community contributions to any issue, but these might be a good place to start! up-for-grabs We welcome community contributions to any issue, but these might be a good place to start! labels Feb 4, 2020
@hs79hs
Copy link

hs79hs commented Feb 29, 2020

Same needs here, because I encountered this RecyclerView's bug
and may need some changes to solve it

@samhouts samhouts removed the inactive Issue is older than 6 months and needs to be retested label Mar 2, 2020
@jfversluis
Copy link
Member

Thanks for this suggestion! As Xamarin.Forms is now in maintenance mode, this will not happen anymore for Xamarin.Forms. We're only adding bugfixes and stability fixes.

If this is still important to you, make sure to check the .NET MAUI repo and see if it's already on the roadmap. If not, feel free to open a discussion to discuss a change first or open an issue with a detailed feature request. Thanks!

@jfversluis jfversluis closed this as not planned Won't fix, can't repro, duplicate, stale Mar 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants