Secondary view doesn't resize when (eg) rotating the device
See original GitHub issueI’m trying to use ExpandableView to show a bit of text in the expanded view. This means that, depending on screen/window width and the length of the text, it can flow into several lines.
What I’ve found was that the secondary view’s height is kept following the first initialisation of the view, so when I rotate the device it will either clip the content or show additional blank space.
In order to get the control to work roughly as expected I have had to implement a few changes to the ExpandableView.cs class, adding this override for OnSizeAllocated.
``
private double _previousWidth;
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
if (width == _previousWidth)
{
//nothing to do
return;
}
else if (this.Status != ExpandStatus.Expanded && this.Status != ExpandStatus.Expanding)
{
// secondaryview is not visible, we should reset it so that it'll appear in the correct size when active
_lastVisibleHeight = -1;
}
else if ( this.Status != ExpandStatus.Collapsed && this.Status != ExpandStatus.Collapsing)
{
// secondaryview is visible, needs resizing to fit new width
this.SecondaryViewHeightRequest = -1;
this.ForceUpdateSize();
}
this._previousWidth = width;
}
Out of a few attempts at fixing this, this was the most complete solution:
- it resizes on UWP when resizing the window.
- it resizes when rotating the device the secondary view is open.
- it resizes correctly when you open the view, close it and rotate the device/resize the window, then reopen the view.
I am very keen on using this control (nice work Andrei), but can’t really do it without fixing this problem. Am I close to a (good enough) fix for the problem or have I somehow not noticed how resizing is supposed to be handled?
Thanks
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (6 by maintainers)
Well, my workaround isn’t necessarily the neatest code, it’s just where I got to to make it work - feel free to take the code, try it and change it if needed.
You’re right - I am likely overlooking many scenarios, as expandableview can be used in many different layouts. I didn’t care about height changes because I’ve made my layout consistent for the primaryview and only the secondaryview can have linebreaks in its content. I haven’t seen how primary view reacts with similar content.