xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] RefreshView Wrapped around CollectionView works on Android, but not on IOS (using Custom Renderer and disabling bouncing) #13351

Open aperel66 opened 3 years ago

aperel66 commented 3 years ago

Description

In the attached XAML GridListingView is a subclass of CollectionView

public class GridListingView : CollectionView, IAddUpdateRemoveListing, IDisposable
    {
        public static bool BugInIosCollectionView = true;
    }

          refreshView.Command = new Command(async () =>
            {
                refreshView.IsRefreshing = true;
                await ForceUpdateMyProfile();
                refreshView.IsRefreshing = false;
            });
<?xml version="1.0" encoding="UTF-8"?>
<cc:ContentViewEx 
            xmlns:cc="clr-namespace:CustomLibraries.XF;assembly=CustomLibraries.XF"
            xmlns:gg="clr-namespace:GlassGrabX"
            xmlns:ggcc="clr-namespace:GlassGrabX.CustomControls"
            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"
            xmlns:views="clr-namespace:GlassGrabX.Views"
            mc:Ignorable="d"
            x:Class="GlassGrabX.Views.MyProfileView"
            BackgroundColor="{DynamicResource WhiteInLightMode}"
            NavigationPage.HasNavigationBar="false">

    <cc:AbsoluteLayoutEx x:Name="MainLayout" WidthRequest="{Static cc:Globals.ScreenWidth}" HeightRequest="{Static cc:Globals.ScreenHeight}" BackgroundColor="{DynamicResource WhiteInLightMode}">
        <cc:StackLayoutEx Padding="{Binding ListingsViewPadding}" AbsoluteLayout.LayoutBounds="{Static cc:Globals.ScreenBelowTopBarLessBottomBar}" BackgroundColor="{Binding BackgroundColor}">
            <RefreshView x:Name="refreshView" IsRefreshing="False" IsEnabled="True"
                      HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                <ggcc:GridListingView x:Name="mainListings" Listings="{Binding CurrentListings}" IsVertical="True" 
                HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
                BackgroundColor="{Binding BackgroundColor}" Columns="{Static views:MyProfileView.ListingColumns}"
                ListingSize="{Static views:MyProfileView.ThumbnailSize}" 
                HorizontalSpacing="{Static views:MyProfileView.ColumnSpacing}"  
                VerticalSpacing="{Static views:MyProfileView.RowSpacing}" 
                DisplayPrice="true" ShouldGroupByCategory="True" DisplayFeaturedShadow="False" 
                IsBounceEnabled="False" CornerRadius="10">
                    <ggcc:GridListingView.Header>
                        <cc:StackLayoutEx x:Name="MainStack" BackgroundColor="{Binding BackgroundColor}" Spacing="0" VerticalOptions="FillAndExpand">
                            <cc:ImageEx x:Name="imgBanner" IsVisible="{Binding BannerVisible}" Source="{Binding Banner}" 
                            WidthRequest="{Binding BannerWidth}" HeightRequest="{Binding BannerHeight}"/>
                            <cc:GridEx x:Name="gridProfile" Padding="10,2,10,0" ColumnSpacing="15" Margin="{Binding ProfileImageMargin}">
                                <cc:GridEx.ColumnDefinitions>
                                    <ColumnDefinition Width="{Binding ProfileImageSize}"/>
                                    <ColumnDefinition Width="*"/>
                                </cc:GridEx.ColumnDefinitions>
                                <cc:GridEx.RowDefinitions>
                                    <RowDefinition Height="{Binding ProfileImageSize}"/>
                                    <RowDefinition Height="Auto"/>
                                </cc:GridEx.RowDefinitions>
                                <cc:StackLayoutEx Orientation="Vertical" Spacing="5" Grid.Row="0" Grid.Column="1" Grid.RowSpan="2">
                                    <BoxView HeightRequest="{Binding SpaceIfBannerExists}"/>
                                    <Label x:Name="lbName" Text="{Binding Name}" Style="{DynamicResource LargeLabelStyle}" FontSize="24" TextColor="{Binding TextColor}"/>
                                    <Label Text="{Binding AccountType}" Style="{DynamicResource RegularLabelStyle}" TextColor="{Binding TextColor}"/>
                                    <Label Text="{Binding ExtraDisplayName}" IsVisible="{Binding DisplayVisible}" Style="{DynamicResource RegularLabelStyle}" 
                               FontSize="12" TextColor="{Binding TextColor}"/>
                                    <cc:StackLayoutEx Orientation="Horizontal" HorizontalOptions="Start">
                                        <Frame x:Name="instagramLayout" HasShadow="False" Margin="0" Padding="5" CornerRadius="12" BorderColor="{DynamicResource InstagramColor}" IsVisible="{Binding InstagramVisible}">
                                            <cc:StackLayoutEx Orientation="Horizontal" Padding="1">
                                                <cc:ImageEx Source="{Static gg:Images.Img_instagram}" WidthRequest="18" HeightRequest="18"/>
                                                <Label Text="{Binding InstagramAccount}" Style="{DynamicResource SmallerLabelStyle}" VerticalTextAlignment="Center" TextColor="{DynamicResource InstagramColor}"/>
                                            </cc:StackLayoutEx>
                                        </Frame>
                                        <Label Text=" "/>
                                    </cc:StackLayoutEx>
                                    <cc:StackLayoutEx Orientation="Horizontal" Spacing="5" IsVisible="{Binding SellerHasRatings}">
                                        <cc:StarsView StarColor="{DynamicResource ThemeColor}" Padding="0,5,0,5" NumberOfStars="{Binding NumberOfStars}"/>
                                        <Label Text="{Binding ReviewsString}" Style="{DynamicResource SmallerLabelStyle}" VerticalOptions="Center" TextColor="{Binding TextColor}"/>
                                        <Label Text="{Binding ReviewsTitle}" Style="{DynamicResource SmallerLabelStyle}" VerticalOptions="Center" TextColor="{Binding TextColor}"/>
                                    </cc:StackLayoutEx>
                                </cc:StackLayoutEx>
                                <cc:ImageEx x:Name="ProfileImage" BackgroundColor="{Binding BackgroundColor}" Source="{Binding ProfileImage}" 
                            Grid.Row="0" Grid.Column="0" CornerRadius="{Binding ProfileImageCornerRadius}"/>
                            </cc:GridEx>
                            <cc:GridEx x:Name="gridBadges" RowSpacing="8" ColumnSpacing="8" Padding="10,5,10,5"/>
                            <cc:StackLayoutEx Orientation="Horizontal" Spacing="30" Padding="20,5,10,0" HorizontalOptions="Center">
                                <cc:StackLayoutEx Orientation="Vertical" Spacing="1">
                                    <Label x:Name="lbFollowsNum" Text="{Binding FollowersString}" Style="{DynamicResource TitleLabelStyle}" FontAttributes="Bold" 
                           FontSize="24" HorizontalTextAlignment="Center" TextColor="{Binding TextColor}"/>
                                    <Label x:Name="lbFollowers" Text="{Binding FollowersLabel}" Style="{DynamicResource RegularLabelStyle}" TextColor="{Binding TextColor}"
                           FontSize="14" HorizontalTextAlignment="Center"/>
                                </cc:StackLayoutEx>
                                <cc:StackLayoutEx Orientation="Vertical" Spacing="1">
                                    <Label x:Name="lbFollowingNum" Text="{Binding FollowingsString}" Style="{DynamicResource TitleLabelStyle}" FontAttributes="Bold" 
                           FontSize="24" HorizontalTextAlignment="Center" TextColor="{Binding TextColor}"/>
                                    <Label x:Name="lbFollowing" Text="Following" Style="{DynamicResource RegularLabelStyle}" TextColor="{Binding TextColor}"
                           FontSize="14" HorizontalTextAlignment="Center"/>
                                </cc:StackLayoutEx>
                                <cc:StackLayoutEx Orientation="Vertical" Spacing="1">
                                    <Label x:Name="lbSalesNum" Text="{Binding TransactionsString}" Style="{DynamicResource TitleLabelStyle}" FontAttributes="Bold" 
                                FontSize="24" HorizontalTextAlignment="Center" TextColor="{Binding TextColor}"/>
                                    <Label x:Name="lbSales" Text="Sales" Style="{DynamicResource RegularLabelStyle}" TextColor="{Binding TextColor}"
                                FontSize="14" HorizontalTextAlignment="Center"/>
                                </cc:StackLayoutEx>
                                <Label Text=" "/>
                            </cc:StackLayoutEx>

                            <BoxView HeightRequest="15"/>
                            <Label x:Name="lbBio" IsVisible="{Binding BioVisible}" Text="{Binding Bio}" TextColor="{Binding TextColor}"
                       Style="{DynamicResource RegularLabelStyle}" FontSize="13" Margin="20,0,20,0"/>
                            <BoxView HeightRequest="15"/>
                            <cc:GridEx x:Name="gridActions" Padding="10,0,10,0" HorizontalOptions="FillAndExpand" ColumnSpacing="10">
                                <cc:GridEx.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                </cc:GridEx.ColumnDefinitions>
                                <cc:GridEx.RowDefinitions>
                                    <RowDefinition Height="35"/>
                                </cc:GridEx.RowDefinitions>
                                <Button Grid.Column="0" Grid.Row="0" x:Name="btnEditProfile" Text="Edit Profile" Style="{DynamicResource NewButtonStyle}"/>
                                <Button Grid.Column="1" Grid.Row="0" x:Name="btnPromotions" Text="Promotions" Style="{DynamicResource NewButtonStyle}"/>
                                <Button Grid.Column="2" Grid.Row="0" x:Name="btnCustomizeProfile" Text="Customize" Style="{DynamicResource NewButtonStyle}"/>
                            </cc:GridEx>
                            <BoxView HeightRequest="15"/>
                            <cc:GridEx x:Name="tabGrid">
                                <cc:GridEx.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="1"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                </cc:GridEx.ColumnDefinitions>
                                <cc:GridEx.RowDefinitions>
                                    <RowDefinition Height="25"/>
                                    <RowDefinition Height="5"/>
                                </cc:GridEx.RowDefinitions>
                                <cc:LabelEx x:Name="lbListings" Text="My Listings" Style="{DynamicResource SmallLabelStyle}" 
                                        TextColor="{Binding TextColor}" Grid.Column="0" 
                                        HorizontalTextAlignment="Center" VerticalTextAlignment="End"/>
                                <cc:LabelEx x:Name="lbCollection" Text="My Collection" Style="{DynamicResource SmallLabelStyle}"
                                        TextColor="{Binding TextColor}" Grid.Column="1" IsVisible="False"
                                        HorizontalTextAlignment="Center" VerticalTextAlignment="End"/>
                                <cc:LabelEx x:Name="lbFavories" Text="Favorites" Style="{DynamicResource SmallLabelStyle}" 
                                        TextColor="{Binding TextColor}" Grid.Column="2" 
                                        HorizontalTextAlignment="Center" VerticalTextAlignment="End"/>
                                <cc:LabelEx x:Name="lbReviews" Text="Reviews" Style="{DynamicResource SmallLabelStyle}" 
                                        TextColor="{Binding TextColor}" Grid.Column="3" 
                                        HorizontalTextAlignment="Center" VerticalTextAlignment="End"/>
                                <cc:BoxViewEx x:Name="boxUnderline" HeightRequest="4" Grid.Row="1" Grid.Column="0" 
                                          BackgroundColor="{Binding TextColorSelected}"/>
                            </cc:GridEx>
                            <cc:LabelEx x:Name="lbAddToMyCollection" Style="{DynamicResource RegularLabelStyle}" TextColor="{Binding TextColorSelected}"
                                       Text="Add To My Collection" HorizontalOptions="EndAndExpand" IsVisible="False"/>
                            <BoxView HeightRequest="5"/>
                        </cc:StackLayoutEx>
                    </ggcc:GridListingView.Header>
                </ggcc:GridListingView>
            </RefreshView>
        </cc:StackLayoutEx>
        <cc:ImageEx Source="{Static gg:Images.Img_share}" x:Name="ivShare" ImageTintColor="{Binding Gray}"  AbsoluteLayout.LayoutBounds="{Static cc:Globals.LeftNavButtonRect}"/>
        <cc:ImageEx Source="{Static gg:Images.Img_moreOptions}" x:Name="ivMoreOptions" ImageTintColor="{DynamicResource GrayColor}" AbsoluteLayout.LayoutBounds="{Static cc:Globals.RightNavButtonRect}"/>
    </cc:AbsoluteLayoutEx>
