migrate to latest mmkv storage

This commit is contained in:
ammarahm-ed
2020-09-06 16:10:34 +05:00
parent ee03318301
commit 401e8da666
12 changed files with 78 additions and 42 deletions

View File

@@ -1,5 +1,4 @@
import React, {useEffect, useState} from 'react'; import React, {useEffect, useState} from 'react';
import MMKV from 'react-native-mmkv-storage';
import Orientation from 'react-native-orientation'; import Orientation from 'react-native-orientation';
import {SafeAreaProvider} from 'react-native-safe-area-context'; import {SafeAreaProvider} from 'react-native-safe-area-context';
import {getColorScheme, scale, updateSize} from './src/common/common'; import {getColorScheme, scale, updateSize} from './src/common/common';
@@ -10,6 +9,8 @@ import {eSubscribeEvent, eUnSubscribeEvent} from './src/services/eventManager';
import {eDispatchAction, eStartSyncer, eResetApp} from './src/services/events'; import {eDispatchAction, eStartSyncer, eResetApp} from './src/services/events';
import {db, DDS, ToastEvent} from './src/utils/utils'; import {db, DDS, ToastEvent} from './src/utils/utils';
import {useNetInfo} from '@react-native-community/netinfo'; import {useNetInfo} from '@react-native-community/netinfo';
import RNHTMLtoPDF from 'react-native-html-to-pdf';
import { MMKV } from './src/utils/storage';
const App = () => { const App = () => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();

View File

@@ -1,5 +1,15 @@
{ {
"images" : [ "images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{ {
"idiom" : "iphone", "idiom" : "iphone",
"size" : "29x29", "size" : "29x29",
@@ -29,6 +39,11 @@
"idiom" : "iphone", "idiom" : "iphone",
"size" : "60x60", "size" : "60x60",
"scale" : "3x" "scale" : "3x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
} }
], ],
"info" : { "info" : {

View File

@@ -24,6 +24,8 @@
<string>1</string> <string>1</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>NSAppTransportSecurity</key> <key>NSAppTransportSecurity</key>
<dict> <dict>
<key>NSAllowsArbitraryLoads</key> <key>NSAllowsArbitraryLoads</key>
@@ -39,7 +41,7 @@
</dict> </dict>
<key>NSLocationWhenInUseUsageDescription</key> <key>NSLocationWhenInUseUsageDescription</key>
<string></string> <string></string>
<key>UIAppFonts</key> <key>UIAppFonts</key>
<array> <array>
<string>DMSerifText-Regular.ttf</string> <string>DMSerifText-Regular.ttf</string>
<string>DMSans-Regular.ttf</string> <string>DMSans-Regular.ttf</string>
@@ -52,6 +54,8 @@
<string>Quicksand-Bold.ttf</string> <string>Quicksand-Bold.ttf</string>
<string>Quicksand-Light.ttf</string> <string>Quicksand-Light.ttf</string>
</array> </array>
<key>UIFileSharingEnabled</key>
<true/>
<key>UILaunchStoryboardName</key> <key>UILaunchStoryboardName</key>
<string>LaunchScreen</string> <string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key> <key>UIRequiredDeviceCapabilities</key>
@@ -64,6 +68,8 @@
<string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string> <string>UIInterfaceOrientationLandscapeRight</string>
</array> </array>
<key>UISupportsDocumentBrowser</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key> <key>UIViewControllerBasedStatusBarAppearance</key>
<false/> <false/>
</dict> </dict>

View File

@@ -68,7 +68,9 @@ PODS:
- DoubleConversion - DoubleConversion
- glog - glog
- glog (0.3.5) - glog (0.3.5)
- MMKV (1.0.24) - MMKV (1.2.2):
- MMKVCore (~> 1.2.2)
- MMKVCore (1.2.2)
- OpenSSL-Universal (1.0.2.19): - OpenSSL-Universal (1.0.2.19):
- OpenSSL-Universal/Static (= 1.0.2.19) - OpenSSL-Universal/Static (= 1.0.2.19)
- OpenSSL-Universal/Static (1.0.2.19) - OpenSSL-Universal/Static (1.0.2.19)
@@ -240,8 +242,10 @@ PODS:
- React-jsinspector (0.63.2) - React-jsinspector (0.63.2)
- react-native-get-random-values (1.4.0): - react-native-get-random-values (1.4.0):
- React - React
- react-native-mmkv-storage (0.2.2): - react-native-html-to-pdf (0.8.0):
- MMKV (= 1.0.24) - React
- react-native-mmkv-storage (0.3.7):
- MMKV (= 1.2.2)
- React - React
- react-native-netinfo (5.9.6): - react-native-netinfo (5.9.6):
- React - React
@@ -374,6 +378,7 @@ DEPENDENCIES:
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`) - React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`) - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
- react-native-get-random-values (from `../node_modules/react-native-get-random-values`) - react-native-get-random-values (from `../node_modules/react-native-get-random-values`)
- react-native-html-to-pdf (from `../node_modules/react-native-html-to-pdf`)
- react-native-mmkv-storage (from `../node_modules/react-native-mmkv-storage`) - react-native-mmkv-storage (from `../node_modules/react-native-mmkv-storage`)
- "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)" - "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)"
- react-native-orientation (from `../node_modules/react-native-orientation`) - react-native-orientation (from `../node_modules/react-native-orientation`)
@@ -415,6 +420,7 @@ SPEC REPOS:
- Flipper-RSocket - Flipper-RSocket
- FlipperKit - FlipperKit
- MMKV - MMKV
- MMKVCore
- OpenSSL-Universal - OpenSSL-Universal
- YogaKit - YogaKit
@@ -451,6 +457,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/jsinspector" :path: "../node_modules/react-native/ReactCommon/jsinspector"
react-native-get-random-values: react-native-get-random-values:
:path: "../node_modules/react-native-get-random-values" :path: "../node_modules/react-native-get-random-values"
react-native-html-to-pdf:
:path: "../node_modules/react-native-html-to-pdf"
react-native-mmkv-storage: react-native-mmkv-storage:
:path: "../node_modules/react-native-mmkv-storage" :path: "../node_modules/react-native-mmkv-storage"
react-native-netinfo: react-native-netinfo:
@@ -521,7 +529,8 @@ SPEC CHECKSUMS:
FlipperKit: bc68102cd4952a258a23c9c1b316c7bec1fecf83 FlipperKit: bc68102cd4952a258a23c9c1b316c7bec1fecf83
Folly: b73c3869541e86821df3c387eb0af5f65addfab4 Folly: b73c3869541e86821df3c387eb0af5f65addfab4
glog: 40a13f7840415b9a77023fbcae0f1e6f43192af3 glog: 40a13f7840415b9a77023fbcae0f1e6f43192af3
MMKV: 758b2edee46b08bdd958db4169191afb9a6d4ebd MMKV: b14909757d8b70e2aa89ff1c6d56a7b239e10a29
MMKVCore: 6225324fe5006026bc86ef8641d567e00c6582f3
OpenSSL-Universal: 8b48cc0d10c1b2923617dfe5c178aa9ed2689355 OpenSSL-Universal: 8b48cc0d10c1b2923617dfe5c178aa9ed2689355
RCTRequired: f13f25e7b12f925f1f6a6a8c69d929a03c0129fe RCTRequired: f13f25e7b12f925f1f6a6a8c69d929a03c0129fe
RCTTypeSafety: 44982c5c8e43ff4141eb519a8ddc88059acd1f3a RCTTypeSafety: 44982c5c8e43ff4141eb519a8ddc88059acd1f3a
@@ -534,7 +543,8 @@ SPEC CHECKSUMS:
React-jsiexecutor: 8ca588cc921e70590820ce72b8789b02c67cce38 React-jsiexecutor: 8ca588cc921e70590820ce72b8789b02c67cce38
React-jsinspector: b14e62ebe7a66e9231e9581279909f2fc3db6606 React-jsinspector: b14e62ebe7a66e9231e9581279909f2fc3db6606
react-native-get-random-values: 2b7500cdb68066aba87cdccd97067c29e16ffe95 react-native-get-random-values: 2b7500cdb68066aba87cdccd97067c29e16ffe95
react-native-mmkv-storage: 4f85ac485ff25ad5b9f7b3c6cd4c8bb067b1028c react-native-html-to-pdf: 1d1199917f56a98377d431bce84c2f275e48eb71
react-native-mmkv-storage: 023a9c501f7430319138a94889fc53691b93d73d
react-native-netinfo: 38a1e0b3e89b48e4b5833ed475d8df5f049f6f90 react-native-netinfo: 38a1e0b3e89b48e4b5833ed475d8df5f049f6f90
react-native-orientation: f1caf84d65f1a4fd4511a18f2b924e634ad7a628 react-native-orientation: f1caf84d65f1a4fd4511a18f2b924e634ad7a628
react-native-safe-area-context: eb91fe1fb3f7b87d9c30a7f0808407d8569d539d react-native-safe-area-context: eb91fe1fb3f7b87d9c30a7f0808407d8569d539d

View File

@@ -1,5 +1,4 @@
import { Dimensions, PixelRatio, StatusBar, Platform } from 'react-native'; import { Dimensions, PixelRatio, StatusBar, Platform } from 'react-native';
import MMKV from 'react-native-mmkv-storage';
import { import {
eSendEvent, eSendEvent,
eSubscribeEvent, eSubscribeEvent,
@@ -7,6 +6,7 @@ import {
} from '../services/eventManager'; } from '../services/eventManager';
import { eThemeUpdated } from '../services/events'; import { eThemeUpdated } from '../services/events';
import { DDS } from '../utils/utils'; import { DDS } from '../utils/utils';
import { MMKV } from '../utils/storage';
export const scale = { export const scale = {
fontScale: 1, fontScale: 1,

View File

@@ -8,7 +8,7 @@ import {
View, View,
KeyboardAvoidingView, KeyboardAvoidingView,
} from 'react-native'; } from 'react-native';
import MMKV from 'react-native-mmkv-storage';
import Share from 'react-native-share'; import Share from 'react-native-share';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { import {
@@ -30,6 +30,7 @@ import {timeConverter, ToastEvent, DDS, db} from '../../utils/utils';
import {openVault, eSendEvent} from '../../services/eventManager'; import {openVault, eSendEvent} from '../../services/eventManager';
import {refreshNotesPage, eOpenPremiumDialog} from '../../services/events'; import {refreshNotesPage, eOpenPremiumDialog} from '../../services/events';
import {PremiumTag} from '../Premium/PremiumTag'; import {PremiumTag} from '../Premium/PremiumTag';
import { MMKV } from '../../utils/storage';
const w = Dimensions.get('window').width; const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height; const h = Dimensions.get('window').height;
@@ -286,7 +287,7 @@ export const ActionSheetComponent = ({
icon: 'theme-light-dark', icon: 'theme-light-dark',
func: () => { func: () => {
if (!colors.night) { if (!colors.night) {
MMKV.setStringAsync('theme', JSON.stringify({night: true})); MMKV .setStringAsync('theme', JSON.stringify({night: true}));
changeColorScheme(COLOR_SCHEME_DARK); changeColorScheme(COLOR_SCHEME_DARK);
} else { } else {
MMKV.setStringAsync('theme', JSON.stringify({night: false})); MMKV.setStringAsync('theme', JSON.stringify({night: false}));

View File

@@ -8,7 +8,7 @@ import {
View, View,
} from 'react-native'; } from 'react-native';
import {createAnimatableComponent} from 'react-native-animatable'; import {createAnimatableComponent} from 'react-native-animatable';
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,
@@ -28,6 +28,7 @@ import {ColorSection} from './ColorSection';
import {MenuListItem} from './MenuListItem'; import {MenuListItem} from './MenuListItem';
import {TagsSection} from './TagsSection'; import {TagsSection} from './TagsSection';
import {UserSection} from './UserSection'; import {UserSection} from './UserSection';
import { MMKV } from '../../utils/storage';
const AnimatedSafeAreaView = createAnimatableComponent(SafeAreaView); const AnimatedSafeAreaView = createAnimatableComponent(SafeAreaView);
@@ -85,7 +86,7 @@ export const Menu = ({
icon: 'theme-light-dark', icon: 'theme-light-dark',
func: () => { func: () => {
if (!colors.night) { if (!colors.night) {
MMKV.setStringAsync('theme', JSON.stringify({night: true})); MMKV .setStringAsync('theme', JSON.stringify({night: true}));
changeColorScheme(COLOR_SCHEME_DARK); changeColorScheme(COLOR_SCHEME_DARK);
} else { } else {
MMKV.setStringAsync('theme', JSON.stringify({night: false})); MMKV.setStringAsync('theme', JSON.stringify({night: false}));

View File

@@ -27,11 +27,11 @@ import {moveNoteHideEvent} from '../DialogManager/recievers';
import {HeaderMenu} from './HeaderMenu'; import {HeaderMenu} from './HeaderMenu';
import {HeaderTitle} from './HeaderTitle'; import {HeaderTitle} from './HeaderTitle';
let offsetY = 0; let offsetY = 0;
let timeout = null let timeout = null;
function useForceUpdate() { function useForceUpdate() {
const [, setTick] = useState(0); const [, setTick] = useState(0);
const update = useCallback(() => { const update = useCallback(() => {
setTick(tick => tick + 1); setTick((tick) => tick + 1);
}, []); }, []);
return update; return update;
} }
@@ -53,38 +53,32 @@ export const Header = ({showSearch, root}) => {
const insets = useSafeArea(); const insets = useSafeArea();
const forceUpdate = useForceUpdate(); const forceUpdate = useForceUpdate();
const onScroll = (y) => {
const onScroll = y => {
if (searchResults.results.length > 0) return; if (searchResults.results.length > 0) return;
if (y < 30) { if (y < 30) {
setHideHeader(false); setHideHeader(false);
offsetY = y offsetY = y;
} }
if (y > offsetY) { if (y > offsetY) {
if (y - offsetY < 100) return; if (y - offsetY < 100) return;
clearTimeout(timeout); clearTimeout(timeout);
timeout = null timeout = null;
timeout = setTimeout(() => { timeout = setTimeout(() => {
setHideHeader(true); setHideHeader(true);
},300); }, 300);
offsetY = y offsetY = y;
} else { } else {
if (offsetY - y < 50) return; if (offsetY - y < 50) return;
clearTimeout(timeout); clearTimeout(timeout);
timeout = null timeout = null;
timeout = setTimeout(() => { timeout = setTimeout(() => {
setHideHeader(false); setHideHeader(false);
},300); }, 300);
offsetY = y offsetY = y;
} }
}; };
const _setModalNavigator = (value) => {
const _setModalNavigator = value => {
if (root) return; if (root) return;
forceUpdate(); forceUpdate();
setIsModalNavigator(value); setIsModalNavigator(value);
@@ -118,7 +112,7 @@ export const Header = ({showSearch, root}) => {
alignItems: 'center', alignItems: 'center',
paddingHorizontal: 12, paddingHorizontal: 12,
width: '100%', width: '100%',
backgroundColor:colors.bg backgroundColor: colors.bg,
}}> }}>
<Animatable.View <Animatable.View
transition={['opacity']} transition={['opacity']}
@@ -191,9 +185,7 @@ export const Header = ({showSearch, root}) => {
size={SIZE.xxxl - 3} size={SIZE.xxxl - 3}
/> />
</TouchableOpacity> </TouchableOpacity>
) : ( ) : undefined}
undefined
)}
{headerState.menu && !DDS.isTab ? ( {headerState.menu && !DDS.isTab ? (
<TouchableOpacity <TouchableOpacity
hitSlop={{top: 20, bottom: 20, left: 50, right: 40}} hitSlop={{top: 20, bottom: 20, left: 50, right: 40}}
@@ -208,12 +200,11 @@ export const Header = ({showSearch, root}) => {
}}> }}>
<Icon color={colors.pri} name={'menu'} size={SIZE.xxxl} /> <Icon color={colors.pri} name={'menu'} size={SIZE.xxxl} />
</TouchableOpacity> </TouchableOpacity>
) : ( ) : undefined}
undefined
)}
<HeaderTitle root={root} /> <HeaderTitle root={root} />
</View> </View>
<View <View
style={{ style={{
flexDirection: 'row', flexDirection: 'row',

View File

@@ -1,6 +1,8 @@
import MMKV from 'react-native-mmkv-storage'; import MMKVStorage from 'react-native-mmkv-storage';
import Sodium from 'react-native-sodium'; import Sodium from 'react-native-sodium';
export const MMKV = new MMKVStorage.Loader().initialize();
async function read(key, isArray = false) { async function read(key, isArray = false) {
let data; let data;
if (isArray) { if (isArray) {

View File

@@ -6,8 +6,7 @@ import {
eHideToast, eHideToast,
} from '../services/events'; } from '../services/events';
import { DeviceDetectionService } from './deviceDetection'; import { DeviceDetectionService } from './deviceDetection';
import StorageInterface from './storage'; import StorageInterface, { MMKV } from './storage';
import MMKV from 'react-native-mmkv-storage';
import { updateEvent } from '../components/DialogManager/recievers'; import { updateEvent } from '../components/DialogManager/recievers';
import { ACTIONS } from '../provider/actions'; import { ACTIONS } from '../provider/actions';
export const DDS = new DeviceDetectionService(); export const DDS = new DeviceDetectionService();

View File

@@ -9,7 +9,7 @@ import {eOnLoadNote, eScrollEvent} from '../../services/events';
import {openEditorAnimation} from '../../utils/animations'; import {openEditorAnimation} from '../../utils/animations';
import {DDS} from '../../utils/utils'; import {DDS} from '../../utils/utils';
import {Placeholder} from '../../components/ListPlaceholders'; import {Placeholder} from '../../components/ListPlaceholders';
import RNHTMLtoPDF from 'react-native-html-to-pdf';
export const Home = ({route, navigation}) => { export const Home = ({route, navigation}) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {notes} = state; const {notes} = state;
@@ -54,7 +54,16 @@ export const Home = ({route, navigation}) => {
type: ACTIONS.CONTAINER_BOTTOM_BUTTON, type: ACTIONS.CONTAINER_BOTTOM_BUTTON,
state: { state: {
bottomButtonText: 'Create a new note', bottomButtonText: 'Create a new note',
bottomButtonOnPress: () => { bottomButtonOnPress: async () => {
let res = await RNHTMLtoPDF.convert({
html: '<h1>Custom converted PDF Document</h1>',
fileName: 'test',
base64: false,
directory:"Documents"
});
console.log(res);
return;
if (DDS.isTab) { if (DDS.isTab) {
eSendEvent(eOnLoadNote, {type: 'new'}); eSendEvent(eOnLoadNote, {type: 'new'});
} else { } else {

View File

@@ -2,7 +2,7 @@ import { useIsFocused } from '@react-navigation/native';
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Clipboard, Linking, Modal, Platform, ScrollView, StatusBar, Text, TouchableOpacity, View } from 'react-native'; import { Clipboard, Linking, Modal, Platform, ScrollView, StatusBar, Text, TouchableOpacity, View } from 'react-native';
import * as Animatable from 'react-native-animatable'; import * as Animatable from 'react-native-animatable';
import MMKV from 'react-native-mmkv-storage';
import QRCode from 'react-native-qrcode-generator'; import QRCode from 'react-native-qrcode-generator';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { ACCENT, COLOR_SCHEME, COLOR_SCHEME_DARK, COLOR_SCHEME_LIGHT, opacity, ph, pv, setColorScheme, SIZE, WEIGHT } from '../../common/common'; import { ACCENT, COLOR_SCHEME, COLOR_SCHEME_DARK, COLOR_SCHEME_LIGHT, opacity, ph, pv, setColorScheme, SIZE, WEIGHT } from '../../common/common';
@@ -13,6 +13,7 @@ import { eSendEvent } from '../../services/eventManager';
import { eOpenLoginDialog, eResetApp } from '../../services/events'; import { eOpenLoginDialog, eResetApp } from '../../services/events';
import NavigationService from '../../services/NavigationService'; import NavigationService from '../../services/NavigationService';
import { db, DDS, setSetting, ToastEvent, w } from '../../utils/utils'; import { db, DDS, setSetting, ToastEvent, w } from '../../utils/utils';
import { MMKV } from '../../utils/storage';
export const Settings = ({route, navigation}) => { export const Settings = ({route, navigation}) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();