Как получить доступ к верхней вкладке / панели инструментов для iOS на страницах оболочки? - PullRequest
0 голосов
/ 01 августа 2020

Я пытался установить параметры гравитации / позиционирования для верхней вкладки / панели инструментов (макет, который появляется, когда вы устанавливаете два ShellContents на вкладку). Это сработало на Android, поскольку средство визуализации Android Shell предоставляет как CreateBottomNavViewAppearanceTracker, так и CreateTabLayoutAppearanceTracker.

Однако средство визуализации iOS Shell предоставляет только CreateTabBarAppearanceTracker в отношении вкладок, которые только имеет дело (по крайней мере, насколько я понимаю) с нижней вкладкой (иерархически выше вкладок ShellContent).

Я попытался создать подкласс ShellItemRenderer, но не смог найти никаких свойств, связанных с тем, что я хотел.

Как это отображается на Android:

Внешний вид верхней панели вкладок на Android

1 Ответ

1 голос
/ 06 августа 2020

Я нашел решение для доступа к верхней вкладке / панели инструментов для iOS на страницах Shell. Вам нужен подкласс ShellSectionRootHeader, который сам является подклассом UICollectionViewController, который является собственным типом, который отображает верхнюю панель вкладок на iOS. Когда у вас есть этот подкласс, вы можете переопределить метод GetCell, чтобы получить каждый отдельный элемент в верхней панели вкладок и изменить их. Но для того, чтобы добраться до этой точки, вам необходимо создать подкласс и создать еще 2 рендерера помимо ShellRenderer.

Вот пример кода рендерера в iOS:

[assembly: ExportRenderer(typeof(Shell), typeof(CustomShellRenderer))]
namespace Xaminals.iOS
{
    public class CustomShellRenderer: ShellRenderer
    {
        protected override IShellSectionRenderer CreateShellSectionRenderer(ShellSection shellSection)
        {
            var shellSectionRenderer = new CustomShellSectionRenderer(this);
            return shellSectionRenderer;
        }
    }
    public class CustomShellSectionRenderer : ShellSectionRenderer
    {

        public CustomShellSectionRenderer(IShellContext context) : base(context)
        { }

        protected override IShellSectionRootRenderer CreateShellSectionRootRenderer(ShellSection shellSection, IShellContext shellContext)
        {
            var renderer = new CustomShellSectionRootRenderer(shellSection, shellContext);

            return renderer;
        }
    }

    public class CustomShellSectionRootRenderer : ShellSectionRootRenderer
    {
        public CustomShellSectionRootRenderer(ShellSection section, IShellContext context) : base(section, context)
        { }

        protected override IShellSectionRootHeader CreateShellSectionRootHeader(IShellContext shellContext)
        {
            var renderer = new CustomShellSectionRootHeader(shellContext);
            return renderer;
        }
    }

    public class CustomShellSectionRootHeader : ShellSectionRootHeader
    {
        public CustomShellSectionRootHeader(IShellContext context) : base(context)
        {
            
        }

        public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
        {
            var cell = base.GetCell(collectionView, indexPath) as ShellSectionHeaderCell;

            // Set desired font here 
            //cell.Label.Font = UIFont.ItalicSystemFontOfSize(11);

            var layout = new UICollectionViewFlowLayout();
            layout.MinimumInteritemSpacing = UIScreen.MainScreen.Bounds.Size.Width / 8;
            layout.SectionInset = new UIEdgeInsets(top: 0, left: UIScreen.MainScreen.Bounds.Size.Width/4, bottom: 0, right: 0);

            collectionView.CollectionViewLayout = layout;

            return cell;
        }
    }

    public class CustomUICollectionViewFlowLayout : UICollectionViewFlowLayout
    {
        public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(CGRect rect)
        {
            return base.LayoutAttributesForElementsInRect(rect);

        }

    }
}

Эффект:

введите описание изображения здесь

...