</cc:ContentViewEx>

Steps to Reproduce

  1. Create an AbsoluteLayout that fills the screen
  2. Place RefreshView Inside AbsoluteLayout with "FillAndExpand" attributes
  3. Place CollectionView inside RefreshView and fill with items

Expected Behavior

RefreshView works and executes "Command" property

Actual Behavior

RefreshView works on Android, but not on IOS

Basic Information

Environment

Microsoft Visual Studio Community 2019 Version 16.8.3 VisualStudio.16.Release/16.8.3+30804.86 Microsoft .NET Framework Version 4.8.04084

Installed Version: Community

ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools

ASA Service Provider 1.0

ASP.NET and Web Tools 2019 16.8.554.20160 ASP.NET and Web Tools 2019

ASP.NET Core Razor Language Services 16.1.0.2052803+84e121f1403378489b842e1797df2f3f5a49ac3c Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2019 16.8.554.20160 For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 16.8.554.20160 Azure App Service Tools v3.0.0

Azure Data Lake Node 1.0 This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio 2.6.1000.0 Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 16.8.554.20160 Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.6.1000.0 Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus 1.2.6 (master@34d6af2) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Fabric.DiagnosticEvents 1.0 Fabric Diagnostic Events

IntelliCode Extension 1.0 IntelliCode Visual Studio Extension Detailed Info

Microsoft Azure HDInsight Azure Node 2.6.1000.0 HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service 2.6.1000.0 Language service for Hive query

Microsoft Azure Service Fabric Tools for Visual Studio 16.0 Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service 2.6.1000.0 Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node 1.0 Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.30924.1

Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager 2.1.113+g422d40002e.RR Install client-side libraries easily to any web project

Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Mono Debugging for Visual Studio 16.8.43 (00471f8) Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 5.8.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

SQL Server Data Tools 16.0.62010.06180 Microsoft SQL Server Data Tools

ToolWindowHostedEditor 1.0 Hosting json editor into a tool window

TypeScript Tools 16.0.21016.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 16.8.0-beta.20507.4+da6be68280c89131cdba2045525b80890401defd Microsoft Visual F# Tools

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions 1.0 View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers

Visual Studio Tools for Kubernetes 1.0 Visual Studio Tools for Kubernetes

VisualStudio.DeviceLog 1.0 Information about my package

VisualStudio.Foo 1.0 Information about my package

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

Xamarin 16.8.000.260 (d16-8@fd405a2) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 16.8.0.507 (remotes/origin/d16-8@e87b24884) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 16.8.112 (86385a3) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 11.1.0.17 (d16-8/c0e2b8e) Xamarin.Android Reference Assemblies and MSBuild support. Mono: be2226b Java.Interop: xamarin/java.interop/d16-8@79d9533 ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000 SQLite: xamarin/sqlite/3.32.1@1a3276b Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-8@2fb1cbc

