I'm using Xamarin.Forms 3.6 latest Version and AutoSize option of Editor control does not work for me.
Auto increase or decrees the height of Editor control when entering the text
Editor does not change the height
@kgbuddhima can you provide a repro please? Or the XAML and device you are testing?
I just tested this on an iOS device and for me the height is expanding without any issues
Is your Editor inside a ListView's ViewCell? Because in my experience AutoSize option doesn't work for this. Which is annoying indeed. We had to implement some renderer workarounds.
No it is inside a stack layout
Not sure if I should create a new issue for this, but it's so closely related... Basically the auto size works for me when editing the text, but when binding to a model that already has text in - the auto size only kicks in after the user starts typing. So yeah there is defo something not quite right around the auto size functionality.
Yes. One year ago I solved it by adding Invalidate() method to TestChanged event.
But now ti also diea not work for the editor.
Can anyone please attach a small project that demonstrates this issue? Thanks!
@kgbuddhima Since we haven't heard from you in more than 30 days, we hope this issue is no longer affecting you. If it is, please reopen this issue and provide the requested information so that we can look into it further. Thank you!
This issue is definitely still happening.
@Russc0 could you elaborate a bit more? Which version are you using? On which platform(s) does this happen? If at all possible it would be totally helping if you could create a little sample reproduction project that shows this problem.
iOS only I believe. Ok I've worked out the issue. If you set the Text before the height of the Editor has initialized. Ie. the height of the Editor view is -1 when you set Text then the AutoSize does not work. For example, if you set Text in the constructor then the Editor view is still -1.
Still have this bug on device
Layout code (part).txt
Can reproduce it ONLY using Material Design
The issue is still present in the latest version of XF for iOS and Android. The actual behaviour is that the Height of the Editor is not updating right away but only after writing some words in the following line. It happens when the Editor is not directly in the row of the Grid that it is set to auto.
To reproduce the problem use the following Content inside a ContentPage:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Frame BackgroundColor="Green" CornerRadius="18" Grid.Row="1" HasShadow="False" Padding="0" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="24" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Margin="4,0,0,0" VerticalOptions="Center" x:Name="m_oImageFaceIconSmall" HeightRequest="24" WidthRequest="24" Grid.Row="0" Grid.Column="0" />
<Editor BackgroundColor="Red" AutoSize="TextChanges" Grid.Column="1"/>
</Grid>
</Frame>
</Grid>
With the above code what you should see while typing in the Editor when it wraps the height of the Editor does not increment immediately. Continue to write some words and it will autosize.
On the other had if you take out the editor from inside the Frame and put it directly un the second Row of the first Grid it will behave as it should be (the control immediately increases/decreases size when arriving on the next/previous line)
Let me know if you cannot reproduce and I will attach a video. It happens always iOS and Android. It seems that the measure happens a while after the actual native controls changed size.
I was able to fix it on iOS with the following renderer:
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName== CustomEditorNoBorder.TextColorProperty.PropertyName && Control.ContentSize.Height > Control.Frame.Size.Height)
{
var fixedWidth = Control.Frame.Size.Width;
var newFrame = Control.Frame;
var newDim=Control.SizeThatFits(new CGSize(width: fixedWidth, nfloat.MaxValue));
newFrame.Size = new CGSize(Math.Max(newDim.Width, fixedWidth), newDim.Height);
Control.Frame = newFrame;
Element.HeightRequest = Control.Frame.Height;
}
}
but I was not able to fix it on Android.
I think it is a bug in the engine when the controls are nested. InvalidateLayout also does not work as it seems a problem from the layout above.
<Editor WidthRequest="{Binding Source={x:Reference YourEditorName}, Path=Width}"/>
fixed the problem for nested (in grid) editor