Xamarin.forms: CollectionView EmptyView in arabic on IOS is mirrored

Created on 4 Aug 2020  路  4Comments  路  Source: xamarin/Xamarin.Forms

CollectionView EmptyView in arabic on IOS is mirrored

Steps to Reproduce

<CollectionView ItemsSource="{Binding Path=BindingContext.ReceivedReminders, Source={x:ReferenceName=DashBoardView}}" 
                                            EmptyView="賲丕 賲賳 亘賳賵丿 賲賲賰賳 毓乇囟賴丕">
....

</CollectionView>
  • Xamarin.Forms 4.7.0.1080
  • iOS: 13.5.1
  • Affected Devices: iphone 6,7,8

Screenshots


image

collectionview 3 bug

Most helpful comment

Another workaround purely using xaml EmptyView data template, I just don't like CustomRenderers ;)

image

All 4 comments

A work around is to create an iOS renderer as follow:

`
[assembly: ExportRenderer(typeof(CollectionView), typeof(CustomCollectionViewRenderer))]
namespace MyApp.iOS.Renderers
{
class CustomCollectionViewRenderer : CollectionViewRenderer
{

    protected override void OnElementChanged(ElementChangedEventArgs<GroupableItemsView> e)
    {
        base.OnElementChanged(e);

        if (Control.PreferredFocusEnvironments[0] is UICollectionView collectionView)
        {
            CollectionView cv = (CollectionView)e.NewElement;

            UICollectionView control = (UICollectionView)Control.PreferredFocusEnvironments[0];

            if (control.EffectiveUserInterfaceLayoutDirection == UIUserInterfaceLayoutDirection.RightToLeft)
            {

                if (cv.EmptyView != null && cv.EmptyView is VisualElement)
                {
                    var emptyView = (VisualElement)cv.EmptyView;
                    emptyView.ScaleX = -1;
                    emptyView.ScaleY = 1;
                }
                else if (cv.EmptyView is string)
                {
                    cv.EmptyView = new Label()
                    {
                        Text = (string)cv.EmptyView,
                        VerticalOptions = LayoutOptions.Center,
                        HorizontalOptions = LayoutOptions.Center,
                        HorizontalTextAlignment = TextAlignment.Center,
                        VerticalTextAlignment = TextAlignment.Center,
                        ScaleX = -1,
                        ScaleY = 1
                    };
                }
            }
        }
    }
}

}
`

Another workaround purely using xaml EmptyView data template, I just don't like CustomRenderers ;)

image

Another workaround purely using xaml EmptyView data template, I just don't like CustomRenderers ;)

image

Nice workaround I liked it

collectionview.header has the same problem

Was this page helpful?
0 / 5 - 0 ratings