No @Navigator.Name annotation found
Android application type
Classic Xamarin.Android (MonoAndroid12.0, etc.)
Affected platform version
Visual Studio Community 2022 for Mac Version 17.4.4, Xamarin.Android 13.1.0.1
Description
I try to create custom AndroidX.Navigation.Navigator. My CustomFragmentNavigator implements IName:
public class CustomFragmentNavigator : AndroidX.Navigation.Navigator, AndroidX.Navigation.Navigator.IName
{
public string Value()
{
return "customFragment";
}
public Class AnnotationType()
{
return Class;
}
...
}
Also I create CustomNavHostFragment:
public class CustomNavHostFragment : AndroidX.Navigation.Fragment.NavHostFragment
{
protected override void OnCreateNavHostController(NavHostController navHostController)
{
base.OnCreateNavHostController(navHostController);
var navigator = new CustomFragmentNavigator(RequireContext(), ChildFragmentManager, GetContainerId());
navHostController.NavigatorProvider.AddNavigator(navigator);
}
int GetContainerId()
{
if (Id > 0)
return Id;
return Resource.Id.nav_host_fragment_container;
}
}
When executing Java.Lang.IllegalArgumentException has been thrown (No @Navigator.Name annotation found for CustomFragmentNavigator).
What is analog of attribute @Navigator.Name("customFragment") in Xamarin?
Steps to Reproduce
- Create custom AndroidX.Navigation.Navigator
- Create custom AndroidX.Navigation.Fragment.NavHostFragment and add navigator from previous step
- Use custom NavHostFragment in layout
Did you find any workaround?
No response
Relevant log output
No response
@Edyazn,
About 18 months ago I had
java.lang.IllegalArgumentException: No @Navigator.Name annotation found for NavGraphNavigator. Issue #6928
I had to add the following to proguard.cfg to fix it.
-keepattributes RuntimeVisibleAnnotations
-keep class * extends androidx.navigation.Navigator
I didn't have a custom navigator though.
I'd need to remove those lines and test again to know if they are still required.
@gmck, default Navigator works correctly. But I need custom implementation for my case. It looks like Xamarin doesn't support it...
@Edyazn Can you provide minimal repro sample please?
Sample is here: https://github.com/Edyazn/CustomNavigatorIssue
@moljac, have you seen my sample?
@Edyazn Yes I have. Thanks.
But I didn't dive in deeper, yet.