Change variable and save it by AsyncStorage

0

I am developing an APP that contains several texts, so the font size of the texts are imported from a single variable.
I'm trying to add an option to leave the font larger, and save the font size chosen, but, I'm not getting it.

Follow the code that changes and "saves" the variable tamanhoFonte .

import React, { Component} from 'react';
import {
    Text,
    Button,
    AsyncStorage,
    View
} from 'react-native';

//Variável que é exportada para todos os textos
export var tamanhoFonte = 18;

export var corTexto = '#646567';

export var nightMode = false;

export default class Variaveis extends Component {


    _storeData() {      
        AsyncStorage.setItem('tamanhoFonte',tamanhoFonte) 
    }

    _retrieveData() {
       AsyncStorage.getItem('tamanhoFonte')
       this.setState({tamanhoFonte:tamanhoFonte})    

    }

    componentWillMount() {
       this._retrieveData();
    }

    constructor(props) {
        super(props);
        this.state = { tamanhoFonte: tamanhoFonte }
    }

    mudaFonte = () => {
        this.setState({tamanhoFonte: this.state.tamanhoFonte+1})
        this._storeData();
    }

    render() {
        return (
            <View>
                <Text>{this.state.tamanhoFonte} </Text>
                <Button title="Muda fonte" onPress={() => { this.mudaFonte() }} />
            </View>)
    }
}
    
asked by anonymous 13.09.2018 / 01:37

1 answer

0

In the _retrieveData function, the asyncStorage getItem is not assigned to any variable. You have this example: link

    
13.09.2018 / 14:35