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

[UWP] Attempt to resolve entry on UWP not correctly calculating the correct height when in a scroll view #8214

Merged
merged 21 commits into from
Jan 11, 2020

Conversation

bmacombe
Copy link
Contributor

@bmacombe bmacombe commented Oct 24, 2019

Description of Change

It seems that when the UWP textbox is in a visual tree that includes a scroll view it seems to mis-measures the height of the text box. This change will set the native text box text property to string.empty while measuring which seems to result in the correct height being calculated. Once that is calculated, it sets the text value back from the XF element.

Used the method of using a static TextBox to do the measure that was already in use in the EditorRenderer to handle autosize. I pulled that code out and modified it, adding it as a static method on FormsTextBox. I then updated the EntryRenderer and EditorRenderer to use this code for measuring their size which corrects the issue.

To help validate I recreated the previous behavior in custom renderers (in the UWP Control Gallery) to show the previous behavior and the new behavior side by side on the issue page.

Issues Resolved

API Changes

None

Platforms Affected

  • UWP

Behavioral/Visual Changes

Correctly calculates the height of a text box in a scroll view.

Before/After Screenshots

Top entry using the existing renderer
Buttom entry using the experimental renderer
image

Testing Procedure

Open the issue page and view the entries

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)

@bmacombe
Copy link
Contributor Author

This PR needs to be finalized, looking for feedback from the XF team and the community before making final changes.

@bmacombe bmacombe changed the title GitHub 2172 [UWP] Attempt to resolve entry on UWP not correctly calculating the correct height when in a scroll view Oct 25, 2019
@bmacombe
Copy link
Contributor Author

This solution likely won't work, after more review I see unintended events being fired by changing the text value. The EntryRenderer updates the XF Entry when the native Textbox text changes.

@bmacombe
Copy link
Contributor Author

I wonder if this issue is related to this comment in VisualElementRenderer.

// Disabled until reason for crashes with unhandled exceptions is discovered
// Without this some layouts may end up with improper sizes, however their children
// will position correctly
//Loaded += (sender, args) => {
if (Packager != null)
	Packager.Load();
//};

@bmacombe
Copy link
Contributor Author

It does appear to be related. Calling Packager.Load() in the Loaded event in SetElement line 150 in visual state renderer resolves the issue. But that comment appears to be from Jason Smith. Thoughts from the XF team with more knowledge on how this process works would be appreciated.

// Disabled until reason for crashes with unhandled exceptions is discovered
// Without this some layouts may end up with improper sizes, however their children
// will position correctly
Loaded += (sender, args) =>
{
	if (Packager != null)
		Packager.Load();
};

image

@bmacombe
Copy link
Contributor Author

bmacombe commented Oct 28, 2019

Lastest observation. I tried stepping through the layout logic and seeing if I could force the items hosted by the ScrollViewer to update their layout, but I noticed that all the UWP LayoutUpdate, Loaded, etc events were being called before the first the requested size of the entry, so they had no effect.

I then refocused on the GetDesiredSize method of VisualElementRender and after just some random experimentation I noticed that heightConstraint was double.Infinity, which makes sense inside a ScrollViewer. But I don't think the UWP layout logic likes this.

Changing the heightConstraint to 500,000 (still effectively infinity as far as layout goes), caused the correct height of the FormsTextBox to be calculated.

if (double.IsInfinity(heightConstraint))
	heightConstraint = 500000;
return base.GetDesiredSize(widthConstraint, heightConstraint);

This "Test Renderer" entry is using a renderer that contains the code above in it's GetDesiredSize override.

image

@samhouts Would it be possible to get a review on method? This seems to be a reasonable solution as I think it would have little side effects.

I did try to recreate this issue in a standard UWP app, but I haven't been able to. So it's still possible there is a XF layout logic issue I'm missing.

@bmacombe
Copy link
Contributor Author

Well, scratch that one. It works in the simple layout in the Issue page, but not in a more complex layout in my own app. Hopefully these notes will help spur some thought in others.

@bmacombe
Copy link
Contributor Author

Another note, I see the UWP TextBox control template also includes a ScrollViewer. Maybe an issue?

<ScrollViewer x:Name="ContentElement" AutomationProperties.AccessibilityView="Raw" Grid.Column="0" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" IsTabStop="False" IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}" Margin="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" Grid.Row="1" VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" ZoomMode="Disabled"/>

@jfversluis
Copy link
Member

Hi @bmacombe thank you for your ongoing, extensive research and writeup on this. We really appreciate it!

I see you asking some feedback and things from time to time, but it's hard to make it concrete since you are progressing on your own 😄

The only thing I can see is to not pay too much attention to the comments in there. They might be pretty old and not relevant anymore. Just trust your own judgement on how to solve this best and of course keeping in mind that other controls and scenarios should just remain working. Did you by any chance get the UI tests running for UWP? That might be a good indication to go on.

Is there anything concrete you want us to look at at this time?

@bmacombe
Copy link
Contributor Author

