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

SetHasOptionsMenu is not marked as deprecated in Xamarin.AndroidX.Navigation.Fragment 2.5.1 #607

Closed
gmck opened this issue Aug 30, 2022 · 1 comment

Comments

@gmck
Copy link

gmck commented Aug 30, 2022

Version Information

Visual Studio 17.4.0 Prv 1.0:
Xamarin.Android version (12/13):
Xamarin.AndroidX.Navigation.Fragment 2.5.1

@moljac
I recently updated from Xamarin.AndroidX.Navigation.Fragment 2.4.2 to 2.5.1 and because of deprecations on OnCreateOptionsMenu, OnPrepareOptionsMenu, OnOptionsItemSelected etc I got a heap of warnings. However, I noticed that SetHasOptionsMenu (or C# HasOptionsMenu = bool ) has not been marked as deprecated. According to Google’s docs, it should have. 2.5.1 depends on AndroidX.Fragment 1.5.1 so the real problem is in it.

I have a couple of tutorials on using Android’s NavigationComponent, so you could use those as test apps for catching new changes in both Navigation.Fragment and Navigation.UI as there hardly ever seems to be a point release that either breaks something or deprecates something.

To see the warnings (and the missing warning) you could download NavigationGraph5 and then just upgrade those two packages and rebuild.

NavigationGraph6 contains updated code using the new IMenuProvider and IMenuHost interfaces, so could be used for future changes to these packages.

https://github.com/gmck/NavigationGraph5
https://github.com/gmck/NavigationGraph6

@gmck gmck added the packages label Aug 30, 2022
@jpobst
Copy link
Contributor

jpobst commented Aug 30, 2022

The issue is that the setter SetHasOptionsMenu is @Deprecated, however the getter HasOptionsMenu is not.

This was a limitation of C# that you cannot place [Obsolete] on a property accessor which is what we would need to do:

public bool HasOptionsMenu {
  get;
  [Obsolete]
  set;
}
error CS1667: Attribute 'System.ObsoleteAttribute' is not valid on property or event accessors. It is only valid on 
'class, struct, enum, constructor, method, property, indexer, field, event, interface, delegate' declarations.

This appears to have been fixed in newer versions of the C# language, so I have filed an issue for our bindings generator to support it:
dotnet/java-interop#1033.

Closing this in favor of that issue.

@jpobst jpobst closed this as completed Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants