RelativeLayout not responding to user-input in iOS

StefaanAvonds.3725StefaanAvonds.3725 ✭✭✭USMember ✭✭✭

Hi everyone

For some reason an entry in iOS isn't responding to any user-input once it is programmatically added to a RelativeLayout while it does work in Android.

The XAML:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="TempProject.Pages.FullRelativeLayoutPage">

    <Image x:Name="imgTest" />

    <StackLayout Orientation="Vertical" Padding="15, 70, 15, 2">
      <Entry TextColor="Black" BackgroundColor="Blue" />
    </StackLayout>

</ContentPage>

C#:

namespace TempProject.Pages
{
    public partial class FullRelativeLayoutPage : ContentPage
    {
        public FullRelativeLayoutPage()
        {
            InitializeComponent();
        }

        protected override void OnAppearing()
        {
            base.OnAppearing();

            var relativeLayout = new RelativeLayout();
            relativeLayout.InputTransparent = true;

            relativeLayout.Children.Add(Content,
                Constraint.RelativeToParent((parent) => 1 * parent.X),
                Constraint.RelativeToParent((parent) => 1 * parent.Y),
                Constraint.RelativeToParent((parent) => 1 * parent.Width),
                Constraint.RelativeToParent((parent) => 1 * parent.Height)
            );

            Content = relativeLayout;
        }
    }
}

How come in Android this entry is editable, but in iOS it is not? FYI a button is not responding either.

Answers

  • StefaanAvonds.3725StefaanAvonds.3725 ✭✭✭ USMember ✭✭✭

    UPDATE:
    I've tried to make a custom renderer to convert the controls to the native UIView so these could be added to a new UICollectionView:

        public class BaseRelativeLayoutRenderer : ViewRenderer<RelativeLayout, UIView>
        {
            protected override void OnElementChanged(ElementChangedEventArgs<RelativeLayout> e)
            {
                base.OnElementChanged(e);
    
                if (e.NewElement == null) return;
    
                var fullSize = new CoreGraphics.CGRect(e.NewElement.X, e.NewElement.Y, e.NewElement.Width, e.NewElement.Height);
                var native = new UICollectionView(fullSize, new UICollectionViewLayout());
    
                foreach (var item in e.NewElement.Children)
                {
                    var renderer = Platform.CreateRenderer(item);
                    var size = new CoreGraphics.CGRect(item.X, item.Y, item.Width, item.Height);
                    renderer.NativeView.Frame = size;
    
                    renderer.NativeView.AutoresizingMask = UIViewAutoresizing.All;
                    renderer.NativeView.ContentMode = UIViewContentMode.ScaleToFill;
    
                    renderer.Element.Layout(size.ToRectangle());
    
                    renderer.NativeView.SetNeedsLayout();
    
                    native.Add(renderer.NativeView);
                }
    
                SetNativeControl(native);
            }
        }
    

    This almost works: both an entry and a button respond to the users interactions, but some things still aren't rendered correctly. For example a ScrollView isn't working anymore (scroll is disabled). Also the Syncfusion SfDataGrid is rendered twice, but only one is scrollable while the other just stays still in the background ...

    Anyone know what the solution is, or how to edit the custom renderer from above?

Sign In or Register to comment.