Skip to content

Commit 337728d

Browse files
authored
Mark OffscreenPageLimitProperty as obsolete and remove unused code (#31306)
> [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ## Description This PR marks the `OffscreenPageLimitProperty` and all related methods as obsolete throughout the .NET MAUI codebase to indicate that these APIs are deprecated and should not be used in future development. Additionally, it removes unused code that was identified during the review process. ## Changes ### API Deprecation Applied `[System.Obsolete]` attributes to the following APIs in `Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific.TabbedPage`: - `OffscreenPageLimitProperty` - The BindableProperty definition - `GetOffscreenPageLimit(BindableObject)` - Static getter method - `SetOffscreenPageLimit(BindableObject, int)` - Static setter method - `OffscreenPageLimit(IPlatformElementConfiguration<Android, FormsElement>)` - Extension method - `SetOffscreenPageLimit(IPlatformElementConfiguration<Android, FormsElement>, int)` - Extension setter method ### Implementation Updates - Added `#pragma warning disable CS0618` around existing usage sites to suppress obsolete warnings in internal implementation code: - `TabbedPageRenderer.UpdateOffscreenPageLimit()` (Compatibility layer) - **Removed unused code**: Deleted the `UpdateOffscreenPageLimit()` method from `TabbedPageManager.cs` since no code was calling it - Preserved the `UpdateOffscreenPageLimit()` method in `TabbedPageRenderer.cs` (compatibility layer) where it is actually used ### Code Cleanup The unused `UpdateOffscreenPageLimit()` method in the modern `TabbedPageManager` implementation was removed as it was never called, while preserving the same method in the compatibility layer where it's properly utilized. ## Impact - **Backward Compatibility**: All existing code continues to work unchanged - **Developer Guidance**: Developers using these APIs will now receive compiler warnings indicating deprecation - **Internal Implementation**: Framework internals continue to function with appropriate warning suppression - **Code Quality**: Removed dead code that was not being used - **Future Direction**: Signals to developers that these APIs may be removed in future versions ## Testing - All existing TabbedPage unit tests continue to pass - Core.Controls and Compatibility projects build successfully - No breaking changes to public API surface beyond the addition of obsolete attributes This change follows the established pattern for deprecating APIs in the .NET MAUI codebase and provides clear guidance to developers about the future direction of these APIs. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.
2 parents 037ae97 + 894da1d commit 337728d

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/Compatibility/Core/src/Android/AppCompat/TabbedPageRenderer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,9 @@ void UpdateIgnoreContainerAreas()
573573

574574
void UpdateOffscreenPageLimit()
575575
{
576+
#pragma warning disable CS0618 // Type or member is obsolete
576577
_viewPager.OffscreenPageLimit = Element.OnThisPlatform().OffscreenPageLimit();
578+
#pragma warning restore CS0618 // Type or member is obsolete
577579
}
578580

579581
void UpdateSwipePaging()

src/Controls/src/Core/Platform/Android/TabbedPageManager.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,6 @@ void UpdateIgnoreContainerAreas()
477477
child.IgnoresContainerArea = child is NavigationPage;
478478
}
479479

480-
void UpdateOffscreenPageLimit()
481-
{
482-
_viewPager.OffscreenPageLimit = Element.OnThisPlatform().OffscreenPageLimit();
483-
}
484-
485480
internal void UpdateSwipePaging()
486481
{
487482
_viewPager.UserInputEnabled = Element.OnThisPlatform().IsSwipePagingEnabled();

src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/TabbedPage.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,22 @@ public static IPlatformElementConfiguration<Android, FormsElement> DisableSmooth
108108
}
109109

110110
/// <summary>Bindable property for <see cref="OffscreenPageLimit"/>.</summary>
111+
[System.Obsolete("OffscreenPageLimitProperty is obsolete. This property will be removed in a future version.")]
111112
public static readonly BindableProperty OffscreenPageLimitProperty =
112113
BindableProperty.Create("OffscreenPageLimit", typeof(int),
113114
typeof(TabbedPage), 3, validateValue: (binding, value) => (int)value >= 0);
114115

115116
/// <summary>Returns the number of offscreen pages are cached in memory.</summary>
116117
/// <param name="element">The platform specific element on which to perform the operation.</param>
117118
/// <returns>The number of offscreen pages are cached in memory.</returns>
119+
[System.Obsolete("GetOffscreenPageLimit is obsolete. This method will be removed in a future version.")]
118120
public static int GetOffscreenPageLimit(BindableObject element)
119121
{
120122
return (int)element.GetValue(OffscreenPageLimitProperty);
121123
}
122124

123125
/// <include file="../../../../docs/Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific/TabbedPage.xml" path="//Member[@MemberName='SetOffscreenPageLimit'][1]/Docs/*" />
126+
[System.Obsolete("SetOffscreenPageLimit is obsolete. This method will be removed in a future version.")]
124127
public static void SetOffscreenPageLimit(BindableObject element, int value)
125128
{
126129
element.SetValue(OffscreenPageLimitProperty, value);
@@ -129,12 +132,14 @@ public static void SetOffscreenPageLimit(BindableObject element, int value)
129132
/// <summary>Returns the number of offscreen pages are cached in memory.</summary>
130133
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
131134
/// <returns>The number of offscreen pages are cached in memory.</returns>
135+
[System.Obsolete("OffscreenPageLimit is obsolete. This method will be removed in a future version.")]
132136
public static int OffscreenPageLimit(this IPlatformElementConfiguration<Android, FormsElement> config)
133137
{
134138
return GetOffscreenPageLimit(config.Element);
135139
}
136140

137141
/// <include file="../../../../docs/Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific/TabbedPage.xml" path="//Member[@MemberName='SetOffscreenPageLimit'][2]/Docs/*" />
142+
[System.Obsolete("SetOffscreenPageLimit is obsolete. This method will be removed in a future version.")]
138143
public static IPlatformElementConfiguration<Android, FormsElement> SetOffscreenPageLimit(this IPlatformElementConfiguration<Android, FormsElement> config, int value)
139144
{
140145
SetOffscreenPageLimit(config.Element, value);

0 commit comments

Comments
 (0)