1
I have a check box which by default is marked as true
(marked), but, I want to dynamically save an option when the user changes this box to false
(or, cancel). As I will not have bank interaction yet, I searched about and decided to do it with Asyncstorage. However, I was unsuccessful after seeing some examples. My code starts with:
state = {
bt_contact: true
}
storeCheckBoxStatus = async () => {
try {
await AsyncStorage.setItem('@storage_Key', this.state.bt_contact)
console.info(AsyncStorage)
} catch (e) {
console.info(e);
}
}
getCheckBoxStatus = async () => {
try {
const value = await AsyncStorage.getItem('@storage_Key')
console.info(AsyncStorage)
console.info(value)
if (!value != null) {
this.setState.bt_contact({bt_contact: (value).bt_contact})
}
} catch (e) {
console.info(e);
}
}
checkBoxTest() {
this.setState({
bt_contact: !this.state.bt_contact
})
if (!this.state.bt_contact != true) {
Alert.alert(
I18n.t('Confirm_cancel_data_sharing'),
I18n.t('Message_alert_data_sharing'),
[
{
text: I18n.t('Cancel'),
onPress: () => this.setState({
bt_contact: true
})
},
{
text: 'OK',
onPress: () => this.storeCheckBoxStatus
},
],
{ cancelable: false }
)
}
}
The first function should read the user record when unchecking the box or not. The second is to render with the value changed for the last time or come as marked by default. And the latter is only interaction with Alert
. That when he cancels, he reschedules and when the ok, will give sequence to be able to save in Torage.
I need you to be safe in Asyncstorage and that I can access, so if you need to send to the bank in the future, you can consult. But from the beginning, I would just like that once you close the phone, you can leave the last option saved. If you clear, reopen unchecked. Anyone can help?
Chunk that rescan the checkbox:
<Text style={[styles.bottomContainerText, { color: themes[theme].auxiliaryText }]}>
<CheckBox style={{
height: 10,
widht: 10,
}}
value={this.state.bt_contact}
onValueChange={() => this.checkBoxTest()}
/>
{I18n.t('Data_sharing')}
</Text>
A tip: put more details on the questions.
– K4L1