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

Cannot Hide Scrollview Bar on Android when Horizontal #4142

Closed
Axemasta opened this issue Oct 19, 2018 · 4 comments
Closed

Cannot Hide Scrollview Bar on Android when Horizontal #4142

Axemasta opened this issue Oct 19, 2018 · 4 comments

Comments

@Axemasta
Copy link

Description

The scroll bar of a horizontal scroll view cannot be removed on android using the following code:

scrollView.HorizontalScrollBarEnabled = false;

I have tested this issue with the use of Custom Renderers & Platform Effects, and successfully recreated in a sample repository.

The scrollview code can be seen here (although i've had this issue in other projects that look different to this)

<ContentPage ...>
    <StackLayout ...>      
        ...
        <ScrollView Orientation="Horizontal" HeightRequest="200">
            <ScrollView.Effects>
                <effects:RemoveScrollBarEffect/>
            </ScrollView.Effects>
            ...
        </ScrollView>
        ...
    </StackLayout>
</ContentPage>

Steps to Reproduce

  1. Create a custom renderer or platform effect (verify this works before continuing)
  2. Acquire access to the scrollview and set the following property:
scrollView.HorizontalScrollBarEnabled = false;
  1. Set the scrollview orientation to horizontal
  2. Run the app on Android

Expected Behavior

The scrollbar has no horizontal indicator

Actual Behavior

The scrollbar has a horizontal indicator

This issue is not encountered on iOS, it behaves as usual (but obviously its a different platform & implementation).

Basic Information

  • Version with issue: 3.3.0.912540, 3.1.0.637273
  • Last known good version: ?
  • IDE: Visual Studio for Mac
  • Platform Target Frameworks:
    • Android: API 24,25
  • Android Support Library Version: 27.0.2.0
  • Nuget Packages: Fresh Project
  • Affected Devices:Android simulator + physical device (tested on Motorola Moto4G)

Screenshots

effect-droid
renderer-droid

Reproduction Link

I have created a standalone project demonstrating this issue, with a readme to guide you in setting up the issue.

https://github.com/Axemasta/ScrollView-Bug-Example

@pauldipietro pauldipietro added this to New in Triage Oct 19, 2018
@petermajor
Copy link

petermajor commented Oct 19, 2018

It's not possible to use an effect for this...

If you look at the ScrollViewRenderer for Android, you'll see that it's actually TWO scroll views - an external vertical ScrollView (this is the Control instance that you will get in the renderer/effect) and a subview (which is a HoriztonalScrollView instance) that you don't have access to.

However, you don't need to worry about this, because there is a property on the Xamarin Forms ScrollView element call "HorizontalScrollBarVisibility" that you can set to "Never".

@hartez
Copy link
Contributor

hartez commented Oct 19, 2018

Ah, petermajor beat me to it..

He's right about why your Effect doesn't work, and that you can just use the HorizontalScrollBarVisibility property to achieve the desired result.

But if you really, really need to access the horizontal ScrollView from an Effect, it is possible (if a bit cumbersome):

private void HideScrollBar(bool hide)
{
	try
	{
		var scrollView = (Android.Widget.ScrollView)Control;
		
		if (scrollView != null)
		{
			scrollView.VerticalScrollBarEnabled = false;

			// Dig into the Container to find the horizontal scroll view
			for (int n = 0; n < Container.ChildCount; n++)
			{
				if (Container.GetChildAt(n) is AHorizontalScrollView hsv)
				{
					hsv.HorizontalScrollBarEnabled = false;
					break;
				}
			}
		}
	}
	catch (Exception ex)
	{
		System.Diagnostics.Debug.WriteLine($"RemoveScrollBarEffect - Android - HideScrollBar - Error:'{ex.Message}'");
	}
}

@hartez hartez closed this as completed Oct 19, 2018
Triage automation moved this from New to Closed Oct 19, 2018
@Axemasta
Copy link
Author

@petermajor Hi Peter Thanks for the response, I was suspecting that this was something to do with the underthehood implementation, I would like to know why the HorizontalScrollBarEnabled does not have a warning associated with it.

I feel a bit dumb that I didn't see the solution that forms offers me but nevertheless I still see this as a bug because the API exists & won't work (without telling you why).

I might submit a request to have the docs updated to reflect this!

@Axemasta
Copy link
Author

@hartez Thanks a ton! It's nice to know that I can access it that way, this begs the question... Should this method be updated to call what you just wrote & to perform the task?

In my opinion having the method in Forms is a bad idea because it's essentially android specific code within a supposedly 'platform agnostic' project. Obviously I see this as a bug because I can quickly whip it up on iOS, and then it only half works on Android.

But I guess a doc change would suffice!
Thanks again.

@samhouts samhouts removed this from Closed in Triage Nov 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants