Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent automatic scrolling for an Editor in Xamarin.Forms.iOS

I have a very simple Xamarin.Forms app. The Xaml is a Grid with one column, and two rows. The first row contains an Entry control. The second row contains a Scrollview, which contains an Editor control (multiline text box). The second row's height is *. The Scrollview VerticalOptions is set to FillAndExpand.

The Editor needs to scroll when it fills up. The first Entry should stay where it is.

On Android the Editor control works as expected, it scrolls when it gets full up. But on iOS, as soon as the keyboard pops up, the Editor scrolls up, taking the cursor up out of sight. It also scrolls up when it only has a few lines of text in it, so they disappear. This behavior occurs on the iPhone simulator, and on a physical device.

I have tried all combinations of verticaloptions on the Scrollview, the grid, and the entry control. Nothing stops the unwanted scrolling.

I can't put a ScrollView round the whole grid because I need that first Entry to stay visible.

I cannot add pictures on this site yet, so here is a link to the layout:

image link

The garish colours are just so I can see where each control begins an ends. I am using the latest version of everything as of Jan 2016.

   <Grid Padding="5,5,5,5" RowSpacing="5" VerticalOptions="FillAndExpand"   HorizontalOptions="FillAndExpand" BackgroundColor="White"  >

    <!--One colum-->
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

    <!--- 2 rows (0-1). 0=title, 1=body-->
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <!-- row 0 Title -->
    <Entry x:Name="txtTitle" Grid.Row="0" Grid.Column="0" BackgroundColor="Gray" TextColor="Black" />

    <!-- row 1 Editor -->
    <ScrollView Grid.Row="1" Grid.Column="0" BackgroundColor="Red" Padding="5,5,5,5" >


        <!--Making the Editor FillAndExpand makes no difference-->   
        <Editor x:Name="txtBody" Grid.Row="1" Grid.Column="0" BackgroundColor="Olive"/>

        <!--  -->
     </ScrollView>


</Grid>
like image 618
Gurgamel Avatar asked Nov 09 '22 21:11

Gurgamel


1 Answers

Further update. I have found that the Editor control has its own scrolling. So I have removed the ScrollView around it. The problem still persists. Once the text in the Editor has more lines than the height of the Editor, you cannot scroll down to the last line in edit mode. It's fine if you only want to view the text, but as soon as you tap the screen to put it in edit mode, you cannot get to the last row. I have deployed this to an iPhone 4 (as the lowest common denominator) and taken a screen shot. See the 1111111 at the bottom of the green Editor? There is more text below that, but you cannot get to it in edit mode. The same thing happens in the Simulator, and on an iPad 3.

iPhone4 Screenshot

This seems to be a fundamental flaw with Xamarin's Editor control. Please can someone confirm is this being addressed or if there is a workaround?

like image 94
Gurgamel Avatar answered Jan 04 '23 03:01

Gurgamel