04-19-2022 11:04
04-19-2022 11:04
Hi all,
I am creating a very cool Clockface where you can choose from settings which stats you want to see and also other stuff like colors of background, gradient and text.
I have an issue with preselecting the toggles, making some of the stats turn on by default. There is nothing about it in the documentation.
This is my code in settings/index.jsx
const activityOptions = [...]. // array elements here
{activityOptions.map(([title, settingsKey]) =>
<Toggle
settingsKey={settingsKey}
label={title}
/>
)}
Any ideas?
Answered! Go to the Best Answer.
Best Answer04-19-2022 14:12
Gold Fitbit Product Experts share support knowledge on the forums and advocate for the betterment of Fitbit products and services. Learn more
04-19-2022 14:12
You could do what I suggested before in your initialize() function.
04-19-2022 12:51
Diamond Fitbit Product Experts share support knowledge on the forums and advocate for the betterment of Fitbit products and services. Learn more
04-19-2022 12:51
Hi @uezbe your post is being moved to the Developer's Forum area. Where you posted is the area where people discuss the apps they have gotten from the Gallery that were already released. I'm sure you'll get more relevant responses once someone sees it in that area.
Best Answer04-19-2022 13:10
Gold Fitbit Product Experts share support knowledge on the forums and advocate for the betterment of Fitbit products and services. Learn more
04-19-2022 13:10
Get your companion code to check whether the settingsStorage item already has a value. If it hasn't, give it whatever value selects the toggle (which you can determine by logging what you get in onSettingsChange).
04-19-2022 14:07 - edited 04-19-2022 14:09
04-19-2022 14:07 - edited 04-19-2022 14:09
Hi @Gondwana,
Here is the implementation of the initialize method I call in the companion/index.js
this is a separate file
import * as messaging from "messaging";
import { settingsStorage } from "settings";
export function initialize() {
settingsStorage.addEventListener("change", evt => {
if (evt.oldValue !== evt.newValue) {
sendValue(evt.key, evt.newValue);
}
});
}
function sendValue(key, val) {
if (val) {
sendSettingData({
key: key,
value: JSON.parse(val)
});
}
}
function sendSettingData(data) {
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
messaging.peerSocket.send(data);
} else {
console.log("No peerSocket connection");
}
}
I'm just initializing it
import * as simpleSettings from "./custom/companion-settings";
mySettings.initialize();
Best Answer04-19-2022 14:12
Gold Fitbit Product Experts share support knowledge on the forums and advocate for the betterment of Fitbit products and services. Learn more
04-19-2022 14:12
You could do what I suggested before in your initialize() function.
04-19-2022 14:15