Xamarin.iOS and Xamarin.Mac SDK 14.6.0.15 (87a1b18d8) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Show/Hide Visual Studio info ``` ```

Build Logs

Screenshots

Reproduction Link

Workaround

aperel66 commented 3 years ago

Forgot to add in code behind:

            refreshView.Command = new Command(async () =>
            {
                refreshView.IsRefreshing = true;
                await ForceUpdateMyProfile();
                refreshView.IsRefreshing = false;
            });
PureWeen commented 3 years ago

@aperel66 can you attach a reproduction?

I tested with our default template and it works fine for me there

image Issue13351.zip

aperel66 commented 3 years ago

Hello, Shane.

Thank you for looking into this issue. I must have failed to mention another important detail. In the IOS Renderer of CollectionView, set the Bounces property to FALSE Like so:

[assembly: ExportRenderer(typeof(CollectionView), typeof(CustomLibraries.iOS.CollectionViewRendererIos))] namespace CollectionViewExtension { public class CollectionViewRendererIos : CollectionViewRenderer { protected override void OnElementChanged(ElementChangedEventArgs e) { base.OnElementChanged(e); if (e.NewElement != null) { Controller.CollectionView.Bounces = false; } } } }

On Wed, Jan 20, 2021 at 7:13 PM Shane Neuville notifications@github.com wrote:

@aperel66 https://github.com/aperel66 can you attach a reproduction?

I tested with our default template and it works fine for me there

[image: image] https://user-images.githubusercontent.com/5375137/105256264-0933da00-5b4b-11eb-9d5c-938e3b3d6409.png Issue13351.zip https://github.com/xamarin/Xamarin.Forms/files/5845987/Issue13351.zip

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/xamarin/Xamarin.Forms/issues/13351#issuecomment-764057158, or unsubscribe https://github.com/notifications/unsubscribe-auth/AM6DKUGBQLZ2ZCKXIVRTTM3S25WSPANCNFSM4V3Z44XA .

-- Alex Perelberg

aperel6 aperel@optonline.net6@gmail.com (203) 858-1514

jsuarezruiz commented 3 years ago

Internally, on iOS, the RefreshView uses a UIRefreshControl and unfortunately, the refresh control won't get called without letting the UITableView bouncing.