Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Fix ShellContent Title Does Not Update at Runtime #26062

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ public override void ViewDidLoad()

UpdateSelectedIndex();
ShellSection.PropertyChanged += OnShellSectionPropertyChanged;
foreach (var shellContent in ShellSectionController.GetItems())
{
shellContent.PropertyChanged += OnShellContentPropertyChanged;
}
}

protected virtual Type GetCellType()
Expand All @@ -217,6 +221,10 @@ protected override void Dispose(bool disposing)
((IShellController)_shellContext.Shell).RemoveAppearanceObserver(this);
ShellSectionController.ItemsCollectionChanged -= OnShellSectionItemsChanged;
ShellSection.PropertyChanged -= OnShellSectionPropertyChanged;
foreach (var shellContent in ShellSectionController.GetItems())
{
shellContent.PropertyChanged -= OnShellContentPropertyChanged;
}

ShellSection = null;
_bar.RemoveFromSuperview();
Expand Down Expand Up @@ -282,6 +290,30 @@ void OnShellSectionItemsChanged(object sender, NotifyCollectionChangedEventArgs
ReloadData();
}

void OnShellContentPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(ShellContent.Title))
{
if (sender is ShellContent shellContent)
{
int index = ShellSectionController.GetItems().IndexOf(shellContent);
if (index >= 0)
{
UpdateHeaderTitle(index, shellContent);
}
}
}
}

void UpdateHeaderTitle(int index, ShellContent shellContent)
{
if (CollectionView.CellForItem(NSIndexPath.FromItemSection(index, 0)) is ShellSectionHeaderCell cell)
{
cell.Label.Text = shellContent.Title;
CollectionView.CollectionViewLayout.InvalidateLayout();
}
}

void ReloadData()
{
if (_isDisposed)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.