11-09-2017 08:35 - edited 11-09-2017 08:39
11-09-2017 08:35 - edited 11-09-2017 08:39
Developing a train tracking app and I would like to:
1. Choose a line
2. Display an AdditiveList containing the stops of chosen line
If I was doing it in a normal react component I would so something like this:
state = { chosenLine: '', lines: [ { "name": "line1" }, { "name": "line2" }, ]; stops: { line1: [ { "name": "stop1" }, { "name": "stop2" }, { "name": "stop3" }, ], line2: [ { "name": "stop1" }, { "name": "stop2" }, { "name": "stop3" }, ] } }; render(props) { return ( <Page> <Section title={<Text bold align="center">Train Schedule</Text>}
> <Select settingsKey="lines" options={this.state.lines} onSelection={(selection) => { this.setState({ chosenLine: selection.values[0].name }); }} /> {this.state.chosenLine && this.renderStops(this.state.chosenLine); } </Section> </Page> ); } renderStops(line) { return ( <AdditiveList settingsKey="stops" addAction={ <Select label="Choose a stop" options={this.state.stops[this.state.chosenLine]} /> } /> ); };
I can't seem to figure out a similar method within the Settings API for Ionic. Any tips?
Thanks
11-12-2017 21:56
11-12-2017 21:56
From what I can tell, it doesn't seem to be possible to use the settings UI as any kind of live UI right now. I was trying to pull a list of results over a REST API to show in the settings UI, but it just doesn't update if the data changes.
https://dev.fitbit.com/reference/companion-api/storage/
"Only changes effected by parts of the system other than the companion application itself trigger events on the storage object. This means that calling setItem, removeItem or clear on the storage object does not trigger any event."
It would be nice to be able to make a more reactive user interface within the FitBit app.
05-10-2019 22:25 - edited 05-11-2019 05:08
05-10-2019 22:25 - edited 05-11-2019 05:08
I realise I'm digging up a long dead thread - is this still the case? I have a setting I'd like to change from the watch and while I can receive the event and data, the settings UI doesn't update.
Edit: Got it working, once I enforced JSON.stringify on the incoming data from the App, the setting started updating dynamically. That led me to finding a bug in evaluating whether a setting should be applied, and now I'm golden.
For reference, if you use this pattern to decide whether to apply a setting it may fail if the newValue is false:
if (evt.data.key === "settingName" && evt.data.newValue) { settings.settingName = evt.data.newValue; }
Instead, I now use this (which I'm sure is terrible in many ways):
if (evt.data.key === "settingName" && (null != evt.data.newValue)) { settings.settingName = evt.data.newValue; }
08-26-2020 10:32
08-26-2020 10:32
To revive a dead thread again, could you elaborate on what you did to get the companion UI to update? I receive the message I send from the device, and settingsStorage says that the correct values are gettings stored, but the UI doesn't reflect the changes, and if I close my app and launch it again, I get the old value from the UI, not the one I stored.