Skip to content

Commit d3db732

Browse files
committed
Async storage
1 parent 1669d98 commit d3db732

File tree

5 files changed

+34
-23
lines changed

5 files changed

+34
-23
lines changed

App.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
1919
import {ApplicationProvider, Layout, Text} from '@ui-kitten/components';
2020
import {mapping, light as lightTheme, dark as darkTheme} from '@eva-design/eva';
2121
import {SafeAreaView} from 'react-native';
22+
import AsyncStorage from '@react-native-community/async-storage';
2223

2324
import {K} from './src/store/constants';
2425

@@ -40,12 +41,27 @@ const SettingsPageNest = () => {
4041
);
4142
};
4243

43-
Appearance.addChangeListener(({ colorScheme }) => {
44-
store.dispatch({type: 'SET_THEME_NATIVE', theme: colorScheme})
44+
Appearance.addChangeListener(({colorScheme}) => {
45+
store.dispatch({type: 'SET_THEME_NATIVE', theme: colorScheme});
4546
});
4647

4748
const App = (props: any) => {
49+
// const getSaved = async () => {
50+
// let raw;
51+
// try {
52+
// raw = await AsyncStorage.multiGet(['themeMode']); //add on to the array for more
53+
// } catch (error) {
54+
// console.log(error);
55+
// }
4856

57+
// let retrivedObject = {};
58+
// raw.map(value => {
59+
// retrivedObject[value[0]] = value[1];
60+
// });
61+
// console.log(retrivedObject);
62+
// return retrivedObject;
63+
// };
64+
// console.log(getSaved().retrivedObject);
4965
const themeColor = props.theme === 'dark' ? K.color.dark : K.color.light;
5066
return (
5167
<AppearanceProvider>
@@ -121,7 +137,8 @@ const mapStateToProps = (state: any) => {
121137

122138
const mapDispatchToProps = (dispatch: any) => {
123139
return {
124-
setThemeNative: (theme: string) => dispatch({type: 'SET_THEME_NATIVE', theme: theme}),
140+
setThemeNative: (theme: string) =>
141+
dispatch({type: 'SET_THEME_NATIVE', theme: theme}),
125142
};
126143
};
127144

ios/Podfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ PODS:
221221
- React-cxxreact (= 0.61.5)
222222
- React-jsi (= 0.61.5)
223223
- ReactCommon/jscallinvoker (= 0.61.5)
224+
- RNCAsyncStorage (1.8.1):
225+
- React
224226
- RNCMaskedView (0.1.7):
225227
- React
226228
- RNGestureHandler (1.6.0):
@@ -265,6 +267,7 @@ DEPENDENCIES:
265267
- React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`)
266268
- ReactCommon/jscallinvoker (from `../node_modules/react-native/ReactCommon`)
267269
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
270+
- "RNCAsyncStorage (from `../node_modules/@react-native-community/async-storage`)"
268271
- "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)"
269272
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
270273
- RNReanimated (from `../node_modules/react-native-reanimated`)
@@ -330,6 +333,8 @@ EXTERNAL SOURCES:
330333
:path: "../node_modules/react-native/Libraries/Vibration"
331334
ReactCommon:
332335
:path: "../node_modules/react-native/ReactCommon"
336+
RNCAsyncStorage:
337+
:path: "../node_modules/@react-native-community/async-storage"
333338
RNCMaskedView:
334339
:path: "../node_modules/@react-native-community/masked-view"
335340
RNGestureHandler:
@@ -373,6 +378,7 @@ SPEC CHECKSUMS:
373378
React-RCTText: 9ccc88273e9a3aacff5094d2175a605efa854dbe
374379
React-RCTVibration: a49a1f42bf8f5acf1c3e297097517c6b3af377ad
375380
ReactCommon: 198c7c8d3591f975e5431bec1b0b3b581aa1c5dd
381+
RNCAsyncStorage: 00bdf63f7f1e0f11d3323533dba4f222e58bf092
376382
RNCMaskedView: 90dd32f5b786bd562e876e1421ea77c700cbf71e
377383
RNGestureHandler: dde546180bf24af0b5f737c8ad04b6f3fa51609a
378384
RNReanimated: 031fe8d9ea93c2bd689a40f05320ef9d96f74d7f

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"dependencies": {
1313
"@eva-design/eva": "^1.4.0",
14+
"@react-native-community/async-storage": "^1.8.1",
1415
"@react-native-community/masked-view": "^0.1.7",
1516
"@react-navigation/bottom-tabs": "^5.1.1",
1617
"@react-navigation/native": "^5.0.9",

src/pages/Settings/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const SettingsPageC = (props: any) => {
2626
{
2727
title: 'Privacy',
2828
onPress: () => {
29-
props.toggleSettingsModal(true, ['Privacy', <Text>Hi</Text>]);
29+
props.toggleSettingsModal(true, ['Privacy Notice', <Text style={{color: themeColor.primaryText}}>Privacy</Text>]);
3030
},
3131
},
3232
];
@@ -102,13 +102,13 @@ const SettingsPageC = (props: any) => {
102102
{
103103
title: 'Tell A Friend',
104104
onPress: () => {
105-
props.toggleSettingsModal(true, ['Share', <Text>Hi</Text>]);
105+
props.toggleSettingsModal(true, ['Share', <Text style={{color: themeColor.primaryText}}>Share</Text>]);
106106
},
107107
},
108108
{
109109
title: 'Report A Bug',
110110
onPress: () => {
111-
props.toggleSettingsModal(true, ['Bug Report', <Text>Hi</Text>]);
111+
props.toggleSettingsModal(true, ['Bug Report', <Text style={{color: themeColor.primaryText}}>Report</Text>]);
112112
},
113113
},
114114
];
@@ -162,7 +162,7 @@ const SettingsPageC = (props: any) => {
162162
}
163163
modalTitle={
164164
<ModalTitle
165-
title={props.settingsModalContent?.[0] ?? 'Blank'}
165+
title={props.settingsModalContent?.[0] ?? ''}
166166
style={{
167167
backgroundColor: themeColor.secondaryBG,
168168
borderBottomColor: themeColor.primaryBG,

src/store/reducer.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
11
import React from 'react';
2-
import {Text, AsyncStorage} from 'react-native';
2+
import { Text } from 'react-native';
33
import { Appearance } from 'react-native-appearance';
44

5-
_retrieveData = async () => {
6-
try {
7-
const value = await AsyncStorage.getItem('TASKS');
8-
if (value !== null) {
9-
// We have data!!
10-
console.log(value);
11-
}
12-
} catch (error) {
13-
// Error retrieving data
14-
}
15-
};
16-
175
const initialState = {
186
orientation: 'portrait', //portrait/landscape
19-
theme: 'light', //dark/light
20-
themeMode: 'auto', //need to save in device
7+
themeMode: 'auto',
218
themeNative: Appearance.getColorScheme(), // device's native theme
9+
theme: Appearance.getColorScheme(), //dark/light
2210
settingsModalIsOpen: false,
2311
settingsModalContent: ['Blank', (<Text></Text>)]
2412
}
2513

2614
export const reducer = (state = initialState, action) => {
27-
2815
switch (action.type) {
2916
case 'TOGGLE_THEME':
3017
return {

0 commit comments

Comments
 (0)