-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.android.js
44 lines (34 loc) · 1.1 KB
/
index.android.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
import React, { Component } from 'react';
import { AppRegistry, AsyncStorage } from 'react-native';
import AppNavigator from './app/navigators/AppNavigator';
class MinimalHN extends Component {
constructor(props) {
super(props);
this.state = {
// Ads disabled by default
adsEnabled: false
};
this.changeAds = this.changeAds.bind(this);
}
async componentDidMount() {
let adsEnabled = await AsyncStorage.getItem('adsEnabled') || 'false';
adsEnabled = JSON.parse(adsEnabled);
this.setState({ adsEnabled: JSON.parse(adsEnabled) });
await AsyncStorage.setItem('adsEnabled', JSON.stringify(adsEnabled));
}
async changeAds() {
let adsEnabled = await AsyncStorage.getItem('adsEnabled');
adsEnabled = JSON.parse(adsEnabled);
this.setState({ adsEnabled: !adsEnabled });
await AsyncStorage.setItem('adsEnabled', JSON.stringify(!adsEnabled));
}
render() {
return (
<AppNavigator
adsEnabled={this.state.adsEnabled}
changeAds={this.changeAds}
/>
);
}
}
AppRegistry.registerComponent('MinimalHN', () => MinimalHN);