add react-native-mmkv-storage

This commit is contained in:
ammarahm-ed
2020-03-10 13:36:33 +05:00
parent 4057d9bf19
commit f72295e39a
8 changed files with 33 additions and 33 deletions

View File

@@ -37,7 +37,7 @@ import {w} from './src/utils/utils';
import Editor from './src/views/Editor'; import Editor from './src/views/Editor';
import Animated, {Easing} from 'react-native-reanimated'; import Animated, {Easing} from 'react-native-reanimated';
import {useForceUpdate} from './src/views/ListsEditor'; import {useForceUpdate} from './src/views/ListsEditor';
import FastStorage from 'react-native-fast-storage'; import MMKV from 'react-native-mmkv-storage';
import {defaultState} from './src/provider/defaultState'; import {defaultState} from './src/provider/defaultState';
import {EditorPosition} from './src/utils/animations'; import {EditorPosition} from './src/utils/animations';
export const DDS = new DeviceDetectionService(); export const DDS = new DeviceDetectionService();
@@ -167,12 +167,12 @@ const App = () => {
async function updateAppTheme(colors = colors) { async function updateAppTheme(colors = colors) {
let newColors = await getColorScheme(colors); let newColors = await getColorScheme(colors);
let s = await FastStorage.getString('settings'); let s = await MMKV.getString('settings');
if (typeof s !== 'string') { if (typeof s !== 'string') {
s = defaultState.settings; s = defaultState.settings;
s = JSON.stringify(s); s = JSON.stringify(s);
await FastStorage.setString('settings', s); await MMKV.setString('settings', s);
dispatch({type: ACTIONS.SETTINGS, s}); dispatch({type: ACTIONS.SETTINGS, s});
} else { } else {
s = JSON.parse(s); s = JSON.parse(s);

View File

@@ -1,5 +1,5 @@
import {Dimensions, PixelRatio, StatusBar, Platform} from 'react-native'; import {Dimensions, PixelRatio, StatusBar, Platform} from 'react-native';
import FastStorage from 'react-native-fast-storage'; import MMKV from 'react-native-mmkv-storage';
import { import {
eSendEvent, eSendEvent,
eSubscribeEvent, eSubscribeEvent,
@@ -187,18 +187,18 @@ export function setColorScheme(colors = COLOR_SCHEME, accent = ACCENT) {
} }
export async function getColorScheme() { export async function getColorScheme() {
let accentColor = await FastStorage.getString('accentColor'); let accentColor = await MMKV.getString('accentColor');
let t = await FastStorage.getString('theme'); let t = await MMKV.getString('theme');
if (typeof accentColor !== 'string') { if (typeof accentColor !== 'string') {
FastStorage.setString('accentColor', '#0560FF'); MMKV.setString('accentColor', '#0560FF');
setAccentColor('#0560FF'); setAccentColor('#0560FF');
} else { } else {
setAccentColor(accentColor); setAccentColor(accentColor);
} }
if (typeof t !== 'string') { if (typeof t !== 'string') {
FastStorage.setString('theme', JSON.stringify({night: false})); MMKV.setString('theme', JSON.stringify({night: false}));
setColorScheme(COLOR_SCHEME_LIGHT); setColorScheme(COLOR_SCHEME_LIGHT);
} else { } else {
let themeToSet = JSON.parse(t); let themeToSet = JSON.parse(t);

View File

@@ -9,7 +9,7 @@ import {
Platform, Platform,
ToastAndroid, ToastAndroid,
} from 'react-native'; } from 'react-native';
import FastStorage from 'react-native-fast-storage'; import MMKV from 'react-native-mmkv-storage';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {db, DDS} from '../../../App'; import {db, DDS} from '../../../App';
import { import {
@@ -283,10 +283,10 @@ export const ActionSheetComponent = ({
icon: 'theme-light-dark', icon: 'theme-light-dark',
func: () => { func: () => {
if (!colors.night) { if (!colors.night) {
FastStorage.setString('theme', JSON.stringify({night: true})); MMKV.setString('theme', JSON.stringify({night: true}));
changeColorScheme(COLOR_SCHEME_DARK); changeColorScheme(COLOR_SCHEME_DARK);
} else { } else {
FastStorage.setString('theme', JSON.stringify({night: false})); MMKV.setString('theme', JSON.stringify({night: false}));
changeColorScheme(COLOR_SCHEME_LIGHT); changeColorScheme(COLOR_SCHEME_LIGHT);
} }
}, },

View File

@@ -9,7 +9,7 @@ import {
TouchableOpacity, TouchableOpacity,
View, View,
} from 'react-native'; } from 'react-native';
import FastStorage from 'react-native-fast-storage'; import MMKV from 'react-native-mmkv-storage';
import {TextInput} from 'react-native-gesture-handler'; import {TextInput} from 'react-native-gesture-handler';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { import {
@@ -326,13 +326,13 @@ export const EditorMenu = ({updateProps = () => {}, timestamp}) => {
icon: 'moon', icon: 'moon',
func: () => { func: () => {
if (!colors.night) { if (!colors.night) {
FastStorage.setString( MMKV.setString(
'theme', 'theme',
JSON.stringify(COLOR_SCHEME_DARK), JSON.stringify(COLOR_SCHEME_DARK),
); );
changeColorScheme(COLOR_SCHEME_DARK); changeColorScheme(COLOR_SCHEME_DARK);
} else { } else {
FastStorage.setString( MMKV.setString(
'theme', 'theme',
JSON.stringify(COLOR_SCHEME_LIGHT), JSON.stringify(COLOR_SCHEME_LIGHT),
); );

View File

@@ -8,7 +8,7 @@ import {
TouchableOpacity, TouchableOpacity,
View, View,
} from 'react-native'; } from 'react-native';
import FastStorage from 'react-native-fast-storage'; import MMKV from 'react-native-mmkv-storage';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {DDS, db} from '../../../App'; import {DDS, db} from '../../../App';
import { import {
@@ -96,10 +96,10 @@ export const Menu = ({
icon: 'theme-light-dark', icon: 'theme-light-dark',
func: () => { func: () => {
if (!colors.night) { if (!colors.night) {
FastStorage.setString('theme', JSON.stringify({night: true})); MMKV.setString('theme', JSON.stringify({night: true}));
changeColorScheme(COLOR_SCHEME_DARK); changeColorScheme(COLOR_SCHEME_DARK);
} else { } else {
FastStorage.setString('theme', JSON.stringify({night: false})); MMKV.setString('theme', JSON.stringify({night: false}));
changeColorScheme(COLOR_SCHEME_LIGHT); changeColorScheme(COLOR_SCHEME_LIGHT);
} }

View File

@@ -8,7 +8,7 @@ async function read(key, isArray = false) {
if (isArray) { if (isArray) {
data = await getArray(key); data = await getArray(key);
} else { } else {
data = await FastStorage.getMap(key); data = await MMKV.getMap(key);
} }
return isArray ? data.slice() : data; return isArray ? data.slice() : data;
@@ -18,7 +18,7 @@ async function write(key, data) {
if (data.length !== undefined) { if (data.length !== undefined) {
return await setArray(key, data.slice()); return await setArray(key, data.slice());
} else { } else {
return await FastStorage.setMap(key, data); return await MMKV.setMap(key, data);
} }
} }
@@ -26,17 +26,17 @@ async function readMulti(keys) {
if (keys.length <= 0) { if (keys.length <= 0) {
return []; return [];
} else { } else {
let data = await FastStorage.getMultipleItems(keys.slice()); let data = await MMKV.getMultipleItems(keys.slice());
return !data ? undefined : data; return !data ? undefined : data;
} }
} }
function remove(key) { function remove(key) {
FastStorage.removeItem(key); MMKV.removeItem(key);
} }
function clear() { function clear() {
FastStorage.clearStore(); MMKV.clearStore();
} }
function encrypt(password, data) { function encrypt(password, data) {

View File

@@ -6,7 +6,7 @@ import {
TouchableOpacity, TouchableOpacity,
View, View,
} from 'react-native'; } from 'react-native';
import FastStorage from 'react-native-fast-storage'; import MMKV from 'react-native-mmkv-storage';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { import {
ACCENT, ACCENT,
@@ -99,7 +99,7 @@ const AppearanceSettings = ({navigation}) => {
onPress={() => { onPress={() => {
changeAccentColor(item); changeAccentColor(item);
FastStorage.setString('accentColor', item); MMKV.setString('accentColor', item);
}} }}
style={{ style={{
flexDirection: 'row', flexDirection: 'row',
@@ -127,10 +127,10 @@ const AppearanceSettings = ({navigation}) => {
<TouchableOpacity <TouchableOpacity
onPress={() => { onPress={() => {
if (!colors.night) { if (!colors.night) {
FastStorage.setString('theme', JSON.stringify({night: true})); MMKV.setString('theme', JSON.stringify({night: true}));
changeColorScheme(COLOR_SCHEME_DARK); changeColorScheme(COLOR_SCHEME_DARK);
} else { } else {
FastStorage.setString('theme', JSON.stringify({night: false})); MMKV.setString('theme', JSON.stringify({night: false}));
changeColorScheme(COLOR_SCHEME_LIGHT); changeColorScheme(COLOR_SCHEME_LIGHT);
} }
@@ -165,10 +165,10 @@ const AppearanceSettings = ({navigation}) => {
<TouchableOpacity <TouchableOpacity
onPress={() => { onPress={() => {
if (!colors.night) { if (!colors.night) {
FastStorage.setString('theme', JSON.stringify({night: true})); MMKV.setString('theme', JSON.stringify({night: true}));
changeColorScheme(COLOR_SCHEME_DARK); changeColorScheme(COLOR_SCHEME_DARK);
} else { } else {
FastStorage.setString('theme', JSON.stringify({night: false})); MMKV.setString('theme', JSON.stringify({night: false}));
changeColorScheme(COLOR_SCHEME_LIGHT); changeColorScheme(COLOR_SCHEME_LIGHT);
} }

View File

@@ -23,7 +23,7 @@ import Container from '../../components/Container';
import {useTracked} from '../../provider'; import {useTracked} from '../../provider';
import {w, hexToRGBA, getElevation} from '../../utils/utils'; import {w, hexToRGBA, getElevation} from '../../utils/utils';
import {ACTIONS} from '../../provider/actions'; import {ACTIONS} from '../../provider/actions';
import FastStorage from 'react-native-fast-storage'; import MMKV from 'react-native-mmkv-storage';
import {DDS} from '../../../App'; import {DDS} from '../../../App';
import {updateEvent} from '../../components/DialogManager'; import {updateEvent} from '../../components/DialogManager';
import {eSendEvent} from '../../services/eventManager'; import {eSendEvent} from '../../services/eventManager';
@@ -33,7 +33,7 @@ import NavigationService from '../../services/NavigationService';
export async function setSetting(settings, name, value) { export async function setSetting(settings, name, value) {
let s = {...settings}; let s = {...settings};
s[name] = value; s[name] = value;
await FastStorage.setString('settings', JSON.stringify(s)); await MMKV.setString('settings', JSON.stringify(s));
updateEvent({type: ACTIONS.SETTINGS, settings: s}); updateEvent({type: ACTIONS.SETTINGS, settings: s});
} }
@@ -319,7 +319,7 @@ export const Settings = ({navigation}) => {
onPress={() => { onPress={() => {
changeAccentColor(item); changeAccentColor(item);
FastStorage.setString('accentColor', item); MMKV.setString('accentColor', item);
}} }}
style={{ style={{
flexDirection: 'row', flexDirection: 'row',
@@ -347,10 +347,10 @@ export const Settings = ({navigation}) => {
<TouchableOpacity <TouchableOpacity
onPress={() => { onPress={() => {
if (!colors.night) { if (!colors.night) {
FastStorage.setString('theme', JSON.stringify({night: true})); MMKV.setString('theme', JSON.stringify({night: true}));
changeColorScheme(COLOR_SCHEME_DARK); changeColorScheme(COLOR_SCHEME_DARK);
} else { } else {
FastStorage.setString('theme', JSON.stringify({night: false})); MMKV.setString('theme', JSON.stringify({night: false}));
changeColorScheme(COLOR_SCHEME_LIGHT); changeColorScheme(COLOR_SCHEME_LIGHT);
} }