Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Fix android header issues (#846)

Leendert de Borstde45c286b1c2
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/AutofillService.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/AutofillService.kt
index 07db467c9..deb12afe7 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/AutofillService.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/AutofillService.kt
@@ -42,6 +42,11 @@ class AutofillService : AutofillService() {
private const val TAG = "AliasVaultAutofill"
}
+ /**
+ * The credential matcher.
+ */
+ private val credentialMatcher = CredentialMatcher()
+
override fun onFillRequest(
request: FillRequest,
cancellationSignal: CancellationSignal,
@@ -122,7 +127,7 @@ class AutofillService : AutofillService() {
// Filter credentials based on app/website info
val filteredCredentials = if (appInfo != null) {
- CredentialMatcher.filterCredentialsByAppInfo(result, appInfo)
+ credentialMatcher.filterCredentialsByAppInfo(result, appInfo)
} else {
result
}
diff --git a/apps/mobile-app/app/(tabs)/credentials/[id].tsx b/apps/mobile-app/app/(tabs)/credentials/[id].tsx
index 49e9cfcd8..0033a8d8b 100644
--- a/apps/mobile-app/app/(tabs)/credentials/[id].tsx
+++ b/apps/mobile-app/app/(tabs)/credentials/[id].tsx
@@ -1,6 +1,6 @@
import { useLocalSearchParams, useNavigation, useRouter } from 'expo-router';
import { useCallback, useEffect, useState } from 'react';
-import { ActivityIndicator, View, Text, StyleSheet, TouchableOpacity, Linking } from 'react-native';
+import { ActivityIndicator, View, Text, StyleSheet, TouchableOpacity, Linking, Pressable } from 'react-native';
import Toast from 'react-native-toast-message';
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
@@ -46,8 +46,11 @@ export default function CredentialDetailsScreen() : React.ReactNode {
*/
headerRight: () => (
<View style={styles.headerRightContainer}>
- <TouchableOpacity
- onPress={handleEdit}
+ <Pressable
+ onPressIn={handleEdit}
+ android_ripple={{ color: 'lightgray' }}
+ pressRetentionOffset={100}
+ hitSlop={100}
style={styles.headerRightButton}
>
<MaterialIcons
@@ -55,7 +58,7 @@ export default function CredentialDetailsScreen() : React.ReactNode {
size={24}
color={colors.primary}
/>
- </TouchableOpacity>
+ </Pressable>
</View>
),
});
diff --git a/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx b/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
index d3aa6fcad..534244443 100644
--- a/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
+++ b/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
@@ -1,6 +1,6 @@
-import { StyleSheet, View, TouchableOpacity, Alert, Keyboard, KeyboardAvoidingView, Platform } from 'react-native';
+import { StyleSheet, View, TouchableOpacity, Alert, Keyboard, KeyboardAvoidingView, Platform, Pressable } from 'react-native';
import { useState, useEffect, useRef, useCallback } from 'react';
-import { useLocalSearchParams, useNavigation, useRouter } from 'expo-router';
+import { Stack, useLocalSearchParams, useNavigation, useRouter } from 'expo-router';
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
import Toast from 'react-native-toast-message';
import { Resolver, useForm } from 'react-hook-form';
@@ -25,6 +25,7 @@ import LoadingOverlay from '@/components/LoadingOverlay';
import { useAuth } from '@/context/AuthContext';
import { ThemedContainer } from '@/components/themed/ThemedContainer';
import { extractServiceNameFromUrl } from '@/utils/UrlUtility';
+import { AndroidHeader } from '@/components/ui/AndroidHeader';
type CredentialMode = 'random' | 'manual';
@@ -44,6 +45,7 @@ export default function AddEditCredentialScreen() : React.ReactNode {
const [isPasswordVisible, setIsPasswordVisible] = useState(false);
const serviceNameRef = useRef<ValidatedFormFieldRef>(null);
const [isLoading, setIsLoading] = useState(false);
+ const [isSaveDisabled, setIsSaveDisabled] = useState(false);
const { control, handleSubmit, setValue, watch } = useForm<Credential>({
resolver: yupResolver(credentialSchema) as Resolver<Credential>,
@@ -206,6 +208,14 @@ export default function AddEditCredentialScreen() : React.ReactNode {
* @param {Credential} data - The form data.
*/
const onSubmit = useCallback(async (data: Credential) : Promise<void> => {
+ // Prevent multiple submissions
+ if (isSaveDisabled) {
+ return;
+ }
+
+ // Disable save button to prevent multiple submissions
+ setIsSaveDisabled(true);
+
Keyboard.dismiss();
setIsLoading(true);
@@ -440,7 +450,9 @@ export default function AddEditCredentialScreen() : React.ReactNode {
},
headerRightButton: {
padding: 10,
- paddingRight: 0,
+ },
+ headerRightButtonDisabled: {
+ opacity: 0.5,
},
keyboardContainer: {
flex: 1,
@@ -449,7 +461,7 @@ export default function AddEditCredentialScreen() : React.ReactNode {
alignItems: 'center',
borderRadius: 6,
flex: 1,
- padding: 12,
+ padding: 8,
},
modeButtonActive: {
backgroundColor: colors.primary,
@@ -484,35 +496,56 @@ export default function AddEditCredentialScreen() : React.ReactNode {
// Set header buttons
useEffect(() => {
- navigation.setOptions({
- title: isEditMode ? 'Edit Credential' : 'Add Credential',
- /**
- * Header left button.
- */
- headerLeft: () => (
- <TouchableOpacity
- onPress={() => router.back()}
- style={styles.headerLeftButton}
- >
- <ThemedText style={styles.headerLeftButtonText}>Cancel</ThemedText>
- </TouchableOpacity>
- ),
- /**
- * Header right button.
- */
- headerRight: () => (
- <TouchableOpacity
- onPress={handleSubmit(onSubmit)}
- style={styles.headerRightButton}
- >
- <MaterialIcons name="save" size={24} color={colors.primary} />
- </TouchableOpacity>
- ),
- });
- }, [navigation, mode, handleSubmit, onSubmit, colors.primary, isEditMode, router, styles.headerLeftButton, styles.headerLeftButtonText, styles.headerRightButton]);
+ if (Platform.OS === 'ios') {
+ navigation.setOptions({
+ /**
+ * Header left button.
+ */
+ headerLeft: () => (
+ <TouchableOpacity
+ onPress={() => router.back()}
+ style={styles.headerLeftButton}
+ >
+ <ThemedText style={styles.headerLeftButtonText}>Cancel</ThemedText>
+ </TouchableOpacity>
+ ),
+ /**
+ * Header right button.
+ */
+ headerRight: () => (
+ <TouchableOpacity
+ onPress={handleSubmit(onSubmit)}
+ style={[styles.headerRightButton, isSaveDisabled && styles.headerRightButtonDisabled]}
+ disabled={isSaveDisabled}
+ >
+ <MaterialIcons name="save" size={22} color={colors.primary} />
+ </TouchableOpacity>
+ ),
+ });
+ } else {
+ navigation.setOptions({
+ /**
+ * Header right button.
+ */
+ headerRight: () => (
+ <Pressable
+ onPress={handleSubmit(onSubmit)}
+ style={[styles.headerRightButton, isSaveDisabled && styles.headerRightButtonDisabled]}
+ android_ripple={{ color: 'lightgray' }}
+ pressRetentionOffset={100}
+ hitSlop={100}
+ disabled={isSaveDisabled}
+ >
+ <MaterialIcons name="save" size={24} color={colors.primary} />
+ </Pressable>
+ ),
+ });
+ }
+ }, [navigation, mode, handleSubmit, onSubmit, colors.primary, isEditMode, router, styles.headerLeftButton, styles.headerLeftButtonText, styles.headerRightButton, styles.headerRightButtonDisabled, isSaveDisabled]);
return (
<>
+ <Stack.Screen options={{ title: isEditMode ? 'Edit Credential' : 'Add Credential' }} />
{(isLoading) && (
<LoadingOverlay status={syncStatus} />
)}
diff --git a/apps/mobile-app/app/(tabs)/emails/_layout.tsx b/apps/mobile-app/app/(tabs)/emails/_layout.tsx
index b4d4f60d6..34c970b40 100644
--- a/apps/mobile-app/app/(tabs)/emails/_layout.tsx
+++ b/apps/mobile-app/app/(tabs)/emails/_layout.tsx
@@ -28,6 +28,8 @@ export default function EmailsLayout(): React.ReactNode {
name="[id]"
options={{
title: 'Email',
+ ...defaultHeaderOptions,
+ headerTransparent: false,
}}
/>
</Stack>
diff --git a/apps/mobile-app/components/credentials/details/TotpSection.tsx b/apps/mobile-app/components/credentials/details/TotpSection.tsx
index 750dab3fe..3b4f13131 100644
--- a/apps/mobile-app/components/credentials/details/TotpSection.tsx
+++ b/apps/mobile-app/components/credentials/details/TotpSection.tsx
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react';
-import { View, StyleSheet, TouchableOpacity } from 'react-native';
+import { View, StyleSheet, TouchableOpacity, Platform } from 'react-native';
import * as OTPAuth from 'otpauth';
import * as Clipboard from 'expo-clipboard';
import Toast from 'react-native-toast-message';
@@ -69,12 +69,16 @@ export const TotpSection: React.FC<TotpSectionProps> = ({ credential }) : React.
const copyToClipboard = async (code: string): Promise<void> => {
try {
await Clipboard.setStringAsync(code);
- Toast.show({
- type: 'success',
- text1: 'Copied to clipboard',
- position: 'bottom',
- visibilityTime: 2000,
- });
+
+ if (Platform.OS !== 'android') {
+ // Only show toast on iOS, Android already shows a native toast on clipboard interactions.
+ Toast.show({
+ type: 'success',
+ text1: 'Copied to clipboard',
+ position: 'bottom',
+ visibilityTime: 2000,
+ });
+ }
} catch (error) {
console.error('Failed to copy:', error);
}
diff --git a/apps/mobile-app/components/form/FormInputCopyToClipboard.tsx b/apps/mobile-app/components/form/FormInputCopyToClipboard.tsx
index 16d4a5145..9f14eb3f7 100644
--- a/apps/mobile-app/components/form/FormInputCopyToClipboard.tsx
+++ b/apps/mobile-app/components/form/FormInputCopyToClipboard.tsx
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
-import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
+import { View, Text, TouchableOpacity, StyleSheet, Platform } from 'react-native';
import * as Clipboard from 'expo-clipboard';
import Toast from 'react-native-toast-message';
import { MaterialIcons } from '@expo/vector-icons';
@@ -29,12 +29,16 @@ const FormInputCopyToClipboard: React.FC<FormInputCopyToClipboardProps> = ({
const copyToClipboard = async () : Promise<void> => {
if (value) {
await Clipboard.setStringAsync(value);
- Toast.show({
- type: 'success',
- text1: 'Copied to clipboard',
- position: 'bottom',
- visibilityTime: 2000,
- });
+
+ if (Platform.OS !== 'android') {
+ // Only show toast on iOS, Android already shows a native toast on clipboard interactions.
+ Toast.show({
+ type: 'success',
+ text1: 'Copied to clipboard',
+ position: 'bottom',
+ visibilityTime: 2000,
+ });
+ }
}
};
diff --git a/apps/mobile-app/components/themed/ThemedHeader.tsx b/apps/mobile-app/components/themed/ThemedHeader.tsx
index 5d8752fe4..1697c861a 100644
--- a/apps/mobile-app/components/themed/ThemedHeader.tsx
+++ b/apps/mobile-app/components/themed/ThemedHeader.tsx
@@ -13,10 +13,6 @@ export function ThemedHeader(): React.ReactNode {
const colors = useColors();
const styles = StyleSheet.create({
- androidHeader: {
- backgroundColor: colors.headerBackgroundAndroid,
- height: 56,
- },
header: {
flex: 1,
},
@@ -30,26 +26,16 @@ export function ThemedHeader(): React.ReactNode {
},
});
- if (Platform.OS === 'ios') {
- return (
- <View style={styles.header}>
- <BlurView
- tint={colorScheme === 'dark' ? 'dark' : 'light'}
- intensity={colorScheme === 'dark' ? 90 : 100}
- style={[StyleSheet.absoluteFill, { backgroundColor: colors.headerBackgroundIos }]}
- />
- <View style={[styles.headerBorder, { backgroundColor: colors.headerBorder }]} />
- </View>
- );
- } else if (Platform.OS === 'android') {
- return (
- <View style={[styles.header, styles.androidHeader]}>
- <View style={[styles.headerBorder, { backgroundColor: colors.headerBorder }]} />
- </View>
- );
- }
-
- return null;
+ return (
+ <View style={styles.header}>
+ <BlurView
+ tint={colorScheme === 'dark' ? 'dark' : 'light'}
+ intensity={colorScheme === 'dark' ? 90 : 100}
+ style={[StyleSheet.absoluteFill, { backgroundColor: colors.headerBackgroundIos }]}
+ />
+ <View style={[styles.headerBorder, { backgroundColor: colors.headerBorder }]} />
+ </View>
+ );
}
/**
@@ -59,13 +45,9 @@ export function ThemedHeader(): React.ReactNode {
*/
export const defaultHeaderOptions = {
/**
- * On iOS, we want the header to be transparent.
- * On Android, we want the header to be opaque.
- */
- headerTransparent: Platform.OS === 'ios' ? true : false,
- /**
- * Header background component that provides consistent styling.
- * @returns {React.ReactNode} The themed header background component
+ * On iOS, we want the header to be transparent and use our custom header background.
+ * On Android, we want to use the native header.
*/
- headerBackground: (): React.ReactNode => <ThemedHeader />,
+ headerTransparent: Platform.OS === 'ios',
+ headerBackground: Platform.OS === 'ios' ? (): React.ReactNode => <ThemedHeader /> : undefined,
};
\ No newline at end of file
diff --git a/apps/mobile-app/components/ui/AndroidHeader.tsx b/apps/mobile-app/components/ui/AndroidHeader.tsx
index d53d17cf8..df84f4daa 100644
--- a/apps/mobile-app/components/ui/AndroidHeader.tsx
+++ b/apps/mobile-app/components/ui/AndroidHeader.tsx
@@ -1,4 +1,4 @@
-import { View, StyleSheet, TouchableOpacity } from 'react-native';
+import { View, StyleSheet, Pressable } from 'react-native';
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
import { ThemedText } from '@/components/themed/ThemedText';
@@ -52,30 +52,36 @@ export function AndroidHeader({ title, headerButtons = [] }: IAndroidHeaderProps
return (
<View style={styles.headerContainer}>
{headerButtons.find(b => b.position === 'left') && (
- <TouchableOpacity
+ <Pressable
style={[styles.headerButton, styles.leftButton]}
onPress={headerButtons.find(b => b.position === 'left')?.onPress}
+ hitSlop={100}
+ android_ripple={{ color: 'lightgray' }}
+ pressRetentionOffset={100}
>
<MaterialIcons
name={headerButtons.find(b => b.position === 'left')?.icon ?? 'add'}
size={28}
color={colors.primary}
/>
- </TouchableOpacity>
+ </Pressable>
)}
<Logo width={40} height={40} style={styles.logo} />
<ThemedText style={styles.headerTitle}>{title}</ThemedText>
{headerButtons.find(b => b.position === 'right') && (
- <TouchableOpacity
+ <Pressable
style={[styles.headerButton, styles.rightButton]}
onPress={headerButtons.find(b => b.position === 'right')?.onPress}
+ hitSlop={100}
+ android_ripple={{ color: 'lightgray' }}
+ pressRetentionOffset={100}
>
<MaterialIcons
name={headerButtons.find(b => b.position === 'right')?.icon ?? 'add'}
size={28}
color={colors.primary}
/>
- </TouchableOpacity>
+ </Pressable>
)}
</View>
);