-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathFilterSettings.js
83 lines (68 loc) · 1.89 KB
/
FilterSettings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const NativeUI = require('NativeUI');
const FilterSettings = {
slider: NativeUI.slider,
picker: NativeUI.picker,
pickerConfig: {
selectedIndex: 0,
items: []
},
keys: [],
callback: undefined,
current: undefined,
configure(settings, callback) {
this.keys = Object.keys(settings);
this.callback = callback;
this.keys.map((key) => {
settings[key].icon.then((icon) => {
settings[key].icon = icon;
});
});
// Handle settings
this.keys.map(key => {
// Simple error check so we don't
// overwrite anything in our object.
if (this[key]) {
throw `${key} is a reserved value.`;
}
// Add icon to picker.
this.pickerConfig.items.push({
image_texture: settings[key].icon
});
// Set default value or fall back to 0
this[key] = settings[key].default || 0;
});
// Set current being edited to be first of settings
this.current = this.keys[0];
// Set slider value to current setting
this.slider.value = this[this.current];
// Initalise piciker and slider.
this.initUI();
},
initUI() {
// Load config into picker
this.picker.configure(this.pickerConfig);
// Listen to picker events
this.picker.selectedIndex.monitor({ fireOnInitialValue: false }).subscribe(index => {
// Update current setting being edited to the new picked item
this.current = this.keys[index.newValue];
// Update slide value new current setting value
this.slider.value = this[this.current];
});
// Subscribe to slider events
this.slider.value.monitor({ fireOnInitialValue: false }).subscribe(val => {
// Update the value for the current setting beeing edited
this[this.current] = val.newValue;
// Tell that we have made changes.
this.callback({
setting: this.current,
newValue: this[this.current]
})
});
// Make picker and slider visible
this.picker.visible = true;
this.slider.visible = true;
}
};
export {
FilterSettings
};