From 37dea6c47a5dff1e43db83d8e5e701df486d13aa Mon Sep 17 00:00:00 2001 From: kake26 Date: Sun, 28 Nov 2021 19:44:00 -0600 Subject: [PATCH] Refactor start --- src/screens/SettingsScreen.js | 84 ++++++++++++++--------------------- 1 file changed, 34 insertions(+), 50 deletions(-) diff --git a/src/screens/SettingsScreen.js b/src/screens/SettingsScreen.js index 2e05294..22f339e 100755 --- a/src/screens/SettingsScreen.js +++ b/src/screens/SettingsScreen.js @@ -1,63 +1,47 @@ -import React from 'react'; +import React, { useState, useEffect } from 'react'; + import { View, Text, TextInput, + } from 'react-native'; + import { Header, Button, } from 'react-native-elements'; +import { useAsyncStorage } from '@react-native-async-storage/async-storage'; -class SettingsScreen extends React.Component { - // 1 - constructor(props) { - super(props); - this.state = { text: "" }; - } - - //2 - changeText(inputText) { - const formattedText = "\u{1F632}" + inputText; - this.setState({ text: formattedText }); - } - - //3 - endEditing() { - const formattedText = this.state.text + "\u{2708}"; - this.setState({ text: formattedText }); - } - - static navigationOptions = ({ navigation }) => { - return { - title: navigation.getParam('otherParam', 'Settings'), - headerStyle: { - backgroundColor: '#3333ff', - }, - headerTintColor: '#fff', - }; - }; - - - - render() { - return ( - - Settings Screen{"\n"}{"\n"} - RPI Media Center Control v 1.0 beta Settings{"\n"} - {"\n"}server IP/hostname: - +// I know all the previous stuff uses componets and classes, but for now this is the +// Only way I can get this to work properly + +export default function App() { + const [value, setValue] = useState('value'); + const { getItem, setItem } = useAsyncStorage('@storage_key'); + + const readItemFromStorage = async () => { + const item = await getItem(); + setValue(item); + }; + + const writeItemToStorage = async newValue => { + await setItem(newValue); + setValue(newValue); + }; + + useEffect(() => { + readItemFromStorage(); + }, []); + + return ( + + Server IP: {value} {"\n"} + writeItemToStorage(newValue) } style={{borderWidth: 1, width: 100}}>{value} + - - -