Access MainLayout from view

I create one View with the annotation @Route and the layout propertie from a MainLayout
@Route(value = “/conferencia/matricula/:matricula”, layout = MainLayout.class)

in that view Can I access some method that I create in MainLayout?

I need to when I enter in a specific view I close the drawer, so I need to execute the

setDrawerOpened(
false
);

method from AppLayout

There is findAncestor which can be used for this, but it requires your view to be attached - therefore call it in the after navigation listener. Another option would be to throw an event like described here https://cookbook.vaadin.com/ui-eventbus