Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions app/(tabs)/(home)/add-link.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import { useFocusEffect } from '@react-navigation/native';
import {
Keyboard,
KeyboardAvoidingView,
Platform,
StyleSheet,
Expand Down Expand Up @@ -37,14 +38,33 @@ export default function AddLinkScreen() {
const isCompact = windowWidth < COMPACT_WIDTH || windowHeight <= SHORT_SCREEN_HEIGHT;
const [isNavigating, setIsNavigating] = useState(false);
const isNavigatingRef = useRef(false);
const urlInputRef = useRef<TextInput>(null);
const urlFocusTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);

const clearUrlFocusTimer = useCallback(() => {
if (urlFocusTimerRef.current) {
clearTimeout(urlFocusTimerRef.current);
urlFocusTimerRef.current = null;
}
}, []);

useFocusEffect(
useCallback(() => {
isNavigatingRef.current = false;
setIsNavigating(false);
}, []),

clearUrlFocusTimer();
urlFocusTimerRef.current = setTimeout(() => {
urlInputRef.current?.focus();
urlFocusTimerRef.current = null;
}, 100);

return clearUrlFocusTimer;
}, [clearUrlFocusTimer]),
);

useEffect(() => clearUrlFocusTimer, [clearUrlFocusTimer]);

useEffect(() => {
const nextSharedUrl = getSharedUrlParam(sharedUrl);

Expand Down Expand Up @@ -132,6 +152,7 @@ export default function AddLinkScreen() {
<View style={[styles.inputRow, isCompact && styles.inputRowCompact]}>
<View style={[styles.inputWrapper, isCompact && styles.inputWrapperCompact, hasError && styles.inputError]}>
<TextInput
ref={urlInputRef}
style={styles.input}
placeholder="https://example.com"
placeholderTextColor={Colors.brand.textHint}
Expand All @@ -140,8 +161,8 @@ export default function AddLinkScreen() {
autoCapitalize="none"
autoCorrect={false}
keyboardType="url"
returnKeyType="search"
onSubmitEditing={handleScan}
returnKeyType="done"
onSubmitEditing={Keyboard.dismiss}
/>
{url.length > 0 && (
<TouchableOpacity
Expand Down
Loading
Loading