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

No @Navigator.Name annotation found #735

Open
Edyazn opened this issue May 26, 2023 · 6 comments
Open

No @Navigator.Name annotation found #735

Edyazn opened this issue May 26, 2023 · 6 comments

Comments

@Edyazn
Copy link

Edyazn commented May 26, 2023

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

  1. Create custom AndroidX.Navigation.Navigator
  2. Create custom AndroidX.Navigation.Fragment.NavHostFragment and add navigator from previous step
  3. Use custom NavHostFragment in layout

Did you find any workaround?

No response

Relevant log output

No response

@gmck
Copy link

gmck commented May 30, 2023

@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.

@Edyazn
Copy link
Author

Edyazn commented Jun 15, 2023

@gmck, default Navigator works correctly. But I need custom implementation for my case. It looks like Xamarin doesn't support it...

@moljac
Copy link
Member

moljac commented Jun 16, 2023

@Edyazn
Can you provide minimal repro sample please?

@Edyazn
Copy link
Author

Edyazn commented Jun 16, 2023

Sample is here: https://github.com/Edyazn/CustomNavigatorIssue

@Edyazn
Copy link
Author

Edyazn commented Jun 30, 2023

@moljac, have you seen my sample?

@moljac
Copy link
Member

moljac commented Jun 30, 2023

@Edyazn Yes I have. Thanks.

But I didn't dive in deeper, yet.

@jpobst jpobst removed the packages label Mar 14, 2024
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

4 participants