From 13760bc31db32ae42e13bfc39ccdea96e077f677 Mon Sep 17 00:00:00 2001 From: Johnny Almonte Date: Sat, 19 Oct 2019 11:20:41 -0400 Subject: [PATCH] Option to "Dont show again" for alert that appears on Android < 7 regarding web editors --- src/lib/userPrefsManager.js | 57 ++++++++++++++++++++++++------------ src/screens/ComponentView.js | 15 +++++++++- 2 files changed, 52 insertions(+), 20 deletions(-) diff --git a/src/lib/userPrefsManager.js b/src/lib/userPrefsManager.js index 59bcde43..a6245d18 100644 --- a/src/lib/userPrefsManager.js +++ b/src/lib/userPrefsManager.js @@ -1,35 +1,54 @@ import Storage from './sfjs/storageManager' -const LastExportDateKey = "LastExportDateKey"; +const LastExportDateKey = 'LastExportDateKey' +const DontShowAgainUnsupportedEditorsKey = 'DoNotShowAgainUnsupportedEditorsKey' export default class UserPrefsManager { - - static instance = null; - static get() { - if(this.instance == null) { - this.instance = new UserPrefsManager(); + static instance = null + static get () { + if (this.instance == null) { + this.instance = new UserPrefsManager() } - return this.instance; + return this.instance } - async setLastExportDate(date) { - await Storage.get().setItem(LastExportDateKey, JSON.stringify(date)); - this.lastExportDate = date; + async setLastExportDate (date) { + await Storage.get().setItem(LastExportDateKey, JSON.stringify(date)) + this.lastExportDate = date } - async clearLastExportDate() { - this.lastExportDate = null; - return Storage.get().clearKeys([LastExportDateKey]); + async clearLastExportDate () { + this.lastExportDate = null + return Storage.get().clearKeys([LastExportDateKey]) } - async getLastExportDate() { - if(!this.lastExportDate) { - var date = await Storage.get().getItem(LastExportDateKey); - if(date) { - this.lastExportDate = new Date(JSON.parse(date)); + async getLastExportDate () { + if (!this.lastExportDate) { + var date = await Storage.get().getItem(LastExportDateKey) + if (date) { + this.lastExportDate = new Date(JSON.parse(date)) } } - return this.lastExportDate; + return this.lastExportDate + } + + async setDontShowAgainEditorsNotSupported () { + await Storage.get().setItem( + DontShowAgainUnsupportedEditorsKey, + JSON.stringify(true) + ) + this.dontShowAgainUnsupportedEditors = true + } + + async getDontShowAgainEditorsNotSupported () { + if (!this.dontShowAgainUnsupportedEditors) { + var dontShowAgain = await Storage.get().getItem( + DontShowAgainUnsupportedEditorsKey + ) + this.dontShowAgainUnsupportedEditors = dontShowAgain !== null + } + + return this.dontShowAgainUnsupportedEditors } } diff --git a/src/screens/ComponentView.js b/src/screens/ComponentView.js index 59534f43..05b9ebe5 100644 --- a/src/screens/ComponentView.js +++ b/src/screens/ComponentView.js @@ -4,6 +4,7 @@ import { WebView } from 'react-native-webview'; import ComponentManager from '@Lib/componentManager' import ModelManager from '@Lib/sfjs/modelManager' +import UserPrefsManager from '@Lib/userPrefsManager' import StyleKit from "@Style/StyleKit" import ApplicationState from "@Lib/ApplicationState" @@ -45,7 +46,19 @@ export default class ComponentView extends Component { componentDidMount() { if(Platform.OS == "android" && Platform.Version <= 23) { // postMessage doesn't work on Android <= 6 (API version 23) https://github.com/facebook/react-native/issues/11594 - Alert.alert('Editors Not Supported', `Web editors require Android 7.0 or greater. Your version does not support web editors. Changes you make may not be properly saved. Please switch to the Plain Editor for the best experience.`, [{text: 'OK'}]) + UserPrefsManager.get().getDontShowAgainEditorsNotSupported().then(dontShowAgain => { + if (dontShowAgain) + return; + + Alert.alert( + 'Editors Not Supported', + 'Web editors require Android 7.0 or greater. Your version does not support web editors. Changes you make may not be properly saved. Please switch to the Plain Editor for the best experience.', + [ + {text: "Don't show again", onPress: () => UserPrefsManager.get().setDontShowAgainEditorsNotSupported()}, + {text: 'OK'} + ] + ) + }) } }