title: Xamarin CollectionView slow scrolling
body: <p>I have a collection view that shows chat messages, it has 10 possible data templates. Each data template contains a flexlayout(because I need to horizontally align it at left or right, like chat bubbles) and inside these flexlayouts, we have a single grid which may show an image, a label, a map or a media player. It loads very fast but is very slow while scrolling. I tried to take off the flexlayout but grid doesn't obey the LayoutOptions End/Start that I need, then I swapped FlexLayout by a ContentView that fills the screen(horizontally) and I was abble to align horizontally its childs. I have noticed no performance improvements with this change, maybe even got worse. Also I have read and done changes following suggestions from <a href="https://docs.microsoft.com/pt-br/xamarin/xamarin-forms/deploy-test/performance?context=xamarin/cross-platform" rel="noreferrer">Optimizing App Performance</a> but seems not be enough.</p>
  
  <p>Below I have my collectionview tag and an example of one data template, the others are very similar, almost doesn't have difference. My doubt is how can I improve this scenario?</p>
  
  <p><strong>CollectionView</strong></p>
  
  <pre><code>&lt;CollectionView x:Name="ChatCollectionView" SelectionMode="None" HorizontalScrollBarVisibility="Never" VerticalScrollBarVisibility="Always" ItemsUpdatingScrollMode="KeepLastItemInView" ItemTemplate="{StaticResource MsgTemplateSelector}" Margin="5,0,5,0" /&gt;
  </code></pre>
  
  <p><strong>One of data templates</strong></p>
  
  <pre><code>&lt;DataTemplate x:Key="DefaultMsg"&gt;
      &lt;FlexLayout Direction="Row" MinimumWidthRequest="50" JustifyContent="{Binding MsgAlign}"&gt;
              &lt;Grid Padding="0" Margin="0,10,0,0"&gt;
                  &lt;Grid.RowDefinitions&gt;
                      &lt;RowDefinition /&gt;
                      &lt;RowDefinition Height="20"&gt;&lt;/RowDefinition&gt;
                  &lt;/Grid.RowDefinitions&gt;
  
                  &lt;BoxView Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="0" Grid.RowSpan="2" CornerRadius="5" BackgroundColor="{Binding MsgBg}" /&gt;
                  &lt;Label Grid.Row="0" Grid.Column="0" Text="{Binding msg}" TextColor="Black" /&gt;
  
                  &lt;Grid Grid.Row="1" Grid.Column="0"&gt;
                      &lt;Grid.ColumnDefinitions&gt;
                          &lt;ColumnDefinition Width="*" /&gt;
                          &lt;ColumnDefinition Width="20" /&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
  
                      &lt;Label Grid.Column="0" Grid.Row="0" TextColor="DarkGray" FontSize="12"&gt;
                          &lt;Label.FormattedText&gt;
                              &lt;FormattedString&gt;
                                  &lt;Span Text="&amp;#xf017; "&gt;
                                      &lt;Span.FontFamily&gt;
                                          &lt;OnPlatform x:TypeArguments="x:String" Android="Font-Awesome-Free-Solid.otf#FontAwesome5Free-Solid" iOS="FontAwesome5Free-Solid" /&gt;
                                      &lt;/Span.FontFamily&gt;
                                  &lt;/Span&gt;
                                  &lt;Span Text="{Binding date}" /&gt;
                                  &lt;Span Text=" at " /&gt;
                                  &lt;Span Text="{Binding hour}" /&gt;
                              &lt;/FormattedString&gt;
                          &lt;/Label.FormattedText&gt;
                      &lt;/Label&gt;
  
                      &lt;ActivityIndicator Grid.Column="1" Grid.Row="0" Color="#ff9000" HeightRequest="15" WidthRequest="15" IsRunning="{Binding sending}" IsVisible="{Binding sending}" HorizontalOptions="End" /&gt;
                      &lt;Label Grid.Column="1" Grid.Row="0" Text="{Binding icon}" IsVisible="{Binding sent}" TextColor="{Binding IconColor}" FontSize="15" HorizontalOptions="End"&gt;
                          &lt;Label.FontFamily&gt;
                              &lt;OnPlatform x:TypeArguments="x:String" Android="Font-Awesome-Free-Solid.otf#FontAwesome5Free-Solid" iOS="FontAwesome5Free-Solid" /&gt;
                          &lt;/Label.FontFamily&gt;
                      &lt;/Label&gt;
                  &lt;/Grid&gt;
              &lt;/Grid&gt;
      &lt;/FlexLayout&gt;
  &lt;/DataTemplate&gt;
  </code></pre>