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 AnswerYou could do what I suggested before in your initialize() function.
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 AnswerGet 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).
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 Answer