diff --git a/src/screens/About/AboutDependenciesScreen.js b/src/screens/About/AboutDependenciesScreen.js index 48cc2c8..8e77afa 100644 --- a/src/screens/About/AboutDependenciesScreen.js +++ b/src/screens/About/AboutDependenciesScreen.js @@ -32,23 +32,40 @@ type Props = { route: Object } +const LIST_ITEM_HEIGHT = 64; + /** * Class defining a screen showing the list of libraries used by the app, taken from package.json */ export default class AboutDependenciesScreen extends React.Component { + data: Array; + + constructor() { + super(); + this.data = generateListFromObject(packageJson.dependencies); + } + + keyExtractor = (item: Object) => item.name; + + renderItem = ({item}: Object) => + ; + + itemLayout = (data, index) => ({length: LIST_ITEM_HEIGHT, offset: LIST_ITEM_HEIGHT * index, index}); + render() { - const data = generateListFromObject(packageJson.dependencies); return ( item.name} - style={{minHeight: 300, width: '100%'}} - renderItem={({item}) => - } + data={this.data} + keyExtractor={this.keyExtractor} + renderItem={this.renderItem} + // Performance props, see https://reactnative.dev/docs/optimizing-flatlist-configuration + removeClippedSubviews={true} + getItemLayout={this.itemLayout} /> ); } diff --git a/src/screens/About/DebugScreen.js b/src/screens/About/DebugScreen.js index 7c544ed..e9e38ba 100644 --- a/src/screens/About/DebugScreen.js +++ b/src/screens/About/DebugScreen.js @@ -1,10 +1,10 @@ // @flow import * as React from 'react'; -import {ScrollView, View} from "react-native"; +import {FlatList, View} from "react-native"; import AsyncStorageManager from "../../managers/AsyncStorageManager"; import CustomModal from "../../components/Custom/CustomModal"; -import {Button, Card, List, Subheading, TextInput, Title, withTheme} from 'react-native-paper'; +import {Button, List, Subheading, TextInput, Title, withTheme} from 'react-native-paper'; type Props = { navigation: Object, @@ -12,7 +12,7 @@ type Props = { type State = { modalCurrentDisplayItem: Object, - currentPreferences: Object, + currentPreferences: Array, } /** @@ -23,10 +23,6 @@ class DebugScreen extends React.Component { modalRef: Object; modalInputValue = ''; - state = { - modalCurrentDisplayItem: {}, - currentPreferences: JSON.parse(JSON.stringify(AsyncStorageManager.getInstance().preferences)) - }; onModalRef: Function; @@ -36,40 +32,20 @@ class DebugScreen extends React.Component { super(props); this.onModalRef = this.onModalRef.bind(this); this.colors = props.theme.colors; + let copy = {...AsyncStorageManager.getInstance().preferences}; + console.log(copy); + let currentPreferences = []; + Object.values(copy).map((object) => { + currentPreferences.push(object); + }); + this.state = { + modalCurrentDisplayItem: {}, + currentPreferences: currentPreferences + }; } /** - * 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 + * Show the edit modal * @param item */ showEditModal(item: Object) { @@ -123,6 +99,17 @@ class DebugScreen extends React.Component { ); } + findIndexOfKey(key: string) { + let index = -1; + for (let i = 0; i < this.state.currentPreferences.length; i++) { + if (this.state.currentPreferences[i].key === key) { + index = i; + break; + } + } + return index; + } + /** * Saves the new value of the given preference * @@ -131,11 +118,12 @@ class DebugScreen extends React.Component { */ saveNewPrefs(key: string, value: string) { this.setState((prevState) => { - let currentPreferences = {...prevState.currentPreferences}; - currentPreferences[key].current = value; + let currentPreferences = [...prevState.currentPreferences]; + currentPreferences[this.findIndexOfKey(key)].current = value; return {currentPreferences}; }); AsyncStorageManager.getInstance().savePref(key, value); + this.modalRef.close(); } /** @@ -147,31 +135,28 @@ class DebugScreen extends React.Component { this.modalRef = ref; } + renderItem = ({item}: Object) => { + return ( + this.showEditModal(item)} + /> + ); + }; + render() { return ( {this.getModalContent()} - - - - - {Object.values(this.state.currentPreferences).map((object) => - - {DebugScreen.getGeneralItem( - () => this.showEditModal(object), - undefined, - //$FlowFixMe - object.key, - 'Click to edit')} - - )} - - - + {/*$FlowFixMe*/} + ); }