diff --git a/packages/mobile/index.js b/packages/mobile/index.js index 6de3dbacf65..0e27af847e7 100644 --- a/packages/mobile/index.js +++ b/packages/mobile/index.js @@ -1,5 +1,7 @@ +// Order is important, please don't change it unless you know what you're doing :D import 'node-libs-react-native/globals' import 'src/missingGlobals' +import 'src/forceCommunityAsyncStorage' import { AppRegistry } from 'react-native' import Logger from 'src/utils/Logger' import App from 'src/app/App' diff --git a/packages/mobile/src/apollo/index.ts b/packages/mobile/src/apollo/index.ts index ef326cf1ee4..0c918e83887 100644 --- a/packages/mobile/src/apollo/index.ts +++ b/packages/mobile/src/apollo/index.ts @@ -1,7 +1,7 @@ +import AsyncStorage from '@react-native-community/async-storage' import ApolloClient from 'apollo-boost' import { InMemoryCache, IntrospectionFragmentMatcher } from 'apollo-cache-inmemory' import { persistCache } from 'apollo-cache-persist' -import { AsyncStorage } from 'react-native' import introspectionQueryResultData from 'src/apollo/fragmentTypes.json' import config from 'src/geth/networkConfig' import Logger from 'src/utils/Logger' diff --git a/packages/mobile/src/forceCommunityAsyncStorage.ts b/packages/mobile/src/forceCommunityAsyncStorage.ts new file mode 100644 index 00000000000..e81266cd4cd --- /dev/null +++ b/packages/mobile/src/forceCommunityAsyncStorage.ts @@ -0,0 +1,15 @@ +import AsyncStorage from '@react-native-community/async-storage' +import ReactNative from 'react-native' + +// Monkey patch React Native so it uses the community implementation of AsyncStorage. +// This is to fix the problem of loosing AsyncStorage data on iOS when some modules +// import AsyncStorage from React Native Core and some others import from React Native Community. +// Since both implementations currently write to the same file on disk, the last one to write wins +// and erases the existing data written by the other. +// See https://github.com/react-native-community/async-storage/issues/118#issuecomment-500138053 +// TODO: remove this once React Native removes AsyncStorage from Core. +Object.defineProperty(ReactNative, 'AsyncStorage', { + get() { + return AsyncStorage + }, +})