Around the view.name variable


Mario Steinbacher

Hello David!

Maybe I do have found a bug.

As I described in the title above it seems like that the view.name ist not in the view object when the app is openen via deeplink. view.name always shows me the name of my first view of the app.

So I'm not able to detect where I am and to load other views if necessary or prevent to navigate to the same view.

Or maybe it's easier to be able to navigate to the same view, something like a reload.

I use this plugin: cordova-plugin-deeplinks

best regards


decsoft

Hello Mario,

I never use such plugin, but I will try to help you. Can I ask where you are trying to use "view.name"? In what event?



Mario Steinbacher
Hello David! in the DeviceRady event, ahhh maybe i need to change it to the DomReady event?!
edit: I do have tried it. but the event (universalLinks) needs to be subscribed on DeviceReady

decsoft

Hello Mario,

A couple of things to comment here. First of all, I can see some weird (unexpected) behaviour with the "DomReady" event, but only in Firefox... if we try to access the "view.name" variable from the "DomReady", we can't... but again, only in Firefox... which give me in a bad position, because I am not quite sure how to achieve a possible fix.

But you tell me that you are using the "DeviceReady" event... so we are not talking about the "DomReady" event... however... maybe what I want to suggest you can work. What I suggest to you is to use a "setTimeout", that is, use a code similar than the below one:

Note that I place an "alert"... but only means that we use the view.name variable... so in one word... try the "setTimeout" when you access to "view.name", Mario, and please, tell me if that works or not.



Mario Steinbacher
Hello David,
It seems not to work. (I tried it with less and more time to wait 250 or 1000)

maybe is the reason because the App (mobile App Android) is running and it is resuming?

decsoft

Hello Mario,

It's quite rare... and maybe specifically related with the plugin that you are using... I mean... I try with a sample app which show (in an alert) the "view.name" variable at the "DeviceReady" event... and certainly works as expected...

Of course, when I launch this app... the view which is loaded is the main one, so for that reason I can get "view1" inside "view.name"... but this is the expected... because certainly the main view is "view1"... and that's the view which is loaded when the app starts.

So maybe all of these is related with the plugin that you are using... so please... let me to figure out how that plugin works... in order to make some tests from my own...



decsoft

Hello Mario,

On the other hand... and this may can help or give us some clue... if I am not wrong, the "DeviceReady" is only executed one time, when the app starts, and the Apache Cordova stuff is ready to be used (this include the Cordova plugins too). But... if the app get paused... and then resumed... probably the "DeviceReady" is not executed again... we have the "Pause" and "Resume" events to be ready in that scenario.

So I am not completely sure about... what I can say is that the "DeviceReady" is only executed one time... when the app is launched for the first time... or if we close the app and then start it again from the scratch... but not if we put the app in pause... then, when the app become resumed, the event which is fired is the "Resume" event, not the "DeviceReady". Maybe this can help you in some way.



decsoft

Hello Mario,

I want to comment here something more about the "DeviceReady", because it's something that get me a bit confused. You say that you use the "DeviceReady" event, but, as I comment in my previous post in this thread, that event is only firef one time, when the app starts. But, if the app starts... certainly we are in the main view... and this is what you describes: I get always the main view name in "view.name"... but this did not mean the "view.name" variable is not set! What this means is exactly that the "view.name" variable stores... well.. the main view name... because you are certainly in the main view!

So here is something that I can't understand perfectly well... there is something that I am missing... because I can't understand it... Again, and tro try to explain it as well as possible: you mention that you always get the "main view name" in the "view.name" variable... but you refer also that you are dealing with that variable in the "DeviceReady" event... but since that event is fired when the app is started... what you get is the expected view name... because it's the main view...

Can you understand what I am trying to explain? I hope so! Because there is something that we are missunderstanding... maybe we need to use another event... or something like that... because what you are getting: "Always the main view name" is what we can expect to get if we are using the "DeviceReady" event...

On the other hand, the Cordova plugin that you are using is a bit hard to implement... I mean... it's the first time I know about it... and apparently requires some configuration in the server side... so I want to ask you if you can prepare for me a sample app who uses that plugin... with the right configuration in certain server (or leave the configuration ready to place from my own here at decsoftutils.com)... so I can try to take a look at that sample app... It's possible to made that sample app for me, Mario?

But please, consider all what I am trying to explain here in this post... about the "DeviceReady" event... the expected result if we use in that event the "view.name" variable, etc. Maybe what you need is to use another event or something like that... I can't be sure at this moment. On the other hand... may you can also consider to use something like "document.location.href"... since with that maybe you can know also (in your case) what view is show in the app at that moment.



decsoft

Hello Mario,

I continue thinking about your problem, and, I want to suggest you something to do, in order to see if everything is working as expected. First of all, if I am not wrong, you use the "DeviceReady" event, because you need to wait until the Cordova stuff (including the plugin you are using) are ready.

Again, if I am not wrong, the plugin that you use will open the app specifiying an app's view in particular, for that reason you want to know what app's view has been "loaded" on the "DeviceReady" event. My theory is that, for some reason, the plugin is always open the app from the main view.

I assume that the "view.name" variable is correct, so, if you are in the main view, the variable will show to you the main view name. In order to try all of these, I suggest to you to use the below code in the "DeviceReady" event:

With the above code you must see (in the alert) the below if you are in the main view of the app:

If you are in another view, the above alert will show you something like the below:

The idea is to check if certainly the plugin is loading the appropriate view, or, if as I think, the plugin is always loading the main view of the app. If I am not wrong, if the plugin is loading the "view2" correctly, then inside the "DeviceReady" you will see the expected value in "view.name", but also in "document.location.href".

So please, go ahead with this test and post here what you can see.

P.S. Maybe the plugin can launch / open your app while the app has been paused before: in this case the event that you must use is the "Resume" event, not the "DeviceReady", since this last one is only fired one time, when your app starts from scratch.



Mario Steinbacher

Hello David!

Thank you for your detailed explanations.

You were right: the plugin always opens with the main view. The reason for this I THINK is that the function thats been executed is that this function is a callback in the DeviceReady Event and therefore this callback function is in this DeviceReady Event Scope and so the view.name has to be the first view of the app.

So my solution was to just set Variables in this function and dertermine in the Resume Event which View is shown.

But also used document.location.href in the DeviceReady Event for the state when the app starts new.

best regards

Mario


decsoft

Hello Mario,

If you finally can handle it, I am happy for that. :-)


Everybody can read the DecSoft support forum for learning purposes, however only DecSoft customers can post new threads. Purchase one or more licenses of some DecSoft products in order to give this and other benefits.

This website uses some useful cookies to store your preferences.

I agree. Hide this note. Give me more information.