How to add Router when ux:AutoCtor=false?

I need little bit of uno code in one of my views and would also like to pass in a router.

<Panel ux:Class="MyView" ux:AutoCtor="false">
    <Router ux:Dependency="router" />
</Panel>

How can I do this? The compiler gives me: MainView.g.uno(36.24): E2009: Call to ‘MyView()’ has some invalid arguments (Fuse.Navigation.Router)

ux:Dependency translates into a constructor argument. So you need for your custom constructor to take a Fuse.Navigation.Router as an argument.

How do I call this router in JS? router is null in my JS. Do I need to do something more in my .uno class then just add (Fuse.Navigation.Router router) to my constructor?

Hi,

You can not combine ux:Dependency with ux:AutoCtor="false" in the same class, unfortunately. To do this, you have to split your class in two layers. In the base class, introduce the dependency. In the derived class, do ux:AutoCtor="false" and then pass a non-null router to the base constructor.

> **Anders Lassen wrote:** > >

Hi,

You can not combine ux:Dependency with ux:AutoCtor="false" in the same class, unfortunately. To do this, you have to split your class in two layers. In the base class, introduce the dependency. In the derived class, do ux:AutoCtor="false" and then pass a non-null router to the base constructor.

> Hi Anders, Can you post an example please or help me with the code below (not working with error = “‘SplashPage’ does not have a property called ‘router’.”): Base class: Derived class .ux: Derived class .uno: using Uno; using Uno.Collections; using Uno.Permissions; using Fuse; public partial class SplashPage { public SplashPage(Fuse.Navigation.Router router) { debug\_log("App init!"); var permissionPromise = Permissions.Request(Permissions.Android.CAMERA); permissionPromise.Then(OnPermitted, OnRejected); } void OnPermitted(PlatformPermission permission) { debug\_log "Woo, we can take the picture now"; InitializeUX(); } void OnRejected(Exception e) { debug_log "Damn: " + e.Message; } } MainView.ux: Thanks for your help !

Hi!

ux:Dependency corresponds to a constructor argument, so you have to this:

 [UXConstructor] 
 public SplashPage([UXParameter("router")] Fuse.Navigation.Router router): base(router) {

Remember using Uno.UX; in the top of your file.

Hi Anders, and thanks for your answer!
I made the changes but still getting “SplashPage.uno(10.12): E3003: ‘__baseClass12’ does not have a constructor that matches this argument list”.
Also getting "MainView.ux(9): E8001: ‘SplashPage’ does not have a property called ‘router’. " if I remove the ux:Dependency=“router” in SplashPage.ux.

The updated files look as follows:

SplashPage.uno

using Uno;
using Uno.UX;
using Uno.Collections;
using Uno.Permissions;
using Fuse;

public partial class SplashPage => should I add :SplashPageRouter ?
{
    [UXConstructor]
    public SplashPage([UXParameter("router")] Fuse.Navigation.Router router): base(router) {
      var permissionPromise = Permissions.Request(Permissions.Android.CAMERA);
      permissionPromise.Then(OnPermitted, OnRejected);
    }
    void OnPermitted(PlatformPermission permission){ InitializeUX(); }
...

SplashPage.ux:

<SplashPageRouter ux:Class="SplashPage" ux:AutoCtor="false" router="router":(tried with and without router="router")>
...

SplashPageRouter.ux:

<Page ux:Class="SplashPageRouter" >
    <Router ux:Dependency="router" />
</Page>

MainView.ux:

<App >
	<Router ux:Name="router" />
	<ClientPanel>

		<Android.StatusBarConfig IsVisible="false" />
	  <iOS.StatusBarConfig Style="Light" IsVisible="false" />

		<Navigator DefaultTemplate="splash">
			<SplashPage ux:Template="splash" router="router" />
			<HomePage ux:Template="home" router="router" />
		</Navigator>
	</ClientPanel>
</App>

Its very confusing to try to understand this. Please upload a complete test project.

Actually this issue comes from the following:

MainView.ux contains a Navigator with two pages. The status bar is set to hidden.
MainView.uno requests access to the Camera.

the app launches, the default page is set, but the camera permission dialog is not visible.
Only when the user navigates to the second page, then the camera permission dialog appears.
the user grants permission and the second page is displayed.

Ok so far (still I would expect the permission to appear from the beginning). But the issue is that when the second page is displayed, the status bar becomes visible + a white rectangle at the bottom of the page appears.

marcmelo8@gmail.com wrote:

Actually this issue comes from the following:

MainView.ux contains a Navigator with two pages. The status bar is set to hidden.
MainView.uno requests access to the Camera.

the app launches, the default page is set, but the camera permission dialog is not visible.
Only when the user navigates to the second page, then the camera permission dialog appears.
the user grants permission and the second page is displayed.

Ok so far (still I would expect the permission to appear from the beginning). But the issue is that when the second page is displayed, the status bar becomes visible + a white rectangle at the bottom of the page appears.

Which I just solved replacing ClientPanel by Panel in the second Page…