Add slider and save value in LocalStorage

This commit is contained in:
Julia Friesel
2018-08-21 14:26:54 +02:00
parent 7a1ef388d3
commit c6b490b2a4
6 changed files with 116 additions and 14 deletions
+59 -3
View File
@@ -3,21 +3,28 @@ import {
View,
Button,
ScrollView,
Alert
Alert,
Text
} from 'react-native'
import Slider from '@ptomasroos/react-native-multi-slider'
import Share from 'react-native-share'
import { DocumentPicker, DocumentPickerUtil } from 'react-native-document-picker'
import rnfs from 'react-native-fs'
import styles from '../styles/index'
import config from '../config'
import { settings as labels } from './labels'
import getDataAsCsvDataUri from '../lib/import-export/export-to-csv'
import importCsv from '../lib/import-export/import-from-csv'
import { getTempScale, saveTempScale } from '../local-storage'
export default class Settings extends Component {
render() {
return (
<ScrollView>
<View style={styles.settingsSegment}>
<Text>{labels.tempScale.segmentTitle}</Text>
<TempSlider/>
</View>
<View style={styles.homeButtons}>
<View style={styles.homeButton}>
<Button
@@ -37,6 +44,55 @@ export default class Settings extends Component {
}
}
class TempSlider extends Component {
constructor(props) {
super(props)
this.state = {
min: config.temperatureScale.low,
max: config.temperatureScale.high
}
this.getStoredScale()
}
async getStoredScale() {
const storedScale = await getTempScale()
if (!storedScale) return
this.setState(storedScale)
}
onValuesChange = (values) => {
this.setState({
min: values[0],
max: values[1]
})
}
onValuesChangeFinish = (values) => {
this.setState({
min: values[0],
max: values[1]
})
saveTempScale(this.state)
}
render() {
return (
<View>
<Text>{`${labels.tempScale.min} ${this.state.min}`}</Text>
<Text>{`${labels.tempScale.max} ${this.state.max}`}</Text>
<Slider
values={[this.state.min, this.state.max]}
min={config.temperatureScale.min}
max={config.temperatureScale.max}
step={0.5}
onValuesChange={this.onValuesChange}
onValuesChangeFinish={this.onValuesChangeFinish}
/>
</View>
)
}
}
async function openShareDialogAndExport() {
let data
try {
@@ -117,4 +173,4 @@ function alertError(msg) {
function importError(msg) {
const postFixed = `${msg}\n\n${labels.import.errors.postFix}`
alertError(postFixed)
}
}