Skip to content

Commit

Permalink
Persist app state
Browse files Browse the repository at this point in the history
  • Loading branch information
dsernst committed Jan 14, 2020
1 parent 6bdecf2 commit 3940483
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 5 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ module.exports = {
'typescript-sort-keys/string-enum': 2,
'react-native/no-inline-styles': ['off'],
'sort-destructure-keys/sort-destructure-keys': 2,
'prefer-const': 2,
},
}
2 changes: 1 addition & 1 deletion App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const screens: { [screen in ScreenNames]: any } = {
InitScreen,
}

let timeouts: ReturnType<typeof setTimeout>[] = []
const timeouts: ReturnType<typeof setTimeout>[] = []

interface Props extends State {
setState: (payload: object) => void
Expand Down
1 change: 1 addition & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ android {
}

dependencies {
implementation project(':@react-native-community_async-storage')
implementation project(':react-native-vector-icons')
implementation project(':react-native-keep-awake')
implementation project(':react-native-sound')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.corbt.keepawake.KCKeepAwakePackage;
import com.zmxv.RNSound.RNSoundPackage;
Expand Down
2 changes: 2 additions & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
rootProject.name = 'GoenkaNative'
include ':@react-native-community_async-storage'
project(':@react-native-community_async-storage').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/async-storage/android')
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
include ':react-native-keep-awake'
Expand Down
31 changes: 29 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,39 @@ import { name as appName } from './app.json'
import { Provider } from 'react-redux'
import { createStore } from 'redux'
import reducer from './reducer'
import { createTransform, persistReducer, persistStore } from 'redux-persist'
import AsyncStorage from '@react-native-community/async-storage'
import { PersistGate } from 'redux-persist/integration/react'

const store = createStore(reducer)
const store = createStore(
persistReducer(
{
key: 'root',
storage: AsyncStorage,

// Transform dates back into JS Dates on rehydrate
// (see: https://github.com/rt2zz/redux-persist/issues/82)
transforms: [
createTransform(JSON.stringify, toRehydrate =>
JSON.parse(toRehydrate, (key, value) =>
typeof value === 'string' && value.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/)
? new Date(value)
: value,
),
),
],

whitelist: ['history', 'duration', 'hasChanting', 'hasExtendedMetta'],
},
reducer,
),
)

const Reduxed = () => (
<Provider store={store}>
<App />
<PersistGate persistor={persistStore(store)}>
<App />
</PersistGate>
</Provider>
)

Expand Down
2 changes: 2 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ target 'GoenkaNative' do

pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'

pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'

target 'GoenkaNativeTests' do
inherit! :search_paths
# Pods for testing
Expand Down
8 changes: 7 additions & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ PODS:
- React-cxxreact (= 0.61.5)
- React-jsi (= 0.61.5)
- ReactCommon/jscallinvoker (= 0.61.5)
- RNCAsyncStorage (1.7.1):
- React
- RNSound (0.11.0):
- React
- RNSound/Core (= 0.11.0)
Expand Down Expand Up @@ -257,6 +259,7 @@ DEPENDENCIES:
- React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`)
- ReactCommon/jscallinvoker (from `../node_modules/react-native/ReactCommon`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- "RNCAsyncStorage (from `../node_modules/@react-native-community/async-storage`)"
- RNSound (from `../node_modules/react-native-sound`)
- RNVectorIcons (from `../node_modules/react-native-vector-icons`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
Expand Down Expand Up @@ -316,6 +319,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/Libraries/Vibration"
ReactCommon:
:path: "../node_modules/react-native/ReactCommon"
RNCAsyncStorage:
:path: "../node_modules/@react-native-community/async-storage"
RNSound:
:path: "../node_modules/react-native-sound"
RNVectorIcons:
Expand Down Expand Up @@ -350,10 +355,11 @@ SPEC CHECKSUMS:
React-RCTText: 9ccc88273e9a3aacff5094d2175a605efa854dbe
React-RCTVibration: a49a1f42bf8f5acf1c3e297097517c6b3af377ad
ReactCommon: 198c7c8d3591f975e5431bec1b0b3b581aa1c5dd
RNCAsyncStorage: 44395cb9c7c1523104c2b499eb426ef7aff82bca
RNSound: da030221e6ac7e8290c6b43f2b5f2133a8e225b0
RNVectorIcons: 0bb4def82230be1333ddaeee9fcba45f0b288ed4
Yoga: f2a7cd4280bfe2cca5a7aed98ba0eb3d1310f18b

PODFILE CHECKSUM: 3050d9d049b26f82de939b1a88132dac72828f1f
PODFILE CHECKSUM: 3211cb7bc9fc907d211f8d4a90c97e14e74d5c26

COCOAPODS: 1.8.4
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},
"dependencies": {
"@react-native-community/async-storage": "^1.7.1",
"@types/react-redux": "^7.1.5",
"dayjs": "^1.8.19",
"lodash": "^4.17.15",
Expand All @@ -19,7 +20,8 @@
"react-native-sound": "^0.11.0",
"react-native-vector-icons": "^6.6.0",
"react-redux": "^7.1.3",
"redux": "^4.0.5"
"redux": "^4.0.5",
"redux-persist": "^6.0.0"
},
"devDependencies": {
"@babel/core": "^7.6.2",
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,11 @@
"@types/istanbul-reports" "^1.1.1"
"@types/yargs" "^13.0.0"

"@react-native-community/async-storage@^1.7.1":
version "1.7.1"
resolved "https://registry.yarnpkg.com/@react-native-community/async-storage/-/async-storage-1.7.1.tgz#ef2104d865de61ad91bba66613e57e689ff4e6a1"
integrity sha512-/oX/x+EU4xNaqIaC/epVKzO8XghzImPA7l8cLz3USEFmtFiXFjBbTeeIFjjEm/u4/cv38Wi1xMEa10PHIWygRg==

"@react-native-community/cli-debugger-ui@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-debugger-ui/-/cli-debugger-ui-3.0.0.tgz#d01d08d1e5ddc1633d82c7d84d48fff07bd39416"
Expand Down Expand Up @@ -5383,6 +5388,11 @@ realpath-native@^1.1.0:
dependencies:
util.promisify "^1.0.0"

redux-persist@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/redux-persist/-/redux-persist-6.0.0.tgz#b4d2972f9859597c130d40d4b146fecdab51b3a8"
integrity sha512-71LLMbUq2r02ng2We9S215LtPu3fY0KgaGE0k8WRgl6RkqxtGfl7HUozz1Dftwsb0D/5mZ8dwAaPbtnzfvbEwQ==

redux@^4.0.0, redux@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f"
Expand Down

0 comments on commit 3940483

Please sign in to comment.