unoplatform / uno

Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
https://platform.uno
Apache License 2.0
8.76k stars 706 forks source link

Unable to disable scroll behavior for `ListView` and `GridView` #5645

Open MaksimNikonovOrioninc opened 3 years ago

MaksimNikonovOrioninc commented 3 years ago

Current behavior

Unable to disable Scroll behavior for ListView or GridView

Expected behavior

For ListView and GridView possible to change scroll behaviurs

How to reproduce it (as minimally and precisely as possible)

<ListView ScrollViewer.HorizontalScrollMode="Disabled">
</ListView>

Workaround

Environment

Nuget Package:

Nuget Package Version(s):

Affected platform(s):

IDE:

Relevant plugins:

Anything else we need to know?

davidjohnoliver commented 3 years ago

Uno doesn't yet support ScrollViewer-related attached properties. There are a couple of different workarounds possible, depending exactly what you're trying to do. If you just want to disable scrolling completely, then you could modify the template of the ListView/GridView (using the Uno style as a starting point) and set HorizontalScrollMode="Disabled" directly on the ScrollViewer inside the style. If you need to be able to toggle scrolling enabled, you might end up writing an attached behavior which looks for the ScrollViewer child of the list and sets the HorizontalScrollMode property dynamically.

MaksimNikonovOrioninc commented 3 years ago

@davidjohnoliver Setting HorizontalScrollMode="Disabled" on ScrollViewer not works, as workaround for this problem was iplemented next

  1. Extension method that could find find native ListViewBase control AndroidX.RecyclerView.Widget.RecyclerView for android and UIKit.UICollectionView for ios
  2. Was added disabling of scrolling in next way
#if NETFX_CORE
            List.GetScrollViewer().VerticalScrollMode = ScrollMode.Disabled;
#elif __ANDROID__
            var nativeList = (AndroidX.RecyclerView.Widget.RecyclerView)List.GetNativeListViewBase();
            nativeList.AddOnScrollListener(ScrollListener);
#elif __IOS__
            var nativeList = (UIKit.UICollectionView)List.GetNativeListViewBase();
            nativeList.ScrollEnabled = false;
#endif
  1. For android also was implemented custom scroll listener

    public class DisableScrollOnScrollListener : RecyclerView.OnScrollListener
    {
        public override void OnScrollStateChanged(RecyclerView recyclerView, int newState)
        {
            base.OnScrollStateChanged(recyclerView, newState);
    
            recyclerView.StopScroll();
        }
    }

Hope that would help to someone