Reputation: 53
I am trying to build a google add on for drive, and I want the displayed card to refresh and show different data depending on the value of a switch.
I am setting a setOnChangeAction to the switch with an action calling a function which updates the navigation with the same card. The card then calls the value of the switch in order to know what to display.
However, the problem is that it seems there is a latency when I change the switch and when the card is refreshed, so I can change the switch several time before the card is updated. This is a problem for me because I cannot control the values set by the user before he does other actions, and it is also quite disturbing when using the add on as the screen changes several seconds after the action is done.
function buildCard(switchValue) {
var switchChangeAction = CardService.newAction()
.setFunctionName("onSwitchChange")
.setParameters({switchValue: switchValue});
var switch = CardService.newSwitch()
.setFieldName("switch")
.setSelected(switchValue)
.setValue("true")
.setOnChangeAction(switchChangeAction);
var switchDecoratedText = CardService.newDecoratedText()
.setText("Show things")
.setSwitchControl(switch);
var section = CardService.newCardSection().addWidget(switchDecoratedText);
if (switchValue) {
// Show things
}
return CardService.newCardBuilder().addSection(section).build();
}
function onSwitchChange(e) {
var switchValue = (e.formInput.switch === "true");
var card = buildCard(switchValue);
var nav = CardService.newNavigation().updateCard(card);
return CardService.newActionResponseBuilder().setNavigation(nav).build();
}
Am I doing something wrong with my code which might cause this latency, or is it a normal behavior of this onChange listener and I cannot do anything about it ?
No matter what I do with the switch, I get this latency.
I can replace the switch with a button and a setOnClickAction Listener, which works with a latency also, BUT, the card goes grey and a loader appear, preventing any other action while the card is built and updated.
I could build a visual element acting like a button but looking like the switch, but it doesn't seem the best way to do it, aspecially as there are already built in switches.
Any idea ?
Thank you
Upvotes: 2
Views: 103