import React, {useRef, useState} from 'react'; import {ScrollView, StyleSheet, Text} from 'react-native'; import {Button, TextInput} from 'react-native-paper'; import Set from './set'; export default function SetForm({ save, set, }: { set: Set; save: (set: Set) => void; }) { const [name, setName] = useState(set.name); const [reps, setReps] = useState(set.reps.toString()); const [weight, setWeight] = useState(set.weight.toString()); const [unit, setUnit] = useState(set.unit); const [selection, setSelection] = useState({ start: 0, end: set.reps.toString().length, }); const weightRef = useRef(null); const handleSubmit = () => { save({ name, reps: Number(reps), created: set.created, weight: Number(weight), id: set.id, unit, }); }; return ( <> weightRef.current?.focus()} selection={selection} onSelectionChange={e => setSelection(e.nativeEvent.selection)} autoFocus selectTextOnFocus blurOnSubmit={false} /> {set.created?.replace('T', ' ')} ); } const styles = StyleSheet.create({ marginBottom: { marginBottom: 10, }, });