forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Force off-main-thread ItemsSource updates to update on main thread (x…
…amarin#11235) * Fixed CollectionView issue adding data in different thread on Android * Fixed build error * Changes to fix the build * Force off-main-thread ObservableCollection changes to marshal to main thread * Update Xamarin.Forms.Controls.Issues.Shared.projitems * Update interface * Restore old method Co-authored-by: Javier Suárez Ruiz <[email protected]> Co-authored-by: Samantha Houts <[email protected]> Co-authored-by: Rui Marinho <[email protected]> fixes xamarin#10735 fixes xamarin#9753
- Loading branch information
Showing
11 changed files
with
830 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue10735.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<controls:TestContentPage | ||
xmlns:controls="clr-namespace:Xamarin.Forms.Controls" | ||
xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:d="http://xamarin.com/schemas/2014/forms/design" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
x:Class="Xamarin.Forms.Controls.Issue10735" | ||
Title="Issue 10735"> | ||
<StackLayout> | ||
<Label | ||
Padding="12" | ||
BackgroundColor="Black" | ||
TextColor="White" | ||
Text="If this sample works without exceptions, the test has passed."/> | ||
<CollectionView | ||
x:Name="_collectionView" | ||
ItemsSource="{Binding Items}" | ||
VerticalOptions="Fill" | ||
ItemSizingStrategy="MeasureAllItems" | ||
ItemsUpdatingScrollMode="KeepLastItemInView"> | ||
<CollectionView.ItemTemplate> | ||
<DataTemplate> | ||
<Label | ||
Text="{Binding}" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Center" | ||
FontSize="30" /> | ||
</DataTemplate> | ||
</CollectionView.ItemTemplate> | ||
</CollectionView> | ||
|
||
<StackLayout | ||
VerticalOptions="End" | ||
Orientation="Horizontal"> | ||
<Editor | ||
x:Name="_editor" | ||
HorizontalOptions="CenterAndExpand" | ||
AutoSize="TextChanges" /> | ||
<Button | ||
x:Name="_button" | ||
HorizontalOptions="CenterAndExpand"/> | ||
</StackLayout> | ||
</StackLayout> | ||
</controls:TestContentPage> |
77 changes: 77 additions & 0 deletions
77
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue10735.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using Xamarin.Forms.Internals; | ||
using Xamarin.Forms.CustomAttributes; | ||
using System.Threading.Tasks; | ||
using System.Collections.ObjectModel; | ||
|
||
#if UITEST | ||
using Xamarin.Forms.Core.UITests; | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls | ||
{ | ||
#if UITEST | ||
[Category(UITestCategories.CollectionView)] | ||
#endif | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 10735, "[Bug] [Fatal] [Android] CollectionView Causes Application Crash When Keyboard Opens", PlatformAffected.Android)] | ||
public partial class Issue10735 : TestContentPage | ||
{ | ||
readonly int _addItemDelay = 300; | ||
int _item = 0; | ||
#if APP | ||
readonly int _changeFocusDelay = 1000; | ||
View _lastFocus; | ||
#endif | ||
|
||
public Issue10735() | ||
{ | ||
#if APP | ||
InitializeComponent(); | ||
BindingContext = this; | ||
StartAddingMessages(); | ||
#endif | ||
} | ||
|
||
public ObservableCollection<string> Items { get; } = new ObservableCollection<string>(); | ||
|
||
protected override void Init() | ||
{ | ||
|
||
} | ||
|
||
void StartAddingMessages() | ||
{ | ||
Task.Run(async () => | ||
{ | ||
while (true) | ||
{ | ||
await Task.Delay(_addItemDelay); | ||
Items.Add(_item.ToString()); | ||
_item++; | ||
} | ||
}); | ||
#if APP | ||
Task.Run(async () => | ||
{ | ||
while (true) | ||
{ | ||
await Task.Delay(_changeFocusDelay); | ||
Device.BeginInvokeOnMainThread(() => | ||
{ | ||
_lastFocus?.Unfocus(); | ||
|
||
if (_lastFocus == _editor) | ||
_lastFocus = _button; | ||
else | ||
_lastFocus = _editor; | ||
|
||
_lastFocus.Focus(); | ||
}); | ||
} | ||
}); | ||
#endif | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.