@jfversluis I think you gave me what I need, Thanks!...I think the comment just made me nervous and unfortunately predates the import into GitHub so I haven't been able to track it back to an issue or find something in Bugzilla.

I think the right solution is to have the Packager.Load happen after the layout control has been loaded. I really think the issue is timing of when the various native UWP elements are created and asked to measure their size. Everything else seems way to much of hack...I might be willing to risk that in some app code...but not in framework code.

So I'll put Packager.Load back into the Loaded event and look into running the UWP UI tests. Just makes me nervous messing with such a root level item in the UWP platform. 😅

@jfversluis
Copy link
Member

Sure, always be careful at this level, but that just means you have to test all the things impacted by it more carefully 😉

Copy link
Member

@jfversluis jfversluis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do would like to get @PureWeen to either run the UWP UI tests or explain to @bmacombe how to run them :)

I think there are some instructions on the repo, did you see those? Here: https://github.com/xamarin/Xamarin.Forms/#run-uwp-ui-tests

@bmacombe
Copy link
Contributor Author

bmacombe commented Dec 9, 2019

I know how to run them 😁 but they don't run right on my machine...tried various versions of the driver etc. Not all the text gets filled in the various search boxes to pull up the tests. I had a little better luck if I changed the control gallery search bars to text boxes...but still had issues.

If anyone has some other suggestions to try I'd be glad to try them again.

@PureWeen
Copy link
Contributor

PureWeen commented Dec 9, 2019

@jfversluis running now

@PureWeen
Copy link
Contributor

@jfversluis This doesn't appear to break anything with the unit tests

Is the removal of this file intentional
https://github.com/xamarin/Xamarin.Forms/pull/8214/files#diff-9d8f28a74e9d78f5c7af9201bf8f98bbL1

@bmacombe
Copy link
Contributor Author

bmacombe commented Dec 10, 2019

@PureWeen I removed it because I accidentally added (or thought I did) when I accidentally staged and checked in those resharper settings. If there was already one there, I didn't realize it.

@bmacombe
Copy link
Contributor Author

I'll try to reverse that...new git skill to learn 😁

@bmacombe
Copy link
Contributor Author

bmacombe commented Dec 11, 2019

@PureWeen @jfversluis I believe I have reversed my resharper file delete...sorry about that!

@jfversluis
Copy link
Member

It appears so, great! Thanks!

@samhouts samhouts requested review from PureWeen and removed request for kingces95 January 1, 2020 01:01
@samhouts samhouts assigned PureWeen and unassigned kingces95 Jan 1, 2020
@samhouts samhouts changed the base branch from master to 4.5.0 January 7, 2020 00:57
@samhouts samhouts removed the request for review from PureWeen January 11, 2020 00:27
@samhouts samhouts assigned samhouts and unassigned PureWeen Jan 11, 2020
@samhouts samhouts merged commit b5b99b6 into xamarin:4.5.0 Jan 11, 2020
@samhouts samhouts added the approved Has two approvals, no pending reviews, and no changes requested label Jan 11, 2020
@bmacombe bmacombe deleted the GitHub_2172 branch January 11, 2020 02:32
tuyen-vuduc pushed a commit to NAXAM/Xamarin.Forms that referenced this pull request Jan 14, 2020
* 'master' of github.com:xamarin/Xamarin.Forms: (330 commits)
  [Android] Fix color filter usage on API29 (xamarin#9180)
  Add null check to GetIconColor (xamarin#9172)
  Apply cecil fixes to make packages 2017 compatible (xamarin#9145)
  [UWP] Attempt to resolve entry on UWP not correctly calculating the correct height when in a scroll view (xamarin#8214)
  Fixes 7992 Changes UWP DatePicker to show the picker flyout on DatePickerFocus() (xamarin#8056)
  Update bug_report.md (xamarin#8688)
  [android/ios] improve perf when not using Application.Properties (xamarin#8887)
  The great Androidx IF Def'ing of 2019 (xamarin#8898)
  Added IconColor property for managing navigation icon color (xamarin#5185)
  Add UWP display prompt (xamarin#8720)
  fix bad merge
  Fix 8743 - now using specific style in SearchBar [UWP] (xamarin#8773)
  Added the SwipeView tag to the Core Gallery samples (xamarin#8819)
  [Tizen] Shell: FlyoutBackgroundImage, FlyoutBackgroundImageAspect (xamarin#8905)
  [Core] remove array covariant cast for UWP (xamarin#9135)
  [android] remove Anticipator.cs for now (xamarin#8858)
  Update the CarouselView Position setting the CurrentItem (xamarin#7946) fixes xamarin#7924
  send remove events (xamarin#9124)
  [platform] improve perf of PropertyChangedEventArgsExtensions (xamarin#9084)
  Fix SeachBarRenderer CreateNativeControl issue (xamarin#8946)
  ...

# Conflicts:
#	Xamarin.Forms.Core/FontImageSource.cs
@samhouts samhouts added this to the 4.5.0 milestone Jan 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants