Prevent automatic scrolling for an Editor in Xamarin.Forms.iOS - 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>

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?

Related

Nativescript IOS: Textview not resizing after Input was cleared

I am trying to create a simple chat in nativescript-angular. On Android everything works fine, however on IOS I have this strange bug, where if the user inputs multiple lines into the textview, the textview does not return to the original state, after the message was sent.
The height of the textview is set to "auto", which is needed to have dynamic sizing for the Textview.
When the user clicks the "send" button, the textview should resize to the original size. However it stays the old height. On Android the TextView resizes perfectly..
This is my TextView:
<TextView #textView row="1" column="0" textWrap="true" lineHeight="4" height="auto"
[(text)]="message" (textChange)="onTextChange($event)" class="text-view" ></TextView>
And in my typescript i just set this.message = ''; which works fine enough on Android.
Any suggestions on how to make the TextView resize on IOS? I tried it with accessing the native element and set the height to auto again:
this.textView.nativeElement.height = "auto";
height is a PercentLength Property, and auto is a valid value, however it has no impact. It works if i set it to an absolute number, but I want to avoid that.
Thanks!
iOS doesn't re-layout upon text change, you may force re-layout with following code.
this.textView.nativeElement.requestLayout();

WKWebView broken scroll/selection when contenteditable="true"

When I load local html in WKWebView with <body contenteditable="true"> I need to scroll downwards when selecting range over keyboard.
In order to do that I have added some observers for keyboardWillShowOrHide and keyboardWillShowOrHide to adjust the scrollView.contentInset and scrollView.scrollIndicatorInsets. That works fine and as expected.
The problem now I'm experiencing is flickering and broken scroll while selecting range of text.
The flickering and broken scroll can be fixed by adding to html <body contenteditable="true" style="overflow:hidden;"> But that breaks the initial scroll downwards when selecting range over keyboard.
Any hints/help would be appreciated.
Here is a link to test projects git

Stretch WebView

I'm stuck on making a gif element which inherits from WebView. This "WebView" is representing the following html => String.Format(#"<html><body><img src='{0}'/></body></html>", value); where value is the URL to the GIF.
However, when I declare it with a local gif, it does work, but the focus of the webview is at the top/left. I can also move/scroll the view of the webview which overflows the limits of the screen..
So, how can I make this WebView stretch about the screen?
For your WebView make sure you have the Horizontal and Vertical Options set to stretch it to the entire screen.
<WebView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
For your gif you will probably want the below to stretch your gif to the entire visible area.
<html><body><img src='{0}' style='width:100%;height:100%;'/></body></html>
If you want the WebView to only be the size of what inside it, then unless you want to get into some complicated javascript callbacks, I would just get the size of the gif and set the width and height request on the WebView.

iOS converting UIView to ScrollView without destroying layout?

Is there any possibility to move from UIView to UIScrollView without destroying all the constraints and placement. The thing is I build the whole UI without testing it on iPhone 4 and now I see some views should be in Scroll View to work. I tried few tricks but nothing works. Constraints gets deleted. Below is the example picture of sample:
Now I want that test1 UIView to be Scroll View, I tried to put Scroll View inside test1 View and then recursively copy test1 inside scroll view and delete old elements but it didnt work (shown bellow)
If there is any way to convert UIView to UIScrollView without destroying constraints (even programatically) that would be great. Thanks
Yes
Simply replace the <view> element by <scrollView> in your XIB file:
Make a backup copy of your XIB file.
Edit your XIB file as plain text:
Xcode > Right click on XIB > Open As > Source Code
Finder > Right click on XIB > Open With > TextEdit
Replace the specific <view> tag by <scrollView>.
Replace attributes (see example below).
Keep the original id attribute.
Replace the closing </view> tag by </scrollView>.
I choose my battles. I prefer constraints as code.
Example, before:
<view contentMode="scaleToFill"
translatesAutoresizingMaskIntoConstraints="NO"
id="ABC-XY-123">
...
</view>
After:
<scrollView
clipsSubviews="YES"
multipleTouchEnabled="YES"
contentMode="scaleToFill"
alwaysBounceVertical="YES"
translatesAutoresizingMaskIntoConstraints="NO"
id="ABC-XY-123">
...
</scrollView>

Wrap Text Silverlight radio button

Is it possible to have the text in a radio button wrap itself? For example, I have a border area to work with that's approximately 350 pixels wide and I want to position some radio buttons in there. I can do that, but when the text is long, I cannot wrap the text.
Try this:
<RadioButton Width="100" >
<RadioButton.Content>
<TextBlock Text="This is some text that is very long" TextWrapping="Wrap" />
</RadioButton.Content>
</RadioButton>

Resources