From 5cf454c6800d6bfe26e08c6b4393b82bff442b4d Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Thu, 3 Mar 2022 22:57:17 +0100 Subject: Initial commit - v1.0.0 --- components/Settings.js | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 components/Settings.js (limited to 'components/Settings.js') diff --git a/components/Settings.js b/components/Settings.js new file mode 100644 index 0000000..813b7c5 --- /dev/null +++ b/components/Settings.js @@ -0,0 +1,83 @@ +import * as React from 'react'; +import { View, Text, StyleSheet, TouchableOpacity } from 'react-native'; +import * as SecureStore from 'expo-secure-store'; +import Dialog from "react-native-dialog"; +import * as WebBrowser from 'expo-web-browser'; + +// import * as ImageManipulator from "expo-image-manipulator"; + +export default class Settings extends React.Component { + constructor(props) { + super(props) + this.state = { ip: ":", dialogVisible: false } + + this.toggleDialog = this.toggleDialog.bind(this) + } + + async componentDidMount() { + this.setState({ ip: await getIp(true) }) + } + + toggleDialog() { + this.setState({ dialogVisible: !this.state.dialogVisible }) + } + + render() { + const [ip, port] = this.state.ip.split(":"); + let [cip, cpo] = [ip, port] + const saveIP = async () => { + const ip = cip + ":" + cpo + await setIp(ip) + this.setState({ ip }) + this.toggleDialog() + } + return ( + + Current IP: {ip}{"\n"}Current port: {port} + New IP & PORT + WebBrowser.openBrowserAsync("http://" + this.state.ip)}>Open web app + + New IP & PORT + cip = c} label="IP" defaultValue={ip} /> + cpo = c} label="PORT" defaultValue={port} /> + + + + + ) + } +} + +export async function getIp(skipProtocol = false) { + return (skipProtocol ? "" : "http://") + (await SecureStore.getItemAsync("ip") ?? "192.168.0.118:8000") +} +export async function setIp(ip) { + await SecureStore.setItemAsync("ip", ip) +} + +const styles = StyleSheet.create({ + cont: { + flexDirection: "column", + backgroundColor: "black", + justifyContent: "space-evenly", + alignItems: "center", + height: "100%", + }, + h1: { + color: "white", + fontSize: 23, + // height: 60, + }, + h1b: { + color: "white", + fontSize: 25, + fontWeight: "bold", + // height: 32, + }, + span: { + color: "white", + fontSize: 22, + }, +}) + + -- cgit v1.3.1