Give up on hidden drawer navigation.

Auto focusing is all messed up here and I
don't think all this trouble is worth it.
This commit is contained in:
Brandon Presley 2022-09-29 13:32:59 +13:00
parent 8a74d750c4
commit 3ec685a76e
5 changed files with 41 additions and 9 deletions

View File

@ -1,5 +1,4 @@
import {createDrawerNavigator} from '@react-navigation/drawer'; import {createDrawerNavigator} from '@react-navigation/drawer';
import {NavigationProp, useNavigation} from '@react-navigation/native';
import React, {useContext, useEffect, useState} from 'react'; import React, {useContext, useEffect, useState} from 'react';
import {useColorScheme} from 'react-native'; import {useColorScheme} from 'react-native';
import {IconButton} from 'react-native-paper'; import {IconButton} from 'react-native-paper';
@ -25,7 +24,6 @@ export default function Routes() {
const [migrated, setMigrated] = useState(false); const [migrated, setMigrated] = useState(false);
const dark = useColorScheme() === 'dark'; const dark = useColorScheme() === 'dark';
const {setColor} = useContext(CustomTheme); const {setColor} = useContext(CustomTheme);
const navigation = useNavigation<NavigationProp<DrawerParamList>>();
useEffect(() => { useEffect(() => {
runMigrations() runMigrations()

View File

@ -1,4 +1,11 @@
import React, {useContext, useEffect, useRef, useState} from 'react'; import {useFocusEffect} from '@react-navigation/native';
import React, {
useCallback,
useContext,
useEffect,
useRef,
useState,
} from 'react';
import {ScrollView, View} from 'react-native'; import {ScrollView, View} from 'react-native';
import {Button, Text} from 'react-native-paper'; import {Button, Text} from 'react-native-paper';
import MassiveInput from './MassiveInput'; import MassiveInput from './MassiveInput';
@ -30,17 +37,25 @@ export default function SetForm({
const repsRef = useRef<any>(null); const repsRef = useRef<any>(null);
const unitRef = useRef<any>(null); const unitRef = useRef<any>(null);
useFocusEffect(
useCallback(() => {
repsRef?.current.focus();
}, []),
);
useEffect(() => { useEffect(() => {
console.log('SetForm.useEffect:', {uri, set, name, reps, unit}); console.log('SetForm.useEffect:', {uri, set});
setName(set.name); setName(set.name);
setReps(set.reps.toString()); setReps(set.reps.toString());
setWeight(set.weight.toString()); setWeight(set.weight.toString());
setUnit(set.unit); setUnit(set.unit);
if (!uri) if (!set.image)
getSets({search: set.name, limit: 1, offset: 0}).then(([s]) => getSets({search: set.name, limit: 1, offset: 0}).then(([s]) =>
setUri(s?.image), setUri(s?.image),
); );
}, [uri, set, name, reps, unit]); else setUri(set.image);
repsRef?.current.focus();
}, [uri, set]);
const handleSubmit = () => { const handleSubmit = () => {
if (!name) return; if (!name) return;
@ -77,7 +92,6 @@ export default function SetForm({
value={name} value={name}
onChangeText={handleName} onChangeText={handleName}
autoCorrect={false} autoCorrect={false}
autoFocus={!name}
blurOnSubmit={false} blurOnSubmit={false}
onSubmitEditing={() => repsRef.current?.focus()} onSubmitEditing={() => repsRef.current?.focus()}
/> />
@ -89,7 +103,6 @@ export default function SetForm({
onSubmitEditing={() => weightRef.current?.focus()} onSubmitEditing={() => weightRef.current?.focus()}
selection={selection} selection={selection}
onSelectionChange={e => setSelection(e.nativeEvent.selection)} onSelectionChange={e => setSelection(e.nativeEvent.selection)}
autoFocus={!!name}
blurOnSubmit={false} blurOnSubmit={false}
innerRef={repsRef} innerRef={repsRef}
/> />

View File

@ -27,6 +27,7 @@ export default function SettingsPage() {
const [showUnit, setShowUnit] = useState(!!settings.showUnit); const [showUnit, setShowUnit] = useState(!!settings.showUnit);
const [workouts, setWorkouts] = useState(!!settings.workouts); const [workouts, setWorkouts] = useState(!!settings.workouts);
const [steps, setSteps] = useState(!!settings.steps); const [steps, setSteps] = useState(!!settings.steps);
const [focus, setFocus] = useState(settings.focus);
const {color, setColor} = useContext(CustomTheme); const {color, setColor} = useContext(CustomTheme);
const {toast} = useContext(SnackbarContext); const {toast} = useContext(SnackbarContext);
@ -48,6 +49,7 @@ export default function SettingsPage() {
color, color,
workouts: +workouts, workouts: +workouts,
steps: +steps, steps: +steps,
focus,
}); });
getSettings(); getSettings();
}, [ }, [
@ -61,6 +63,7 @@ export default function SettingsPage() {
color, color,
workouts, workouts,
steps, steps,
focus,
]); ]);
const changeAlarmEnabled = useCallback( const changeAlarmEnabled = useCallback(
@ -173,6 +176,18 @@ export default function SettingsPage() {
{input.name} {input.name}
</Switch> </Switch>
))} ))}
{'focus'.includes(search.toLowerCase()) && (
<Picker
style={{color}}
dropdownIconColor={color}
selectedValue={focus}
onValueChange={value => setFocus(value)}>
<Picker.Item value="" label="Don't auto focus" />
<Picker.Item value="name" label="Auto focus Name" />
<Picker.Item value="reps" label="Auto focus Reps" />
<Picker.Item value="weight" label="Auto focus Weight" />
</Picker>
)}
{'theme'.includes(search.toLowerCase()) && ( {'theme'.includes(search.toLowerCase()) && (
<Picker <Picker
style={{color}} style={{color}}
@ -190,7 +205,9 @@ export default function SettingsPage() {
</Picker> </Picker>
)} )}
{'alarm sound'.includes(search.toLowerCase()) && ( {'alarm sound'.includes(search.toLowerCase()) && (
<Button style={{alignSelf: 'flex-start'}} onPress={changeSound}> <Button
style={{alignSelf: 'flex-start', marginTop: MARGIN}}
onPress={changeSound}>
Alarm sound Alarm sound
{sound {sound
? ': ' + sound.split('/')[sound.split('/').length - 1] ? ': ' + sound.split('/')[sound.split('/').length - 1]

3
db.ts
View File

@ -103,6 +103,9 @@ const migrations = [
` `
ALTER TABLE settings ADD COLUMN nextAlarm TEXT NULL ALTER TABLE settings ADD COLUMN nextAlarm TEXT NULL
`, `,
`
ALTER TABLE settings ADD COLUMN focus TEXT NULL
`,
]; ];
export let db: SQLiteDatabase; export let db: SQLiteDatabase;

View File

@ -10,4 +10,5 @@ export default interface Settings {
workouts: number; workouts: number;
steps: number; steps: number;
nextAlarm?: string; nextAlarm?: string;
focus?: 'name' | 'reps' | 'weight';
} }