Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Reset credentials page when tapping on tabbar item again (#771)
Leendert de Borstf40ba5060711
diff --git a/mobile-app/app/(tabs)/(credentials)/index.tsx b/mobile-app/app/(tabs)/(credentials)/index.tsxindex 6a782b049..c000d6684 100644--- a/mobile-app/app/(tabs)/(credentials)/index.tsx+++ b/mobile-app/app/(tabs)/(credentials)/index.tsx@@ -1,7 +1,7 @@-import { StyleSheet, Text, FlatList, ActivityIndicator, TouchableOpacity, TextInput, Keyboard, Image, RefreshControl } from 'react-native';-import { useState, useEffect, useCallback } from 'react';+import { StyleSheet, Text, FlatList, ActivityIndicator, TouchableOpacity, TextInput, Keyboard, RefreshControl } from 'react-native';+import { useState, useEffect, useCallback, useRef } from 'react';import { router, Stack } from 'expo-router';-+import { useNavigation } from '@react-navigation/native';import { ThemedText } from '@/components/ThemedText';import { ThemedView } from '@/components/ThemedView';import { ThemedSafeAreaView } from '@/components/ThemedSafeAreaView';@@ -11,55 +11,43 @@ import { Credential } from '@/utils/types/Credential';import { useVaultSync } from '@/hooks/useVaultSync';import { useColors } from '@/hooks/useColorScheme';import { CredentialCard } from '@/components/CredentialCard';+import emitter from '@/utils/EventEmitter';export default function CredentialsScreen() {const [searchQuery, setSearchQuery] = useState('');const [refreshing, setRefreshing] = useState(false);const { syncVault } = useVaultSync();const colors = useColors();+ const flatListRef = useRef<FlatList>(null);+ const navigation = useNavigation();+ const [isTabFocused, setIsTabFocused] = useState(false);- const styles = StyleSheet.create({- container: {- flex: 1,- marginBottom: 80,- },- content: {- flex: 1,- padding: 16,- },- titleContainer: {- flexDirection: 'row',- alignItems: 'center',- gap: 8,- marginBottom: 16,- },- stepContainer: {- flex: 1,- gap: 8,- },- credentialItem: {- backgroundColor: colors.accentBackground,- borderColor: colors.accentBorder,- padding: 12,- borderRadius: 8,- marginBottom: 8,- borderWidth: 1,- },- emptyText: {- color: colors.textMuted,- textAlign: 'center',- fontSize: 16,- marginTop: 24,- },- searchInput: {- backgroundColor: colors.accentBackground,- color: colors.text,- padding: 12,- borderRadius: 8,- marginBottom: 16,- fontSize: 16,- },- });+ useEffect(() => {+ const unsubscribeFocus = navigation.addListener('focus', () => {+ setIsTabFocused(true);+ });++ const unsubscribeBlur = navigation.addListener('blur', () => {+ setIsTabFocused(false);+ });++ const sub = emitter.addListener('tabPress', (routeName: string) => {+ console.log('Tab press received:', routeName);+ if (routeName === '(credentials)' && isTabFocused) {+ console.log('Tab re-pressed while focused: reset screen');+ setSearchQuery(''); // Reset search+ setRefreshing(false); // Reset refreshing+ // Scroll to top+ flatListRef.current?.scrollToOffset({ offset: 0, animated: true });+ }+ });++ return () => {+ sub.remove();+ unsubscribeFocus();+ unsubscribeBlur();+ };+ }, [isTabFocused]);const [credentialsList, setCredentialsList] = useState<Credential[]>([]);const [isLoadingCredentials, setIsLoadingCredentials] = useState(false);@@ -142,6 +130,49 @@ export default function CredentialsScreen() {navigateToCredential(credentialId);};+ const styles = StyleSheet.create({+ container: {+ flex: 1,+ marginBottom: 80,+ },+ content: {+ flex: 1,+ padding: 16,+ },+ titleContainer: {+ flexDirection: 'row',+ alignItems: 'center',+ gap: 8,+ marginBottom: 16,+ },+ stepContainer: {+ flex: 1,+ gap: 8,+ },+ credentialItem: {+ backgroundColor: colors.accentBackground,+ borderColor: colors.accentBorder,+ padding: 12,+ borderRadius: 8,+ marginBottom: 8,+ borderWidth: 1,+ },+ emptyText: {+ color: colors.textMuted,+ textAlign: 'center',+ fontSize: 16,+ marginTop: 24,+ },+ searchInput: {+ backgroundColor: colors.accentBackground,+ color: colors.text,+ padding: 12,+ borderRadius: 8,+ marginBottom: 16,+ fontSize: 16,+ },+ });+return (<ThemedSafeAreaView style={styles.container}><Stack.Screen options={{ title: "Credentials" }} />@@ -151,6 +182,7 @@ export default function CredentialsScreen() {<ActivityIndicator size="large" color={colors.primary} />) : (<FlatList+ ref={flatListRef}data={filteredCredentials}keyExtractor={(item) => item.Id}keyboardShouldPersistTaps='handled'diff --git a/mobile-app/app/(tabs)/_layout.tsx b/mobile-app/app/(tabs)/_layout.tsxindex d7a9b93a4..d6e28c3fb 100644--- a/mobile-app/app/(tabs)/_layout.tsx+++ b/mobile-app/app/(tabs)/_layout.tsx@@ -1,14 +1,14 @@-import { Tabs } from 'expo-router';+import { Tabs, usePathname } from 'expo-router';import React, { useEffect } from 'react';-import { Platform, View } from 'react-native';+import { Platform } from 'react-native';import { router } from 'expo-router';-import { HapticTab } from '@/components/HapticTab';import { IconSymbol } from '@/components/ui/IconSymbol';import TabBarBackground from '@/components/ui/TabBarBackground';import { useColors } from '@/hooks/useColorScheme';import { useAuth } from '@/context/AuthContext';import { useDb } from '@/context/DbContext';+import emitter from '@/utils/EventEmitter';export default function TabLayout() {const colors = useColors();@@ -37,6 +37,13 @@ export default function TabLayout() {return (<Tabs+ screenListeners={{+ tabPress: (e) => {+ const targetPathname = (e.target as string).split('-')[0];+ console.log('Tab pressed in layout, navigating to:', targetPathname);+ emitter.emit('tabPress', targetPathname);+ },+ }}screenOptions={{tabBarActiveTintColor: colors.tint,headerShown: false,@@ -73,9 +80,4 @@ export default function TabLayout() {/></Tabs>);-}--// Simple icon component since we don't have access to the actual icon library-const Icon = ({ name, size, color }: { name: string; size: number; color: string }) => (- <View style={{ width: size, height: size, backgroundColor: color }} />-);+}\ No newline at end of filediff --git a/mobile-app/package-lock.json b/mobile-app/package-lock.jsonindex a6ea063a4..6d9c7a613 100644--- a/mobile-app/package-lock.json+++ b/mobile-app/package-lock.json@@ -27,6 +27,7 @@"expo-symbols": "~0.2.2","expo-system-ui": "~4.0.9","expo-web-browser": "~14.0.2",+ "fbemitter": "^3.0.0","react": "18.3.1","react-dom": "18.3.1","react-native": "0.76.9",@@ -46,6 +47,7 @@"devDependencies": {"@babel/core": "^7.25.2","@types/argon2-browser": "^1.18.4",+ "@types/fbemitter": "^2.0.35","@types/jest": "^29.5.12","@types/react": "~18.3.12","@types/react-test-renderer": "^18.3.0",@@ -4163,6 +4165,13 @@"license": "MIT","peer": true},+ "node_modules/@types/fbemitter": {+ "version": "2.0.35",+ "resolved": "https://registry.npmjs.org/@types/fbemitter/-/fbemitter-2.0.35.tgz",+ "integrity": "sha512-Xem6d7qUfmouCHntCrRYgDBwbf+WWRd6G+7WEFlEZFZ67LZXiYRvT2LV8wcZa6mIaAil95+ABQdKgB6hPIsnng==",+ "dev": true,+ "license": "MIT"+ },"node_modules/@types/graceful-fs": {"version": "4.1.9","resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.9.tgz",diff --git a/mobile-app/package.json b/mobile-app/package.jsonindex d179c7f91..bdae66fee 100644--- a/mobile-app/package.json+++ b/mobile-app/package.json@@ -34,6 +34,7 @@"expo-symbols": "~0.2.2","expo-system-ui": "~4.0.9","expo-web-browser": "~14.0.2",+ "fbemitter": "^3.0.0","react": "18.3.1","react-dom": "18.3.1","react-native": "0.76.9",@@ -53,6 +54,7 @@"devDependencies": {"@babel/core": "^7.25.2","@types/argon2-browser": "^1.18.4",+ "@types/fbemitter": "^2.0.35","@types/jest": "^29.5.12","@types/react": "~18.3.12","@types/react-test-renderer": "^18.3.0",diff --git a/mobile-app/utils/EventEmitter.tsx b/mobile-app/utils/EventEmitter.tsxnew file mode 100644index 000000000..f74a41cba--- /dev/null+++ b/mobile-app/utils/EventEmitter.tsx@@ -0,0 +1,8 @@+import { EventEmitter } from 'fbemitter';++/**+ * Create a new event emitter instance which is used by the app+ * to communicate between components.+ */+const emitter = new EventEmitter();+export default emitter;