Skip to content

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

Add AddItemFab with visible options to mobile app (#2287)

Leendert de Borst6e56a6bb45d1
diff --git a/apps/mobile-app/app/(tabs)/items/add-edit.tsx b/apps/mobile-app/app/(tabs)/items/add-edit.tsx
index 4ad7c985d..3282fd272 100644
--- a/apps/mobile-app/app/(tabs)/items/add-edit.tsx
+++ b/apps/mobile-app/app/(tabs)/items/add-edit.tsx
@@ -1371,9 +1371,7 @@ export default function AddEditItemScreen(): React.ReactNode {
{/* Item Type Selector */}
<ItemTypeSelector
selectedType={item.ItemType}
- isEditMode={isEditMode}
onTypeChange={handleTypeChange}
- onRegenerateAlias={aliasFieldsShownByDefault ? generateRandomAlias : undefined}
/>
{/* Item Name and Primary Fields Section */}
diff --git a/apps/mobile-app/app/(tabs)/items/folder/[id].tsx b/apps/mobile-app/app/(tabs)/items/folder/[id].tsx
index c15f88c5a..e5a0305a8 100644
--- a/apps/mobile-app/app/(tabs)/items/folder/[id].tsx
+++ b/apps/mobile-app/app/(tabs)/items/folder/[id].tsx
@@ -27,6 +27,7 @@ import { DeleteFolderModal } from '@/components/folders/DeleteFolderModal';
import { FolderBreadcrumb } from '@/components/folders/FolderBreadcrumb';
import { FolderModal } from '@/components/folders/FolderModal';
import { FolderPill } from '@/components/folders/FolderPill';
+import { AddItemFab } from '@/components/items/AddItemFab';
import { ItemCard } from '@/components/items/ItemCard';
import { SortMenu } from '@/components/items/SortMenu';
import { ThemedContainer } from '@/components/themed/ThemedContainer';
@@ -455,18 +456,17 @@ export default function FolderViewScreen(): React.ReactNode {
}, [dbContext.sqliteClient, folderId, executeVaultMutation, router]);
/**
- * Handle FAB press - navigate to add item screen with folder pre-selected.
+ * Handle item type selection from the FAB menu.
*/
- const handleAddItem = useCallback(() => {
+ const handleAddItem = useCallback((itemType: ItemType) => {
navigate(() => {
- router.push(`/(tabs)/items/add-edit?folderId=${folderId}` as '/(tabs)/items/add-edit');
+ router.push(`/(tabs)/items/add-edit?folderId=${folderId}&itemType=${itemType}` as '/(tabs)/items/add-edit');
HapticsUtility.impact();
});
}, [folderId, router, navigate]);
/**
- * Handle subfolder click - navigate to subfolder view, preserving the active filter
- * so the subfolder opens with the same filter that produced its badge count.
+ * Handle subfolder click.
*/
const handleSubfolderClick = useCallback((subfolderId: string) => {
navigate(() => {
@@ -641,31 +641,6 @@ export default function FolderViewScreen(): React.ReactNode {
textAlign: 'center',
paddingHorizontal: 32,
},
- // FAB styles
- fab: {
- alignItems: 'center',
- backgroundColor: colors.primary,
- borderRadius: 28,
- bottom: Platform.OS === 'ios' ? insets.bottom + 60 : 16,
- elevation: 4,
- height: 56,
- justifyContent: 'center',
- position: 'absolute',
- right: 16,
- shadowColor: colors.black,
- shadowOffset: {
- width: 0,
- height: 2,
- },
- shadowOpacity: 0.25,
- shadowRadius: 3.84,
- width: 56,
- zIndex: 1000,
- },
- fabIcon: {
- color: colors.primarySurfaceText,
- fontSize: 24,
- },
// Subfolder pills styles
folderPillsContainer: {
flexDirection: 'row',
@@ -940,11 +915,6 @@ export default function FolderViewScreen(): React.ReactNode {
return (
<ThemedContainer style={styles.container}>
- {/* FAB */}
- <RobustPressable style={styles.fab} onPress={handleAddItem}>
- <MaterialIcons name="add" style={styles.fabIcon} />
- </RobustPressable>
-
{/* Item list */}
<FlatList
ref={flatListRef}
@@ -980,6 +950,9 @@ export default function FolderViewScreen(): React.ReactNode {
ListEmptyComponent={renderEmptyComponent() as React.ReactElement}
/>
+ {/* FAB with item type menu */}
+ <AddItemFab onSelectType={handleAddItem} />
+
{/* Filter menu overlay */}
{renderFilterOverlay()}
diff --git a/apps/mobile-app/app/(tabs)/items/index.tsx b/apps/mobile-app/app/(tabs)/items/index.tsx
index 377e7c634..fa14d15fa 100644
--- a/apps/mobile-app/app/(tabs)/items/index.tsx
+++ b/apps/mobile-app/app/(tabs)/items/index.tsx
@@ -25,6 +25,7 @@ import Logo from '@/assets/images/logo.svg';
import { ConfirmDialog } from '@/components/common/ConfirmDialog';
import { FolderModal } from '@/components/folders/FolderModal';
import { FolderPill, type FolderWithCount } from '@/components/folders/FolderPill';
+import { AddItemFab } from '@/components/items/AddItemFab';
import { ItemCard } from '@/components/items/ItemCard';
import { ItemFilterMenu } from '@/components/items/ItemFilterMenu';
import { SortMenu } from '@/components/items/SortMenu';
@@ -33,7 +34,6 @@ import { ThemedText } from '@/components/themed/ThemedText';
import { ThemedView } from '@/components/themed/ThemedView';
import { AndroidHeader } from '@/components/ui/AndroidHeader';
import { CollapsibleHeader } from '@/components/ui/CollapsibleHeader';
-import { RobustPressable } from '@/components/ui/RobustPressable';
import { SkeletonLoader } from '@/components/ui/SkeletonLoader';
import { useApp } from '@/context/AppContext';
import { useDb } from '@/context/DbContext';
@@ -564,21 +564,18 @@ export default function ItemsScreen(): React.ReactNode {
}, [dbContext.sqliteClient, executeVaultMutation, loadItems]);
/**
- * Handle FAB press - navigate to add item screen.
+ * Handle item type selection from the FAB menu - navigate to the add item screen.
* If there's a search query, pass it as itemUrl (if URL) or itemName (if not).
*/
- const handleAddItem = useCallback(() => {
+ const handleAddItem = useCallback((itemType: ItemType) => {
navigate(() => {
const trimmedQuery = searchQuery.trim();
if (trimmedQuery) {
const isUrl = /^https?:\/\//i.test(trimmedQuery);
- if (isUrl) {
- router.push(`/(tabs)/items/add-edit?itemUrl=${encodeURIComponent(trimmedQuery)}`);
- } else {
- router.push(`/(tabs)/items/add-edit?itemName=${encodeURIComponent(trimmedQuery)}`);
- }
+ const queryParam = isUrl ? 'itemUrl' : 'itemName';
+ router.push(`/(tabs)/items/add-edit?itemType=${itemType}&${queryParam}=${encodeURIComponent(trimmedQuery)}`);
} else {
- router.push('/(tabs)/items/add-edit');
+ router.push(`/(tabs)/items/add-edit?itemType=${itemType}`);
}
HapticsUtility.impact();
});
@@ -734,31 +731,6 @@ export default function ItemsScreen(): React.ReactNode {
marginTop: 16,
paddingTop: 16,
},
- // FAB styles
- fab: {
- alignItems: 'center',
- backgroundColor: colors.primary,
- borderRadius: 28,
- bottom: Platform.OS === 'ios' ? insets.bottom + 60 : 16,
- elevation: 4,
- height: 56,
- justifyContent: 'center',
- position: 'absolute',
- right: 16,
- shadowColor: colors.black,
- shadowOffset: {
- width: 0,
- height: 2,
- },
- shadowOpacity: 0.25,
- shadowRadius: 3.84,
- width: 56,
- zIndex: 1000,
- },
- fabIcon: {
- color: colors.primarySurfaceText,
- fontSize: 24,
- },
});
/**
@@ -964,11 +936,6 @@ export default function ItemsScreen(): React.ReactNode {
alwaysVisible={true}
/>
<ThemedView style={styles.stepContainer}>
- {/* FAB */}
- <RobustPressable style={styles.fab} onPress={handleAddItem} testID="add-item-button">
- <MaterialIcons name="add" style={styles.fabIcon} />
- </RobustPressable>
-
{/* Item list */}
<Animated.FlatList
ref={flatListRef}
@@ -1011,6 +978,9 @@ export default function ItemsScreen(): React.ReactNode {
/>
</ThemedView>
+ {/* FAB with item type menu */}
+ <AddItemFab onSelectType={handleAddItem} testID="add-item-button" />
+
{/* Filter menu overlay */}
<ItemFilterMenu
visible={showFilterMenu}
diff --git a/apps/mobile-app/components/form/FormField.tsx b/apps/mobile-app/components/form/FormField.tsx
index b60c22be5..88d082d4f 100644
--- a/apps/mobile-app/components/form/FormField.tsx
+++ b/apps/mobile-app/components/form/FormField.tsx
@@ -93,7 +93,7 @@ const FormFieldComponent = forwardRef<FormFieldRef, FormFieldProps>(({
borderColor: colorRed,
},
inputGroup: {
- marginBottom: 6,
+ marginBottom: 4,
},
inputLabel: {
color: colors.textMuted,
diff --git a/apps/mobile-app/components/form/ItemNameField.tsx b/apps/mobile-app/components/form/ItemNameField.tsx
index 66b53fe72..d49b5363c 100644
--- a/apps/mobile-app/components/form/ItemNameField.tsx
+++ b/apps/mobile-app/components/form/ItemNameField.tsx
@@ -103,7 +103,7 @@ export const ItemNameField = forwardRef<ItemNameFieldRef, IItemNameFieldProps>((
color: colors.destructive,
},
wrapper: {
- marginBottom: 16,
+ marginBottom: 4,
},
});
diff --git a/apps/mobile-app/components/items/AddItemFab.tsx b/apps/mobile-app/components/items/AddItemFab.tsx
new file mode 100644
index 000000000..99a9f84c0
--- /dev/null
+++ b/apps/mobile-app/components/items/AddItemFab.tsx
@@ -0,0 +1,381 @@
+import MaterialIcons from '@expo/vector-icons/MaterialIcons';
+import { BlurView } from 'expo-blur';
+import React, { useCallback, useEffect, useRef, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+import { Animated, BackHandler, Easing, Platform, Pressable, StyleSheet, useWindowDimensions, View } from 'react-native';
+import { useSafeAreaInsets } from 'react-native-safe-area-context';
+
+import type { ItemType } from '@/utils/dist/core/models/vault';
+import { HapticsUtility } from '@/utils/HapticsUtility';
+
+import { useColorScheme, useColors } from '@/hooks/useColorScheme';
+
+import { ITEM_TYPE_OPTIONS } from '@/components/items/ItemTypeSelector';
+import { ThemedText } from '@/components/themed/ThemedText';
+import { RobustPressable } from '@/components/ui/RobustPressable';
+
+const FAB_SIZE = 56;
+const MENU_GAP = 12;
+
+type AddItemFabProps = {
+ onSelectType: (type: ItemType) => void;
+ testID?: string;
+};
+
+/**
+ * Floating action button that pops out the list of item types that can be created.
+ */
+export const AddItemFab: React.FC<AddItemFabProps> = ({ onSelectType, testID }) => {
+ const { t } = useTranslation();
+ const colors = useColors();
+ const colorScheme = useColorScheme();
+ const insets = useSafeAreaInsets();
+
+ const { width: windowWidth, height: windowHeight } = useWindowDimensions();
+
+ const [isMounted, setIsMounted] = useState(false);
+ const [backdropOffset, setBackdropOffset] = useState<{ left: number; top: number } | null>(null);
+ const rootRef = useRef<View>(null);
+ const isOpenRef = useRef(false);
+ const progress = useRef(new Animated.Value(0)).current;
+ const rowProgress = useRef(ITEM_TYPE_OPTIONS.map(() => new Animated.Value(0))).current;
+
+ /**
+ * Measure where this component sits in the window so the backdrop can cover the
+ * full screen, including the padding of the screen container it is rendered in.
+ */
+ const measureBackdrop = useCallback((): void => {
+ rootRef.current?.measureInWindow((x, y) => {
+ setBackdropOffset({ left: -x, top: -y });
+ });
+ }, []);
+
+ /**
+ * Open the menu, unfurling the rows outwards from the button.
+ */
+ const open = useCallback((): void => {
+ isOpenRef.current = true;
+ setIsMounted(true);
+ HapticsUtility.impact();
+
+ Animated.parallel([
+ Animated.timing(progress, {
+ toValue: 1,
+ duration: 180,
+ easing: Easing.out(Easing.cubic),
+ useNativeDriver: true,
+ }),
+ // Android pills unfurl one by one; the rows nearest the button lead so the
+ // menu appears to grow out of it. iOS animates the card as a whole instead.
+ ...(Platform.OS === 'android' ? [
+ Animated.stagger(35, [...rowProgress].reverse().map(value => Animated.spring(value, {
+ toValue: 1,
+ damping: 14,
+ stiffness: 220,
+ mass: 0.6,
+ useNativeDriver: true,
+ }))),
+ ] : []),
+ ]).start();
+ }, [progress, rowProgress]);
+
+ /**
+ * Close the menu and unmount it once the exit animation has finished.
+ */
+ const close = useCallback((): void => {
+ isOpenRef.current = false;
+
+ Animated.parallel([
+ Animated.timing(progress, {
+ toValue: 0,
+ duration: 130,
+ easing: Easing.in(Easing.cubic),
+ useNativeDriver: true,
+ }),
+ ...rowProgress.map(value => Animated.timing(value, {
+ toValue: 0,
+ duration: 110,
+ useNativeDriver: true,
+ })),
+ ]).start(() => {
+ if (!isOpenRef.current) {
+ setIsMounted(false);
+ }
+ });
+ }, [progress, rowProgress]);
+
+ /**
+ * Let the Android back button dismiss the menu instead of leaving the screen.
+ */
+ useEffect(() => {
+ if (Platform.OS !== 'android' || !isMounted) {
+ return;
+ }
+
+ const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
+ if (!isOpenRef.current) {
+ return false;
+ }
+ close();
+ return true;
+ });
+
+ return () => subscription.remove();
+ }, [isMounted, close]);
+
+ /**
+ * Close the menu and report the picked type to the parent screen.
+ */
+ const handleSelect = useCallback((type: ItemType): void => {
+ close();
+ onSelectType(type);
+ }, [close, onSelectType]);
+
+ /**
+ * Toggle the menu open or closed.
+ */
+ const handleFabPress = useCallback((): void => {
+ if (isOpenRef.current) {
+ close();
+ } else {
+ open();
+ }
+ }, [close, open]);
+
+ const fabBottom = Platform.OS === 'ios' ? insets.bottom + 60 : 16;
+
+ const styles = StyleSheet.create({
+ root: {
+ zIndex: 1000,
+ },
+ backdropBox: {
+ height: windowHeight,
+ left: backdropOffset?.left ?? 0,
+ position: 'absolute',
+ top: backdropOffset?.top ?? 0,
+ width: windowWidth,
+ },
+ scrim: {
+ backgroundColor: Platform.OS === 'ios' ? 'transparent' : 'rgba(0, 0, 0, 0.3)',
+ },
+ fab: {
+ alignItems: 'center',
+ backgroundColor: colors.primary,
+ borderRadius: FAB_SIZE / 2,
+ bottom: fabBottom,
+ elevation: 4,
+ height: FAB_SIZE,
+ justifyContent: 'center',
+ position: 'absolute',
+ right: 16,
+ shadowColor: colors.black,
+ shadowOffset: {
+ width: 0,
+ height: 2,
+ },
+ shadowOpacity: 0.25,
+ shadowRadius: 3.84,
+ width: FAB_SIZE,
+ zIndex: 1000,
+ },
+ fabIcon: {
+ color: colors.primarySurfaceText,
+ fontSize: 24,
+ },
+ menu: {
+ alignItems: 'flex-end',
+ bottom: fabBottom + FAB_SIZE + MENU_GAP,
+ position: 'absolute',
+ right: 16,
+ zIndex: 1000,
+ },
+ /* Android: separate pills stacked above the button. */
+ pill: {
+ alignItems: 'center',
+ backgroundColor: colors.accentBackground,
+ borderColor: colors.accentBorder,
+ borderRadius: 24,
+ borderWidth: 1,
+ elevation: 3,
+ flexDirection: 'row',
+ gap: 10,
+ paddingHorizontal: 16,
+ paddingVertical: 12,
+ },
+ pillRow: {
+ marginBottom: 10,
+ },
+ pillText: {
+ color: colors.text,
+ fontSize: 15,
+ fontWeight: '500',
+ },
+ /* iOS: single grouped card, like a native context menu. */
+ cardShadow: {
+ backgroundColor: colors.accentBackground,
+ borderRadius: 14,
+ minWidth: 220,
+ shadowColor: colors.black,
+ shadowOffset: { width: 0, height: 8 },
+ shadowOpacity: colorScheme === 'dark' ? 0.6 : 0.22,
+ shadowRadius: 18,
+ },
+ card: {
+ borderColor: colors.accentBorder,
+ borderRadius: 14,
+ borderWidth: StyleSheet.hairlineWidth,
+ overflow: 'hidden',
+ },
+ cardRow: {
+ alignItems: 'center',
+ flexDirection: 'row',
+ gap: 12,
+ justifyContent: 'space-between',
+ paddingHorizontal: 16,
+ paddingVertical: 13,
+ },
+ cardRowText: {
+ color: colors.text,
+ flex: 1,
+ fontSize: 16,
+ },
+ cardSeparator: {
+ backgroundColor: colors.accentBorder,
+ height: StyleSheet.hairlineWidth,
+ marginLeft: 16,
+ },
+ });
+
+ const rotate = progress.interpolate({
+ inputRange: [0, 1],
+ outputRange: ['0deg', '45deg'],
+ });
+
+ /**
+ * Render the Android FAB menu: one pill per item type, staggered out of the button.
+ */
+ const renderPills = (): React.ReactNode => ITEM_TYPE_OPTIONS.map((option, index) => (
+ <Animated.View
+ key={option.type}
+ style={[
+ styles.pillRow,
+ {
+ opacity: rowProgress[index],
+ transform: [
+ {
+ translateY: rowProgress[index].interpolate({
+ inputRange: [0, 1],
+ outputRange: [16, 0],
+ }),
+ },
+ {
+ scale: rowProgress[index].interpolate({
+ inputRange: [0, 1],
+ outputRange: [0.85, 1],
+ }),
+ },
+ ],
+ },
+ ]}
+ >
+ <RobustPressable
+ style={styles.pill}
+ onPress={() => handleSelect(option.type)}
+ hitSlop={0}
+ testID={`add-item-type-${option.type}`}
+ >
+ <MaterialIcons name={option.icon} size={20} color={colors.primary} />
+ <ThemedText style={styles.pillText}>{t(option.titleKey)}</ThemedText>
+ </RobustPressable>
+ </Animated.View>
+ ));
+
+ /**
+ * Render the iOS card menu: a single grouped list scaling out of the button corner.
+ */
+ const renderCard = (): React.ReactNode => (
+ <Animated.View
+ style={[
+ styles.cardShadow,
+ {
+ opacity: progress,
+ transform: [
+ {
+ translateX: progress.interpolate({
+ inputRange: [0, 1],
+ outputRange: [14, 0],
+ }),
+ },
+ {
+ translateY: progress.interpolate({
+ inputRange: [0, 1],
+ outputRange: [18, 0],
+ }),
+ },
+ {
+ scale: progress.interpolate({
+ inputRange: [0, 1],
+ outputRange: [0.85, 1],
+ }),
+ },
+ ],
+ },
+ ]}
+ >
+ <View style={styles.card}>
+ {ITEM_TYPE_OPTIONS.map((option, index) => (
+ <View key={option.type}>
+ {index > 0 && <View style={styles.cardSeparator} />}
+ <RobustPressable
+ style={styles.cardRow}
+ onPress={() => handleSelect(option.type)}
+ hitSlop={0}
+ testID={`add-item-type-${option.type}`}
+ >
+ <ThemedText style={styles.cardRowText}>{t(option.titleKey)}</ThemedText>
+ <MaterialIcons name={option.icon} size={20} color={colors.primary} />
+ </RobustPressable>
+ </View>
+ ))}
+ </View>
+ </Animated.View>
+ );
+
+ return (
+ <View
+ ref={rootRef}
+ style={[StyleSheet.absoluteFill, styles.root]}
+ onLayout={measureBackdrop}
+ pointerEvents="box-none"
+ >
+ {isMounted && (
+ <>
+ <Animated.View style={[styles.backdropBox, styles.scrim, { opacity: progress }]}>
+ {Platform.OS === 'ios' && (
+ <BlurView
+ intensity={18}
+ tint={colorScheme === 'dark' ? 'dark' : 'light'}
+ style={StyleSheet.absoluteFill}
+ />
+ )}
+ </Animated.View>
+ <Pressable
+ style={styles.backdropBox}
+ onPress={close}
+ accessibilityLabel={t('common.close')}
+ />
+
+ <View style={styles.menu} pointerEvents="box-none">
+ {Platform.OS === 'ios' ? renderCard() : renderPills()}
+ </View>
+ </>
+ )}
+
+ <RobustPressable style={styles.fab} onPress={handleFabPress} testID={testID}>
+ <Animated.View style={{ transform: [{ rotate }] }}>
+ <MaterialIcons name="add" style={styles.fabIcon} />
+ </Animated.View>
+ </RobustPressable>
+ </View>
+ );
+};
diff --git a/apps/mobile-app/i18n/locales/en.json b/apps/mobile-app/i18n/locales/en.json
index 1b794e312..0ed83e1f5 100644
--- a/apps/mobile-app/i18n/locales/en.json
+++ b/apps/mobile-app/i18n/locales/en.json
@@ -344,6 +344,7 @@
"settings": "Settings"
},
"itemTypes": {
+ "typeLabel": "Item Type",
"creating": "Creating",
"editing": "Editing",
"login": {