From 03549957a828061e8a7d0d02c63101c651e0cfd8 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Sun, 29 Mar 2020 15:08:51 +0200 Subject: [PATCH] Improved documentation and fixed debug mode --- screens/About/AboutDependenciesScreen.js | 6 ++ screens/About/AboutScreen.js | 77 ++++++++++++++++++++++-- screens/About/DebugScreen.js | 32 +++++++++- 3 files changed, 110 insertions(+), 5 deletions(-) diff --git a/screens/About/AboutDependenciesScreen.js b/screens/About/AboutDependenciesScreen.js index 06cdc33..2b8f3ce 100644 --- a/screens/About/AboutDependenciesScreen.js +++ b/screens/About/AboutDependenciesScreen.js @@ -10,6 +10,12 @@ type listItem = { version: string }; +/** + * Generates the dependencies list from the raw json + * + * @param object The raw json + * @return {Array} + */ function generateListFromObject(object: { [string]: string }): Array { let list = []; let keys = Object.keys(object); diff --git a/screens/About/AboutScreen.js b/screens/About/AboutScreen.js index ac890e8..022d8f4 100644 --- a/screens/About/AboutScreen.js +++ b/screens/About/AboutScreen.js @@ -105,7 +105,7 @@ class AboutScreen extends React.Component { icon: 'bug-check', text: i18n.t('aboutScreen.debug'), showChevron: true, - showOnlyDebug: true + showOnlyInDebug: true }, ]; /** @@ -171,6 +171,9 @@ class AboutScreen extends React.Component { showChevron: true }, ]; + /** + * Order of information cards + */ dataOrder: Array = [ { id: 'app', @@ -201,6 +204,11 @@ class AboutScreen extends React.Component { this.colors = props.theme.colors; } + /** + * Gets the app icon + * @param props + * @return {*} + */ getAppIcon(props) { return ( { ); } - keyExtractor(item: Object) { + /** + * Extracts a key from the given item + * + * @param item The item to extract the key from + * @return {string} The extracted key + */ + keyExtractor(item: Object): string { return item.icon; } + /** + * Gets the app card showing information and links about the app. + * + * @return {*} + */ getAppCard() { return ( @@ -235,6 +254,11 @@ class AboutScreen extends React.Component { ); } + /** + * Gets the team card showing information and links about the team + * + * @return {*} + */ getTeamCard() { return ( @@ -263,6 +287,11 @@ class AboutScreen extends React.Component { ); } + /** + * Gets the techno card showing information and links about the technologies used in the app + * + * @return {*} + */ getTechnoCard() { return ( @@ -280,12 +309,25 @@ class AboutScreen extends React.Component { ); } + /** + * Gets a chevron icon + * + * @param props + * @return {*} + */ getChevronIcon(props: Object) { return ( ); } + /** + * Gets a custom list item icon + * + * @param item The item to show the icon for + * @param props + * @return {*} + */ getItemIcon(item: Object, props: Object) { return ( @@ -295,10 +337,12 @@ class AboutScreen extends React.Component { /** * Get a clickable card item to be rendered inside a card. * - * @returns {React.Node} + * @returns {*} */ getCardItem({item}: Object) { - let shouldShow = !item.showOnlyInDebug || (item.showOnlyInDebug && this.state.isDebugUnlocked); + let shouldShow = item === undefined + || !item.showOnlyInDebug + || (item.showOnlyInDebug && this.state.isDebugUnlocked); const getItemIcon = this.getItemIcon.bind(this, item); if (shouldShow) { if (item.showChevron) { @@ -323,6 +367,9 @@ class AboutScreen extends React.Component { return null; } + /** + * Tries to unlock debug mode + */ tryUnlockDebugMode() { this.debugTapCounter = this.debugTapCounter + 1; if (this.debugTapCounter >= 4) { @@ -330,12 +377,20 @@ class AboutScreen extends React.Component { } } + /** + * Unlocks debug mode + */ unlockDebugMode() { this.setState({isDebugUnlocked: true}); let key = AsyncStorageManager.getInstance().preferences.debugUnlocked.key; AsyncStorageManager.getInstance().savePref(key, '1'); } + /** + * Gets the bug report modal's content + * + * @return {*} + */ getBugReportModal() { return ( { ); } + /** + * opens the bug report modal + */ openBugReportModal() { if (this.modalRef) { this.modalRef.open(); } } + /** + * Gets a card, depending on the given item's id + * + * @param item The item to show + * @return {*} + */ getMainCard({item}: Object) { switch (item.id) { case 'app': @@ -394,6 +458,11 @@ class AboutScreen extends React.Component { return ; } + /** + * Callback used when receiving the modal ref + * + * @param ref + */ onModalRef(ref: Object) { this.modalRef = ref; } diff --git a/screens/About/DebugScreen.js b/screens/About/DebugScreen.js index 404353a..5cbf141 100644 --- a/screens/About/DebugScreen.js +++ b/screens/About/DebugScreen.js @@ -16,7 +16,8 @@ type State = { } /** - * Class defining the Debug screen. This screen allows the user to get detailed information on the app/device. + * Class defining the Debug screen. + * This screen allows the user to get and modify information on the app/device. */ class DebugScreen extends React.Component { @@ -37,6 +38,15 @@ class DebugScreen extends React.Component { this.colors = props.theme.colors; } + /** + * Gets a clickable list item + * + * @param onPressCallback The function to call when clicking on the item + * @param icon The item's icon + * @param title The item's title + * @param subtitle The item's subtitle + * @return {*} + */ static getGeneralItem(onPressCallback: Function, icon: ?string, title: string, subtitle: string) { if (icon !== undefined) { return ( @@ -58,6 +68,10 @@ class DebugScreen extends React.Component { } } + /** + * Show the + * @param item + */ showEditModal(item: Object) { this.setState({ modalCurrentDisplayItem: item @@ -67,6 +81,11 @@ class DebugScreen extends React.Component { } } + /** + * Gets the edit modal content + * + * @return {*} + */ getModalContent() { return ( { ); } + /** + * Saves the new value of the given preference + * + * @param key The pref key + * @param value The pref value + */ saveNewPrefs(key: string, value: string) { this.setState((prevState) => { let currentPreferences = {...prevState.currentPreferences}; @@ -113,6 +138,11 @@ class DebugScreen extends React.Component { AsyncStorageManager.getInstance().savePref(key, value); } + /** + * Callback used when receiving the modal ref + * + * @param ref + */ onModalRef(ref: Object) { this.modalRef = ref; }