Get Page Title in Native Mobile

0
Hi   I am trying to implement a button on a template page which will execute a task based on the Title of the current page.  I read on an old community post about using a JavaScript action within the Nanoflow but I am having issues putting it in place.   I have create a JavaScript Action  which outputs a String   With the following code (based on the old community post I found); When I execute the Nanoflow I get the following error;   An error occurred while executing an action of ProductCatalogue.NativePhone_Product.actionButton2: Can't find variable: document Nanoflow stack: "Call JavaScript Action" in nanoflow "ProductCatalogue.ACT_OpenWebPage"   Is there a better way to get the Title of the page or is there something I need to import into the JS action to make it work?   Thanks Grant
asked
4 answers
0

https://docs.mendix.com/howto/extensibility/create-native-javascript-action/

go through this, it is document to create javascript action for react native

also try 'react-native' instead of 'react-navigation/native'

answered
0

Hi Grant,

Mostly it is correct , but try once

const title=document.title

 

 

answered
0

Hi Grant,

the error you are facing is because it is native app, and it won't run on browser so it doesn't understand document 

 

try this import and code below

import { NavigationContext } from 'react-navigation/native';

import { useContext } from 'react';



const navigation = useContext(NavigationContext);
    
    if (navigation && navigation.getCurrentRoute) {
        const route = navigation.getCurrentRoute();
        if (route && route.name) {
            return route.name;
        }
    }
    
    return 'Unknown Title';

 

answered
0

Hi I have managed to get it working now thanks to a combo of changing it to react/native and rereading the documentation.

 

Thanks

Grant

answered