// @flow import * as React from 'react'; import {ScrollView, View} from "react-native"; import AsyncStorageManager from "../../managers/AsyncStorageManager"; import CustomModal from "../../components/CustomModal"; import {Button, Card, List, Subheading, TextInput, Title, withTheme} from 'react-native-paper'; type Props = { navigation: Object, }; type State = { modalCurrentDisplayItem: Object, currentPreferences: Object, } /** * Class defining the Debug screen. * This screen allows the user to get and modify information on the app/device. */ class DebugScreen extends React.Component { modalRef: Object; modalInputValue = ''; state = { modalCurrentDisplayItem: {}, currentPreferences: JSON.parse(JSON.stringify(AsyncStorageManager.getInstance().preferences)) }; onModalRef: Function; colors: Object; constructor(props) { super(props); this.onModalRef = this.onModalRef.bind(this); 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 ( } onPress={onPressCallback} /> ); } else { return ( ); } } /** * Show the * @param item */ showEditModal(item: Object) { this.setState({ modalCurrentDisplayItem: item }); if (this.modalRef) { this.modalRef.open(); } } /** * Gets the edit modal content * * @return {*} */ getModalContent() { return ( {this.state.modalCurrentDisplayItem.key} Default: {this.state.modalCurrentDisplayItem.default} Current: {this.state.modalCurrentDisplayItem.current} this.modalInputValue = text} /> ); } /** * 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}; currentPreferences[key].current = value; return {currentPreferences}; }); AsyncStorageManager.getInstance().savePref(key, value); } /** * Callback used when receiving the modal ref * * @param ref */ onModalRef(ref: Object) { this.modalRef = ref; } render() { return ( {this.getModalContent()} {Object.values(this.state.currentPreferences).map((object) => {DebugScreen.getGeneralItem( () => this.showEditModal(object), undefined, //$FlowFixMe object.key, 'Click to edit')} )} ); } } export default withTheme(DebugScreen);