Skip to content

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

Add shared modalwrapper to mobile app (#1473)

Leendert de Borstc6dd5406cfc7
diff --git a/apps/mobile-app/components/common/ModalWrapper.tsx b/apps/mobile-app/components/common/ModalWrapper.tsx
new file mode 100644
index 000000000..0a56fe29a
--- /dev/null
+++ b/apps/mobile-app/components/common/ModalWrapper.tsx
@@ -0,0 +1,185 @@
+import React from 'react';
+import {
+ Modal,
+ StyleSheet,
+ Text,
+ View,
+ KeyboardAvoidingView,
+ Platform,
+ TouchableWithoutFeedback,
+ Keyboard,
+ ScrollView,
+} from 'react-native';
+
+import { useColors, useColorScheme } from '@/hooks/useColorScheme';
+
+interface IModalWrapperProps {
+ /** Whether the modal is visible. */
+ isOpen: boolean;
+ /** Callback when the modal is requested to close. */
+ onClose: () => void;
+ /** Whether closing is disabled (e.g., during submission). */
+ isSubmitting?: boolean;
+ /** Optional modal title. */
+ title?: string;
+ /** Modal body content. */
+ children: React.ReactNode;
+ /** Optional footer content (e.g., buttons). */
+ footer?: React.ReactNode;
+ /** Whether to enable keyboard avoiding behavior. Default: false. */
+ keyboardAvoiding?: boolean;
+ /** Whether the content should be scrollable. Default: false. */
+ scrollable?: boolean;
+ /** Maximum height for scrollable content. Default: 400. */
+ maxScrollHeight?: number;
+ /** Animation type for the modal. Default: 'fade'. */
+ animationType?: 'fade' | 'slide' | 'none';
+ /** Custom max width for the container. Default: 400. */
+ maxWidth?: number;
+ /** Custom width percentage. Default: '90%'. */
+ width?: string;
+ /** Whether to show header border. Default: true (only when title is provided). */
+ showHeaderBorder?: boolean;
+ /** Whether to show footer border. Default: true (only when footer is provided). */
+ showFooterBorder?: boolean;
+}
+
+/**
+ * A generic modal wrapper component that provides consistent behavior:
+ * - Themed backdrop (dark/light mode support)
+ * - Consistent container styling
+ * - Optional title with header
+ * - Optional scrollable content
+ * - Optional keyboard avoiding behavior
+ * - Prevents closing during submission
+ */
+export const ModalWrapper: React.FC<IModalWrapperProps> = ({
+ isOpen,
+ onClose,
+ isSubmitting = false,
+ title,
+ children,
+ footer,
+ keyboardAvoiding = false,
+ scrollable = false,
+ maxScrollHeight = 400,
+ animationType = 'fade',
+ maxWidth = 400,
+ width = '90%',
+ showHeaderBorder = true,
+ showFooterBorder = true,
+}) => {
+ const colors = useColors();
+ const colorScheme = useColorScheme();
+
+ /**
+ * Handle close - only allow if not submitting.
+ */
+ const handleClose = (): void => {
+ if (!isSubmitting) {
+ onClose();
+ }
+ };
+
+ const styles = StyleSheet.create({
+ backdrop: {
+ alignItems: 'center',
+ // Lighter backdrop in dark mode for better contrast against black background
+ backgroundColor: colorScheme === 'dark' ? 'rgba(255, 255, 255, 0.15)' : 'rgba(0, 0, 0, 0.5)',
+ flex: 1,
+ justifyContent: 'center',
+ },
+ container: {
+ backgroundColor: colors.background,
+ borderRadius: 12,
+ marginHorizontal: 16,
+ maxWidth,
+ overflow: 'hidden',
+ width: width as never,
+ },
+ header: {
+ borderBottomColor: showHeaderBorder ? colors.accentBorder : 'transparent',
+ borderBottomWidth: showHeaderBorder ? 1 : 0,
+ padding: 20,
+ },
+ title: {
+ color: colors.text,
+ fontSize: 18,
+ fontWeight: '600',
+ },
+ body: {
+ padding: 20,
+ },
+ scrollBody: {
+ maxHeight: maxScrollHeight,
+ padding: 20,
+ },
+ footer: {
+ borderTopColor: showFooterBorder ? colors.accentBorder : 'transparent',
+ borderTopWidth: showFooterBorder ? 1 : 0,
+ padding: 16,
+ },
+ });
+
+ const renderContent = (): React.ReactNode => (
+ <View style={styles.container}>
+ {title && (
+ <View style={styles.header}>
+ <Text style={styles.title}>{title}</Text>
+ </View>
+ )}
+
+ {scrollable ? (
+ <ScrollView style={styles.scrollBody}>
+ {children}
+ </ScrollView>
+ ) : (
+ <View style={styles.body}>
+ {children}
+ </View>
+ )}
+
+ {footer && (
+ <View style={styles.footer}>
+ {footer}
+ </View>
+ )}
+ </View>
+ );
+
+ const renderBackdrop = (): React.ReactNode => {
+ if (keyboardAvoiding) {
+ return (
+ <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
+ <KeyboardAvoidingView
+ behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
+ style={styles.backdrop}
+ >
+ <TouchableWithoutFeedback>
+ {renderContent()}
+ </TouchableWithoutFeedback>
+ </KeyboardAvoidingView>
+ </TouchableWithoutFeedback>
+ );
+ }
+
+ return (
+ <View style={styles.backdrop}>
+ {renderContent()}
+ </View>
+ );
+ };
+
+ return (
+ <Modal
+ visible={isOpen}
+ transparent
+ animationType={animationType}
+ onRequestClose={handleClose}
+ >
+ {renderBackdrop()}
+ </Modal>
+ );
+};
+
+export default ModalWrapper;
diff --git a/apps/mobile-app/components/folders/DeleteFolderModal.tsx b/apps/mobile-app/components/folders/DeleteFolderModal.tsx
index 344088a2f..ca5bd3510 100644
--- a/apps/mobile-app/components/folders/DeleteFolderModal.tsx
+++ b/apps/mobile-app/components/folders/DeleteFolderModal.tsx
@@ -2,7 +2,6 @@ import MaterialIcons from '@expo/vector-icons/MaterialIcons';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import {
- Modal,
StyleSheet,
Text,
TouchableOpacity,
@@ -10,7 +9,8 @@ import {
ActivityIndicator,
} from 'react-native';
-import { useColors, useColorScheme } from '@/hooks/useColorScheme';
+import { useColors } from '@/hooks/useColorScheme';
+import { ModalWrapper } from '@/components/common/ModalWrapper';
interface IDeleteFolderModalProps {
isOpen: boolean;
@@ -32,7 +32,6 @@ export const DeleteFolderModal: React.FC<IDeleteFolderModalProps> = ({
}) => {
const { t } = useTranslation();
const colors = useColors();
- const colorScheme = useColorScheme();
const [isSubmitting, setIsSubmitting] = useState(false);
/**
@@ -65,22 +64,7 @@ export const DeleteFolderModal: React.FC<IDeleteFolderModalProps> = ({
}
};
- /**
- * Handle close - only allow if not submitting.
- */
- const handleClose = (): void => {
- if (!isSubmitting) {
- onClose();
- }
- };
-
const styles = StyleSheet.create({
- backdrop: {
- alignItems: 'center',
- backgroundColor: colorScheme === 'dark' ? 'rgba(255, 255, 255, 0.15)' : 'rgba(0, 0, 0, 0.5)',
- flex: 1,
- justifyContent: 'center',
- },
cancelButton: {
alignItems: 'center',
backgroundColor: colors.accentBackground,
@@ -95,14 +79,6 @@ export const DeleteFolderModal: React.FC<IDeleteFolderModalProps> = ({
fontSize: 16,
fontWeight: '500',
},
- container: {
- backgroundColor: colors.background,
- borderRadius: 12,
- marginHorizontal: 20,
- maxWidth: 400,
- padding: 20,
- width: '90%',
- },
optionButton: {
borderColor: colors.accentBorder,
borderRadius: 10,
@@ -137,84 +113,74 @@ export const DeleteFolderModal: React.FC<IDeleteFolderModalProps> = ({
optionTitleDanger: {
color: colors.destructive,
},
- title: {
- color: colors.text,
- fontSize: 18,
- fontWeight: '600',
- marginBottom: 4,
- },
});
return (
- <Modal
- visible={isOpen}
- transparent
- animationType="fade"
- onRequestClose={handleClose}
+ <ModalWrapper
+ isOpen={isOpen}
+ onClose={onClose}
+ isSubmitting={isSubmitting}
+ title={t('items.folders.deleteFolder')}
+ showHeaderBorder={false}
+ showFooterBorder={false}
>
- <View style={styles.backdrop}>
- <View style={styles.container}>
- <Text style={styles.title}>{t('items.folders.deleteFolder')}</Text>
-
- {/* Option 1: Delete folder only - move items to root */}
- <TouchableOpacity
- style={styles.optionButton}
- onPress={handleDeleteFolderOnly}
- disabled={isSubmitting}
- >
- <MaterialIcons
- name="folder"
- size={22}
- color={colors.tint}
- style={styles.optionIcon}
- />
- <View style={styles.optionContent}>
- <Text style={styles.optionTitle}>
- {t('items.folders.deleteFolderKeepItems')}
- </Text>
- <Text style={styles.optionDescription}>
- {t('items.folders.deleteFolderKeepItemsDescription')}
- </Text>
- </View>
- {isSubmitting && <ActivityIndicator size="small" color={colors.primary} />}
- </TouchableOpacity>
+ {/* Option 1: Delete folder only - move items to root */}
+ <TouchableOpacity
+ style={styles.optionButton}
+ onPress={handleDeleteFolderOnly}
+ disabled={isSubmitting}
+ >
+ <MaterialIcons
+ name="folder"
+ size={22}
+ color={colors.tint}
+ style={styles.optionIcon}
+ />
+ <View style={styles.optionContent}>
+ <Text style={styles.optionTitle}>
+ {t('items.folders.deleteFolderKeepItems')}
+ </Text>
+ <Text style={styles.optionDescription}>
+ {t('items.folders.deleteFolderKeepItemsDescription')}
+ </Text>
+ </View>
+ {isSubmitting && <ActivityIndicator size="small" color={colors.primary} />}
+ </TouchableOpacity>
- {/* Option 2: Delete folder and contents */}
- {itemCount > 0 && (
- <TouchableOpacity
- style={[styles.optionButton, styles.optionButtonDanger]}
- onPress={handleDeleteFolderAndContents}
- disabled={isSubmitting}
- >
- <MaterialIcons
- name="delete"
- size={22}
- color={colors.destructive}
- style={styles.optionIcon}
- />
- <View style={styles.optionContent}>
- <Text style={[styles.optionTitle, styles.optionTitleDanger]}>
- {t('items.folders.deleteFolderAndItems')}
- </Text>
- <Text style={[styles.optionDescription, styles.optionDescriptionDanger]}>
- {t('items.folders.deleteFolderAndItemsDescription', { count: itemCount })}
- </Text>
- </View>
- {isSubmitting && <ActivityIndicator size="small" color={colors.destructive} />}
- </TouchableOpacity>
- )}
+ {/* Option 2: Delete folder and contents */}
+ {itemCount > 0 && (
+ <TouchableOpacity
+ style={[styles.optionButton, styles.optionButtonDanger]}
+ onPress={handleDeleteFolderAndContents}
+ disabled={isSubmitting}
+ >
+ <MaterialIcons
+ name="delete"
+ size={22}
+ color={colors.destructive}
+ style={styles.optionIcon}
+ />
+ <View style={styles.optionContent}>
+ <Text style={[styles.optionTitle, styles.optionTitleDanger]}>
+ {t('items.folders.deleteFolderAndItems')}
+ </Text>
+ <Text style={[styles.optionDescription, styles.optionDescriptionDanger]}>
+ {t('items.folders.deleteFolderAndItemsDescription', { count: itemCount })}
+ </Text>
+ </View>
+ {isSubmitting && <ActivityIndicator size="small" color={colors.destructive} />}
+ </TouchableOpacity>
+ )}
- {/* Cancel button */}
- <TouchableOpacity
- style={styles.cancelButton}
- onPress={handleClose}
- disabled={isSubmitting}
- >
- <Text style={styles.cancelButtonText}>{t('common.cancel')}</Text>
- </TouchableOpacity>
- </View>
- </View>
- </Modal>
+ {/* Cancel button */}
+ <TouchableOpacity
+ style={styles.cancelButton}
+ onPress={onClose}
+ disabled={isSubmitting}
+ >
+ <Text style={styles.cancelButtonText}>{t('common.cancel')}</Text>
+ </TouchableOpacity>
+ </ModalWrapper>
);
};
diff --git a/apps/mobile-app/components/folders/FolderModal.tsx b/apps/mobile-app/components/folders/FolderModal.tsx
index 64ad096f0..3edf75eb2 100644
--- a/apps/mobile-app/components/folders/FolderModal.tsx
+++ b/apps/mobile-app/components/folders/FolderModal.tsx
@@ -1,20 +1,16 @@
import React, { useState, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import {
- Modal,
StyleSheet,
Text,
TextInput,
TouchableOpacity,
View,
- KeyboardAvoidingView,
- Platform,
- TouchableWithoutFeedback,
- Keyboard,
ActivityIndicator,
} from 'react-native';
-import { useColors, useColorScheme } from '@/hooks/useColorScheme';
+import { useColors } from '@/hooks/useColorScheme';
+import { ModalWrapper } from '@/components/common/ModalWrapper';
interface IFolderModalProps {
isOpen: boolean;
@@ -36,7 +32,6 @@ export const FolderModal: React.FC<IFolderModalProps> = ({
}) => {
const { t } = useTranslation();
const colors = useColors();
- const colorScheme = useColorScheme();
const [folderName, setFolderName] = useState(initialName);
const [isSubmitting, setIsSubmitting] = useState(false);
const [error, setError] = useState<string | null>(null);
@@ -72,67 +67,44 @@ export const FolderModal: React.FC<IFolderModalProps> = ({
}
};
- /**
- * Handle close - only allow if not submitting
- */
- const handleClose = (): void => {
- if (!isSubmitting) {
- onClose();
- }
- };
-
const styles = StyleSheet.create({
- backdrop: {
- alignItems: 'center',
- backgroundColor: colorScheme === 'dark' ? 'rgba(255, 255, 255, 0.15)' : 'rgba(0, 0, 0, 0.5)',
- flex: 1,
- justifyContent: 'center',
- },
- buttonRow: {
- flexDirection: 'row',
- gap: 12,
- marginTop: 20,
+ label: {
+ color: colors.textMuted,
+ fontSize: 14,
+ fontWeight: '500',
},
- cancelButton: {
- alignItems: 'center',
+ input: {
+ backgroundColor: colors.accentBackground,
borderColor: colors.accentBorder,
borderRadius: 8,
borderWidth: 1,
- flex: 1,
- paddingVertical: 12,
- },
- cancelButtonText: {
color: colors.text,
fontSize: 16,
- fontWeight: '500',
- },
- container: {
- backgroundColor: colors.background,
- borderRadius: 12,
- marginHorizontal: 20,
- maxWidth: 400,
- padding: 20,
- width: '90%',
+ marginTop: 8,
+ paddingHorizontal: 12,
+ paddingVertical: 10,
},
errorText: {
color: colors.destructive,
fontSize: 14,
marginTop: 8,
},
- input: {
- backgroundColor: colors.accentBackground,
+ buttonRow: {
+ flexDirection: 'row',
+ gap: 12,
+ marginTop: 20,
+ },
+ cancelButton: {
+ alignItems: 'center',
borderColor: colors.accentBorder,
borderRadius: 8,
borderWidth: 1,
+ flex: 1,
+ paddingVertical: 12,
+ },
+ cancelButtonText: {
color: colors.text,
fontSize: 16,
- marginTop: 8,
- paddingHorizontal: 12,
- paddingVertical: 10,
- },
- label: {
- color: colors.textMuted,
- fontSize: 14,
fontWeight: '500',
},
saveButton: {
@@ -150,74 +122,56 @@ export const FolderModal: React.FC<IFolderModalProps> = ({
fontSize: 16,
fontWeight: '600',
},
- title: {
- color: colors.text,
- fontSize: 18,
- fontWeight: '600',
- marginBottom: 16,
- },
});
return (
- <Modal
- visible={isOpen}
- transparent
- animationType="fade"
- onRequestClose={handleClose}
+ <ModalWrapper
+ isOpen={isOpen}
+ onClose={onClose}
+ isSubmitting={isSubmitting}
+ title={mode === 'create' ? t('items.folders.createFolder') : t('items.folders.editFolder')}
+ keyboardAvoiding
+ showHeaderBorder={false}
+ showFooterBorder={false}
>
- <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
- <KeyboardAvoidingView
- behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
- style={styles.backdrop}
- >
- <TouchableWithoutFeedback>
- <View style={styles.container}>
- <Text style={styles.title}>
- {mode === 'create' ? t('items.folders.createFolder') : t('items.folders.editFolder')}
- </Text>
+ <Text style={styles.label}>{t('items.folders.folderName')}</Text>
+ <TextInput
+ style={styles.input}
+ value={folderName}
+ onChangeText={setFolderName}
+ placeholder={t('items.folders.folderNamePlaceholder')}
+ placeholderTextColor={colors.textMuted}
+ autoFocus
+ autoCapitalize="sentences"
+ editable={!isSubmitting}
+ />
- <Text style={styles.label}>{t('items.folders.folderName')}</Text>
- <TextInput
- style={styles.input}
- value={folderName}
- onChangeText={setFolderName}
- placeholder={t('items.folders.folderNamePlaceholder')}
- placeholderTextColor={colors.textMuted}
- autoFocus
- autoCapitalize="sentences"
- editable={!isSubmitting}
- />
+ {error && <Text style={styles.errorText}>{error}</Text>}
- {error && <Text style={styles.errorText}>{error}</Text>}
-
- <View style={styles.buttonRow}>
- <TouchableOpacity
- style={styles.cancelButton}
- onPress={handleClose}
- disabled={isSubmitting}
- >
- <Text style={styles.cancelButtonText}>{t('common.cancel')}</Text>
- </TouchableOpacity>
+ <View style={styles.buttonRow}>
+ <TouchableOpacity
+ style={styles.cancelButton}
+ onPress={onClose}
+ disabled={isSubmitting}
+ >
+ <Text style={styles.cancelButtonText}>{t('common.cancel')}</Text>
+ </TouchableOpacity>
- <TouchableOpacity
- style={[styles.saveButton, isSubmitting && styles.saveButtonDisabled]}
- onPress={handleSubmit}
- disabled={isSubmitting}
- >
- {isSubmitting ? (
- <ActivityIndicator color="#FFFFFF" size="small" />
- ) : (
- <Text style={styles.saveButtonText}>
- {mode === 'create' ? t('common.add') : t('common.save')}
- </Text>
- )}
- </TouchableOpacity>
- </View>
- </View>
- </TouchableWithoutFeedback>
- </KeyboardAvoidingView>
- </TouchableWithoutFeedback>
- </Modal>
+ <TouchableOpacity
+ style={[styles.saveButton, isSubmitting && styles.saveButtonDisabled]}
+ onPress={handleSubmit}
+ disabled={isSubmitting}
+ >
+ {isSubmitting ? (
+ <ActivityIndicator color="#FFFFFF" size="small" />
+ ) : (
+ <Text style={styles.saveButtonText}>
+ {mode === 'create' ? t('common.add') : t('common.save')}
+ </Text>
+ )}
+ </TouchableOpacity>
+ </View>
+ </ModalWrapper>
);
};
diff --git a/apps/mobile-app/components/folders/FolderSelector.tsx b/apps/mobile-app/components/folders/FolderSelector.tsx
index e561af841..b73aaae4b 100644
--- a/apps/mobile-app/components/folders/FolderSelector.tsx
+++ b/apps/mobile-app/components/folders/FolderSelector.tsx
@@ -2,16 +2,15 @@ import MaterialIcons from '@expo/vector-icons/MaterialIcons';
import React, { useState, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import {
- Modal,
StyleSheet,
Text,
TouchableOpacity,
- TouchableWithoutFeedback,
View,
ScrollView,
} from 'react-native';
-import { useColors, useColorScheme } from '@/hooks/useColorScheme';
+import { useColors } from '@/hooks/useColorScheme';
+import { ModalWrapper } from '@/components/common/ModalWrapper';
type Folder = {
Id: string;
@@ -37,7 +36,6 @@ export const FolderSelector: React.FC<IFolderSelectorProps> = ({
}) => {
const { t } = useTranslation();
const colors = useColors();
- const colorScheme = useColorScheme();
const [showModal, setShowModal] = useState(false);
const selectedFolder = folders.find(f => f.Id === selectedFolderId);
@@ -51,12 +49,6 @@ export const FolderSelector: React.FC<IFolderSelectorProps> = ({
}, [onFolderChange]);
const styles = StyleSheet.create({
- backdrop: {
- alignItems: 'center',
- backgroundColor: colorScheme === 'dark' ? 'rgba(255, 255, 255, 0.15)' : 'rgba(0, 0, 0, 0.5)',
- flex: 1,
- justifyContent: 'center',
- },
button: {
alignItems: 'center',
backgroundColor: selectedFolderId ? colors.tint + '20' : colors.accentBackground,
@@ -76,17 +68,8 @@ export const FolderSelector: React.FC<IFolderSelectorProps> = ({
closeButton: {
padding: 4,
position: 'absolute',
- right: 16,
- top: 16,
- },
- container: {
- backgroundColor: colors.background,
- borderRadius: 12,
- marginHorizontal: 20,
- maxHeight: '70%',
- maxWidth: 400,
- padding: 20,
- width: '90%',
+ right: 0,
+ top: 0,
},
folderOption: {
alignItems: 'center',
@@ -114,20 +97,97 @@ export const FolderSelector: React.FC<IFolderSelectorProps> = ({
fontWeight: '500',
marginBottom: 6,
},
- optionsList: {
- marginTop: 16,
+ modalHeader: {
+ alignItems: 'center',
+ flexDirection: 'row',
+ justifyContent: 'space-between',
+ marginBottom: 16,
},
- title: {
+ modalTitle: {
color: colors.text,
fontSize: 18,
fontWeight: '600',
- marginBottom: 4,
+ },
+ optionsList: {
+ maxHeight: 300,
},
wrapper: {
marginBottom: 16,
},
});
+ const modalContent = (
+ <>
+ <View style={styles.modalHeader}>
+ <Text style={styles.modalTitle}>{t('items.folders.selectFolder')}</Text>
+ <TouchableOpacity
+ style={styles.closeButton}
+ onPress={() => setShowModal(false)}
+ >
+ <MaterialIcons name="close" size={24} color={colors.textMuted} />
+ </TouchableOpacity>
+ </View>
+
+ <ScrollView style={styles.optionsList}>
+ {/* No folder option */}
+ <TouchableOpacity
+ style={[
+ styles.folderOption,
+ !selectedFolderId && styles.folderOptionActive,
+ ]}
+ onPress={() => handleSelectFolder(null)}
+ >
+ <MaterialIcons
+ name="folder-open"
+ size={22}
+ color={!selectedFolderId ? colors.tint : colors.textMuted}
+ />
+ <Text
+ style={[
+ styles.folderOptionText,
+ !selectedFolderId && styles.folderOptionTextActive,
+ ]}
+ >
+ {t('items.folders.noFolder')}
+ </Text>
+ {!selectedFolderId && (
+ <MaterialIcons name="check" size={20} color={colors.tint} />
+ )}
+ </TouchableOpacity>
+
+ {/* Folder options */}
+ {folders.map(folder => (
+ <TouchableOpacity
+ key={folder.Id}
+ style={[
+ styles.folderOption,
+ selectedFolderId === folder.Id && styles.folderOptionActive,
+ ]}
+ onPress={() => handleSelectFolder(folder.Id)}
+ >
+ <MaterialIcons
+ name="folder"
+ size={22}
+ color={selectedFolderId === folder.Id ? colors.tint : colors.textMuted}
+ />
+ <Text
+ style={[
+ styles.folderOptionText,
+ selectedFolderId === folder.Id && styles.folderOptionTextActive,
+ ]}
+ numberOfLines={1}
+ >
+ {folder.Name}
+ </Text>
+ {selectedFolderId === folder.Id && (
+ <MaterialIcons name="check" size={20} color={colors.tint} />
+ )}
+ </TouchableOpacity>
+ ))}
+ </ScrollView>
+ </>
+ );
+
return (
<View style={styles.wrapper}>
<Text style={styles.label}>{t('items.folders.folder')}</Text>
@@ -151,87 +211,14 @@ export const FolderSelector: React.FC<IFolderSelectorProps> = ({
/>
</TouchableOpacity>
- <Modal
- visible={showModal}
- transparent
- animationType="fade"
- onRequestClose={() => setShowModal(false)}
+ <ModalWrapper
+ isOpen={showModal}
+ onClose={() => setShowModal(false)}
+ showHeaderBorder={false}
+ showFooterBorder={false}
>
- <TouchableWithoutFeedback onPress={() => setShowModal(false)}>
- <View style={styles.backdrop}>
- <TouchableWithoutFeedback>
- <View style={styles.container}>
- <Text style={styles.title}>{t('items.folders.selectFolder')}</Text>
-
- <TouchableOpacity
- style={styles.closeButton}
- onPress={() => setShowModal(false)}
- >
- <MaterialIcons name="close" size={24} color={colors.textMuted} />
- </TouchableOpacity>
-
- <ScrollView style={styles.optionsList}>
- {/* No folder option */}
- <TouchableOpacity
- style={[
- styles.folderOption,
- !selectedFolderId && styles.folderOptionActive,
- ]}
- onPress={() => handleSelectFolder(null)}
- >
- <MaterialIcons
- name="folder-open"
- size={22}
- color={!selectedFolderId ? colors.tint : colors.textMuted}
- />
- <Text
- style={[
- styles.folderOptionText,
- !selectedFolderId && styles.folderOptionTextActive,
- ]}
- >
- {t('items.folders.noFolder')}
- </Text>
- {!selectedFolderId && (
- <MaterialIcons name="check" size={20} color={colors.tint} />
- )}
- </TouchableOpacity>
-
- {/* Folder options */}
- {folders.map(folder => (
- <TouchableOpacity
- key={folder.Id}
- style={[
- styles.folderOption,
- selectedFolderId === folder.Id && styles.folderOptionActive,
- ]}
- onPress={() => handleSelectFolder(folder.Id)}
- >
- <MaterialIcons
- name="folder"
- size={22}
- color={selectedFolderId === folder.Id ? colors.tint : colors.textMuted}
- />
- <Text
- style={[
- styles.folderOptionText,
- selectedFolderId === folder.Id && styles.folderOptionTextActive,
- ]}
- numberOfLines={1}
- >
- {folder.Name}
- </Text>
- {selectedFolderId === folder.Id && (
- <MaterialIcons name="check" size={20} color={colors.tint} />
- )}
- </TouchableOpacity>
- ))}
- </ScrollView>
- </View>
- </TouchableWithoutFeedback>
- </View>
- </TouchableWithoutFeedback>
- </Modal>
+ {modalContent}
+ </ModalWrapper>
</View>
);
};
diff --git a/apps/mobile-app/components/form/AddFieldMenu.tsx b/apps/mobile-app/components/form/AddFieldMenu.tsx
index 6dec8db94..cccd9b586 100644
--- a/apps/mobile-app/components/form/AddFieldMenu.tsx
+++ b/apps/mobile-app/components/form/AddFieldMenu.tsx
@@ -18,6 +18,7 @@ import { useColors } from '@/hooks/useColorScheme';
import { ThemedText } from '@/components/themed/ThemedText';
import { RobustPressable } from '@/components/ui/RobustPressable';
+import { ModalWrapper } from '@/components/common/ModalWrapper';
/**
* Configuration for an optional section (not field-based).
@@ -155,6 +156,7 @@ export const AddFieldMenu: React.FC<AddFieldMenuProps> = ({
customFieldModalButtons: {
flexDirection: 'row',
gap: 12,
+ marginTop: 16,
},
customFieldModalButton: {
alignItems: 'center',
@@ -179,11 +181,6 @@ export const AddFieldMenu: React.FC<AddFieldMenuProps> = ({
customFieldModalButtonTextSecondary: {
color: colors.text,
},
- customFieldModalContent: {
- backgroundColor: colors.background,
- borderRadius: 12,
- padding: 20,
- },
customFieldModalInput: {
backgroundColor: colors.accentBackground,
borderColor: colors.accentBorder,
@@ -201,12 +198,6 @@ export const AddFieldMenu: React.FC<AddFieldMenuProps> = ({
fontWeight: '600',
marginBottom: 8,
},
- customFieldModalOverlay: {
- backgroundColor: 'rgba(0, 0, 0, 0.5)',
- flex: 1,
- justifyContent: 'center',
- padding: 20,
- },
fieldTypeChip: {
backgroundColor: colors.accentBackground,
borderColor: colors.accentBorder,
@@ -232,14 +223,7 @@ export const AddFieldMenu: React.FC<AddFieldMenuProps> = ({
paddingBottom: 16,
},
fieldTypeScrollView: {
- marginBottom: 16,
- },
- customFieldModalTitle: {
- color: colors.text,
- fontSize: 18,
- fontWeight: '700',
- marginBottom: 16,
- textAlign: 'center',
+ marginBottom: 0,
},
menuContainer: {
backgroundColor: colors.background,
@@ -352,6 +336,79 @@ export const AddFieldMenu: React.FC<AddFieldMenuProps> = ({
return options;
}, [optionalSystemFields, visibleFieldKeys, optionalSections, t, handleAddSystemField, handleAddSection]);
+ const customFieldModalContent = (
+ <>
+ <ThemedText style={styles.customFieldModalLabel}>
+ {t('itemTypes.fieldLabel')}
+ </ThemedText>
+ <TextInput
+ style={styles.customFieldModalInput}
+ value={customFieldLabel}
+ onChangeText={setCustomFieldLabel}
+ placeholder={t('itemTypes.enterFieldName')}
+ placeholderTextColor={colors.textMuted}
+ autoFocus
+ />
+
+ <ThemedText style={styles.customFieldModalLabel}>
+ {t('itemTypes.fieldType')}
+ </ThemedText>
+ <ScrollView
+ horizontal
+ showsHorizontalScrollIndicator={false}
+ style={styles.fieldTypeScrollView}
+ contentContainerStyle={styles.fieldTypeContainer}
+ >
+ {FIELD_TYPE_OPTIONS.map(option => (
+ <TouchableOpacity
+ key={option.value}
+ style={[
+ styles.fieldTypeChip,
+ customFieldType === option.value && styles.fieldTypeChipSelected,
+ ]}
+ onPress={() => setCustomFieldType(option.value as FieldType)}
+ activeOpacity={0.7}
+ >
+ <ThemedText
+ style={[
+ styles.fieldTypeChipText,
+ customFieldType === option.value && styles.fieldTypeChipTextSelected,
+ ]}
+ >
+ {t(option.labelKey)}
+ </ThemedText>
+ </TouchableOpacity>
+ ))}
+ </ScrollView>
+
+ <View style={styles.customFieldModalButtons}>
+ <TouchableOpacity
+ style={[styles.customFieldModalButton, styles.customFieldModalButtonSecondary]}
+ onPress={handleCloseCustomFieldModal}
+ activeOpacity={0.7}
+ >
+ <ThemedText style={[styles.customFieldModalButtonText, styles.customFieldModalButtonTextSecondary]}>
+ {t('common.cancel')}
+ </ThemedText>
+ </TouchableOpacity>
+ <TouchableOpacity
+ style={[
+ styles.customFieldModalButton,
+ styles.customFieldModalButtonPrimary,
+ !customFieldLabel.trim() && { opacity: 0.5 },
+ ]}
+ onPress={handleAddCustomField}
+ disabled={!customFieldLabel.trim()}
+ activeOpacity={0.7}
+ >
+ <ThemedText style={[styles.customFieldModalButtonText, styles.customFieldModalButtonTextPrimary]}>
+ {t('common.add')}
+ </ThemedText>
+ </TouchableOpacity>
+ </View>
+ </>
+ );
+
return (
<>
<RobustPressable
@@ -364,7 +421,7 @@ export const AddFieldMenu: React.FC<AddFieldMenuProps> = ({
</ThemedText>
</RobustPressable>
- {/* Main Menu Modal */}
+ {/* Main Menu Modal - Action sheet style, slides from bottom */}
<Modal
visible={isOpen}
transparent
@@ -416,94 +473,17 @@ export const AddFieldMenu: React.FC<AddFieldMenuProps> = ({
</TouchableWithoutFeedback>
</Modal>
- {/* Custom Field Modal */}
- <Modal
- visible={showCustomFieldModal}
- transparent
- animationType="fade"
- onRequestClose={handleCloseCustomFieldModal}
+ {/* Custom Field Modal - Uses ModalWrapper for centered dialog */}
+ <ModalWrapper
+ isOpen={showCustomFieldModal}
+ onClose={handleCloseCustomFieldModal}
+ title={t('itemTypes.addCustomField')}
+ keyboardAvoiding
+ showHeaderBorder={false}
+ showFooterBorder={false}
>
- <TouchableWithoutFeedback onPress={handleCloseCustomFieldModal}>
- <View style={styles.customFieldModalOverlay}>
- <TouchableWithoutFeedback>
- <View style={styles.customFieldModalContent}>
- <ThemedText style={styles.customFieldModalTitle}>
- {t('itemTypes.addCustomField')}
- </ThemedText>
-
- <ThemedText style={styles.customFieldModalLabel}>
- {t('itemTypes.fieldLabel')}
- </ThemedText>
- <TextInput
- style={styles.customFieldModalInput}
- value={customFieldLabel}
- onChangeText={setCustomFieldLabel}
- placeholder={t('itemTypes.enterFieldName')}
- placeholderTextColor={colors.textMuted}
- autoFocus
- />
-
- <ThemedText style={styles.customFieldModalLabel}>
- {t('itemTypes.fieldType')}
- </ThemedText>
- <ScrollView
- horizontal
- showsHorizontalScrollIndicator={false}
- style={styles.fieldTypeScrollView}
- contentContainerStyle={styles.fieldTypeContainer}
- >
- {FIELD_TYPE_OPTIONS.map(option => (
- <TouchableOpacity
- key={option.value}
- style={[
- styles.fieldTypeChip,
- customFieldType === option.value && styles.fieldTypeChipSelected,
- ]}
- onPress={() => setCustomFieldType(option.value as FieldType)}
- activeOpacity={0.7}
- >
- <ThemedText
- style={[
- styles.fieldTypeChipText,
- customFieldType === option.value && styles.fieldTypeChipTextSelected,
- ]}
- >
- {t(option.labelKey)}
- </ThemedText>
- </TouchableOpacity>
- ))}
- </ScrollView>
-
- <View style={styles.customFieldModalButtons}>
- <TouchableOpacity
- style={[styles.customFieldModalButton, styles.customFieldModalButtonSecondary]}
- onPress={handleCloseCustomFieldModal}
- activeOpacity={0.7}
- >
- <ThemedText style={[styles.customFieldModalButtonText, styles.customFieldModalButtonTextSecondary]}>
- {t('common.cancel')}
- </ThemedText>
- </TouchableOpacity>
- <TouchableOpacity
- style={[
- styles.customFieldModalButton,
- styles.customFieldModalButtonPrimary,
- !customFieldLabel.trim() && { opacity: 0.5 },
- ]}
- onPress={handleAddCustomField}
- disabled={!customFieldLabel.trim()}
- activeOpacity={0.7}
- >
- <ThemedText style={[styles.customFieldModalButtonText, styles.customFieldModalButtonTextPrimary]}>
- {t('common.add')}
- </ThemedText>
- </TouchableOpacity>
- </View>
- </View>
- </TouchableWithoutFeedback>
- </View>
- </TouchableWithoutFeedback>
- </Modal>
+ {customFieldModalContent}
+ </ModalWrapper>
</>
);
};
diff --git a/apps/mobile-app/components/form/AdvancedPasswordField.tsx b/apps/mobile-app/components/form/AdvancedPasswordField.tsx
index 1f538f50f..2c16a62f8 100644
--- a/apps/mobile-app/components/form/AdvancedPasswordField.tsx
+++ b/apps/mobile-app/components/form/AdvancedPasswordField.tsx
@@ -2,7 +2,7 @@ import { MaterialIcons } from '@expo/vector-icons';
import Slider from '@react-native-community/slider';
import React, { forwardRef, useImperativeHandle, useMemo, useRef, useState, useCallback, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
-import { View, TextInput, TextInputProps, StyleSheet, TouchableOpacity, Platform, Modal, ScrollView, Switch } from 'react-native';
+import { View, TextInput, TextInputProps, StyleSheet, TouchableOpacity, Platform, ScrollView, Switch } from 'react-native';
import type { PasswordSettings } from '@/utils/dist/core/models/vault';
import { CreatePasswordGenerator } from '@/utils/dist/core/password-generator';
@@ -11,6 +11,7 @@ import { useColors } from '@/hooks/useColorScheme';
import { ThemedText } from '@/components/themed/ThemedText';
import { useDb } from '@/context/DbContext';
+import { ModalWrapper } from '@/components/common/ModalWrapper';
export type AdvancedPasswordFieldRef = {
focus: () => void;
@@ -243,26 +244,12 @@ const AdvancedPasswordFieldComponent = forwardRef<AdvancedPasswordFieldRef, Adva
removeButton: {
padding: 4,
},
- modalContent: {
- backgroundColor: colors.accentBackground,
- borderRadius: 12,
- maxHeight: '80%',
- maxWidth: 400,
- padding: 20,
- width: '90%',
- },
modalHeader: {
alignItems: 'center',
flexDirection: 'row',
justifyContent: 'space-between',
marginBottom: 20,
},
- modalOverlay: {
- alignItems: 'center',
- backgroundColor: 'rgba(0, 0, 0, 0.8)',
- flex: 1,
- justifyContent: 'center',
- },
modalTitle: {
color: colors.text,
fontSize: 18,
@@ -360,6 +347,101 @@ const AdvancedPasswordFieldComponent = forwardRef<AdvancedPasswordFieldRef, Adva
const showClearButton = Platform.OS === 'android' && value && value.length > 0;
+ const settingsModalContent = (
+ <>
+ <View style={styles.modalHeader}>
+ <ThemedText style={styles.modalTitle}>{t('items.changePasswordComplexity')}</ThemedText>
+ <TouchableOpacity
+ style={styles.closeButton}
+ onPress={() => setShowSettingsModal(false)}
+ activeOpacity={0.7}
+ >
+ <MaterialIcons name="close" size={24} color={colors.textMuted} />
+ </TouchableOpacity>
+ </View>
+
+ <ScrollView showsVerticalScrollIndicator={false}>
+ <View style={styles.previewContainer}>
+ <View style={styles.previewInputContainer}>
+ <TextInput
+ style={styles.previewInput}
+ value={previewPassword}
+ editable={false}
+ />
+ <TouchableOpacity
+ style={styles.refreshButton}
+ onPress={handleRefreshPreview}
+ activeOpacity={0.7}
+ >
+ <MaterialIcons name="refresh" size={20} color={colors.primary} />
+ </TouchableOpacity>
+ </View>
+ </View>
+
+ <View style={styles.settingsSection}>
+ <View style={styles.settingItem}>
+ <ThemedText style={styles.settingLabel}>{t('items.includeLowercase')}</ThemedText>
+ <Switch
+ value={currentSettings?.UseLowercase ?? true}
+ onValueChange={(settingValue) => updateSetting('UseLowercase', settingValue)}
+ trackColor={{ false: colors.accentBorder, true: colors.primary }}
+ thumbColor={Platform.OS === 'android' ? colors.background : undefined}
+ />
+ </View>
+
+ <View style={styles.settingItem}>
+ <ThemedText style={styles.settingLabel}>{t('items.includeUppercase')}</ThemedText>
+ <Switch
+ value={currentSettings?.UseUppercase ?? true}
+ onValueChange={(settingValue) => updateSetting('UseUppercase', settingValue)}
+ trackColor={{ false: colors.accentBorder, true: colors.primary }}
+ thumbColor={Platform.OS === 'android' ? colors.background : undefined}
+ />
+ </View>
+
+ <View style={styles.settingItem}>
+ <ThemedText style={styles.settingLabel}>{t('items.includeNumbers')}</ThemedText>
+ <Switch
+ value={currentSettings?.UseNumbers ?? true}
+ onValueChange={(settingValue) => updateSetting('UseNumbers', settingValue)}
+ trackColor={{ false: colors.accentBorder, true: colors.primary }}
+ thumbColor={Platform.OS === 'android' ? colors.background : undefined}
+ />
+ </View>
+
+ <View style={styles.settingItem}>
+ <ThemedText style={styles.settingLabel}>{t('items.includeSpecialChars')}</ThemedText>
+ <Switch
+ value={currentSettings?.UseSpecialChars ?? true}
+ onValueChange={(settingValue) => updateSetting('UseSpecialChars', settingValue)}
+ trackColor={{ false: colors.accentBorder, true: colors.primary }}
+ thumbColor={Platform.OS === 'android' ? colors.background : undefined}
+ />
+ </View>
+
+ <View style={styles.settingItem}>
+ <ThemedText style={styles.settingLabel}>{t('items.avoidAmbiguousChars')}</ThemedText>
+ <Switch
+ value={currentSettings?.UseNonAmbiguousChars ?? false}
+ onValueChange={(settingValue) => updateSetting('UseNonAmbiguousChars', settingValue)}
+ trackColor={{ false: colors.accentBorder, true: colors.primary }}
+ thumbColor={Platform.OS === 'android' ? colors.background : undefined}
+ />
+ </View>
+ </View>
+
+ <TouchableOpacity
+ style={styles.useButton}
+ onPress={handleUsePassword}
+ activeOpacity={0.7}
+ >
+ <MaterialIcons name="keyboard-arrow-down" size={20} color={colors.text} />
+ <ThemedText style={styles.useButtonText}>{t('common.use')}</ThemedText>
+ </TouchableOpacity>
+ </ScrollView>
+ </>
+ );
+
return (
<View style={styles.inputGroup}>
<View style={styles.labelContainer}>
@@ -455,107 +537,14 @@ const AdvancedPasswordFieldComponent = forwardRef<AdvancedPasswordFieldRef, Adva
/>
</View>
- <Modal
- visible={showSettingsModal}
- transparent
- animationType="fade"
- onRequestClose={() => setShowSettingsModal(false)}
+ <ModalWrapper
+ isOpen={showSettingsModal}
+ onClose={() => setShowSettingsModal(false)}
+ showHeaderBorder={false}
+ showFooterBorder={false}
>
- <View style={styles.modalOverlay}>
- <View style={styles.modalContent}>
- <View style={styles.modalHeader}>
- <ThemedText style={styles.modalTitle}>{t('items.changePasswordComplexity')}</ThemedText>
- <TouchableOpacity
- style={styles.closeButton}
- onPress={() => setShowSettingsModal(false)}
- activeOpacity={0.7}
- >
- <MaterialIcons name="close" size={24} color={colors.textMuted} />
- </TouchableOpacity>
- </View>
-
- <ScrollView showsVerticalScrollIndicator={false}>
- <View style={styles.previewContainer}>
- <View style={styles.previewInputContainer}>
- <TextInput
- style={styles.previewInput}
- value={previewPassword}
- editable={false}
- />
- <TouchableOpacity
- style={styles.refreshButton}
- onPress={handleRefreshPreview}
- activeOpacity={0.7}
- >
- <MaterialIcons name="refresh" size={20} color={colors.primary} />
- </TouchableOpacity>
- </View>
- </View>
-
- <View style={styles.settingsSection}>
- <View style={styles.settingItem}>
- <ThemedText style={styles.settingLabel}>{t('items.includeLowercase')}</ThemedText>
- <Switch
- value={currentSettings?.UseLowercase ?? true}
- onValueChange={(settingValue) => updateSetting('UseLowercase', settingValue)}
- trackColor={{ false: colors.accentBorder, true: colors.primary }}
- thumbColor={Platform.OS === 'android' ? colors.background : undefined}
- />
- </View>
-
- <View style={styles.settingItem}>
- <ThemedText style={styles.settingLabel}>{t('items.includeUppercase')}</ThemedText>
- <Switch
- value={currentSettings?.UseUppercase ?? true}
- onValueChange={(settingValue) => updateSetting('UseUppercase', settingValue)}
- trackColor={{ false: colors.accentBorder, true: colors.primary }}
- thumbColor={Platform.OS === 'android' ? colors.background : undefined}
- />
- </View>
-
- <View style={styles.settingItem}>
- <ThemedText style={styles.settingLabel}>{t('items.includeNumbers')}</ThemedText>
- <Switch
- value={currentSettings?.UseNumbers ?? true}
- onValueChange={(settingValue) => updateSetting('UseNumbers', settingValue)}
- trackColor={{ false: colors.accentBorder, true: colors.primary }}
- thumbColor={Platform.OS === 'android' ? colors.background : undefined}
- />
- </View>
-
- <View style={styles.settingItem}>
- <ThemedText style={styles.settingLabel}>{t('items.includeSpecialChars')}</ThemedText>
- <Switch
- value={currentSettings?.UseSpecialChars ?? true}
- onValueChange={(settingValue) => updateSetting('UseSpecialChars', settingValue)}
- trackColor={{ false: colors.accentBorder, true: colors.primary }}
- thumbColor={Platform.OS === 'android' ? colors.background : undefined}
- />
- </View>
-
- <View style={styles.settingItem}>
- <ThemedText style={styles.settingLabel}>{t('items.avoidAmbiguousChars')}</ThemedText>
- <Switch
- value={currentSettings?.UseNonAmbiguousChars ?? false}
- onValueChange={(settingValue) => updateSetting('UseNonAmbiguousChars', settingValue)}
- trackColor={{ false: colors.accentBorder, true: colors.primary }}
- thumbColor={Platform.OS === 'android' ? colors.background : undefined}
- />
- </View>
- </View>
-
- <TouchableOpacity
- style={styles.useButton}
- onPress={handleUsePassword}
- activeOpacity={0.7}
- >
- <MaterialIcons name="keyboard-arrow-down" size={20} color={colors.text} />
- <ThemedText style={styles.useButtonText}>{t('common.use')}</ThemedText>
- </TouchableOpacity>
- </ScrollView>
- </View>
- </View>
- </Modal>
+ {settingsModalContent}
+ </ModalWrapper>
</View>
);
});
diff --git a/apps/mobile-app/components/items/ConfirmDeleteModal.tsx b/apps/mobile-app/components/items/ConfirmDeleteModal.tsx
index 60fc42809..10403476c 100644
--- a/apps/mobile-app/components/items/ConfirmDeleteModal.tsx
+++ b/apps/mobile-app/components/items/ConfirmDeleteModal.tsx
@@ -1,7 +1,6 @@
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import {
- Modal,
StyleSheet,
Text,
TouchableOpacity,
@@ -9,7 +8,8 @@ import {
ActivityIndicator,
} from 'react-native';
-import { useColors, useColorScheme } from '@/hooks/useColorScheme';
+import { useColors } from '@/hooks/useColorScheme';
+import { ModalWrapper } from '@/components/common/ModalWrapper';
interface IConfirmDeleteModalProps {
isOpen: boolean;
@@ -33,7 +33,6 @@ export const ConfirmDeleteModal: React.FC<IConfirmDeleteModalProps> = ({
}) => {
const { t } = useTranslation();
const colors = useColors();
- const colorScheme = useColorScheme();
const [isSubmitting, setIsSubmitting] = useState(false);
/**
@@ -50,46 +49,16 @@ export const ConfirmDeleteModal: React.FC<IConfirmDeleteModalProps> = ({
}
};
- /**
- * Handle close - only allow if not submitting.
- */
- const handleClose = (): void => {
- if (!isSubmitting) {
- onClose();
- }
- };
-
const styles = StyleSheet.create({
- backdrop: {
- alignItems: 'center',
- // Lighter backdrop in dark mode for better contrast against black background
- backgroundColor: colorScheme === 'dark' ? 'rgba(255, 255, 255, 0.15)' : 'rgba(0, 0, 0, 0.5)',
- flex: 1,
- justifyContent: 'center',
- },
- container: {
- backgroundColor: colors.background,
- borderRadius: 12,
- marginHorizontal: 20,
- maxWidth: 400,
- padding: 20,
- width: '90%',
- },
- title: {
- color: colors.text,
- fontSize: 18,
- fontWeight: '600',
- marginBottom: 12,
- },
message: {
color: colors.textMuted,
fontSize: 14,
lineHeight: 20,
- marginBottom: 20,
},
buttonsContainer: {
flexDirection: 'row',
gap: 12,
+ marginTop: 20,
},
cancelButton: {
alignItems: 'center',
@@ -126,45 +95,42 @@ export const ConfirmDeleteModal: React.FC<IConfirmDeleteModalProps> = ({
});
return (
- <Modal
- visible={isOpen}
- transparent
- animationType="fade"
- onRequestClose={handleClose}
+ <ModalWrapper
+ isOpen={isOpen}
+ onClose={onClose}
+ isSubmitting={isSubmitting}
+ title={title}
+ showHeaderBorder={false}
+ showFooterBorder={false}
>
- <View style={styles.backdrop}>
- <View style={styles.container}>
- <Text style={styles.title}>{title}</Text>
- <Text style={styles.message}>{message}</Text>
+ <Text style={styles.message}>{message}</Text>
- <View style={styles.buttonsContainer}>
- <TouchableOpacity
- style={styles.cancelButton}
- onPress={handleClose}
- disabled={isSubmitting}
- >
- <Text style={styles.cancelButtonText}>{t('common.cancel')}</Text>
- </TouchableOpacity>
+ <View style={styles.buttonsContainer}>
+ <TouchableOpacity
+ style={styles.cancelButton}
+ onPress={onClose}
+ disabled={isSubmitting}
+ >
+ <Text style={styles.cancelButtonText}>{t('common.cancel')}</Text>
+ </TouchableOpacity>
- <TouchableOpacity
- style={[
- styles.confirmButton,
- isSubmitting && styles.confirmButtonDisabled
- ]}
- onPress={handleConfirm}
- disabled={isSubmitting}
- >
- {isSubmitting && (
- <ActivityIndicator size="small" color={colors.white} />
- )}
- <Text style={styles.confirmButtonText}>
- {confirmText || t('common.delete')}
- </Text>
- </TouchableOpacity>
- </View>
- </View>
+ <TouchableOpacity
+ style={[
+ styles.confirmButton,
+ isSubmitting && styles.confirmButtonDisabled
+ ]}
+ onPress={handleConfirm}
+ disabled={isSubmitting}
+ >
+ {isSubmitting && (
+ <ActivityIndicator size="small" color={colors.white} />
+ )}
+ <Text style={styles.confirmButtonText}>
+ {confirmText || t('common.delete')}
+ </Text>
+ </TouchableOpacity>
</View>
- </Modal>
+ </ModalWrapper>
);
};
diff --git a/apps/mobile-app/components/items/FieldHistoryModal.tsx b/apps/mobile-app/components/items/FieldHistoryModal.tsx
index 3511bb357..79e3807fd 100644
--- a/apps/mobile-app/components/items/FieldHistoryModal.tsx
+++ b/apps/mobile-app/components/items/FieldHistoryModal.tsx
@@ -2,12 +2,10 @@ import { MaterialIcons } from '@expo/vector-icons';
import React, { useState, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import {
- Modal,
StyleSheet,
Text,
View,
ActivityIndicator,
- ScrollView,
TouchableOpacity,
} from 'react-native';
import Toast from 'react-native-toast-message';
@@ -15,10 +13,11 @@ import Toast from 'react-native-toast-message';
import type { FieldHistory, FieldType } from '@/utils/dist/core/models/vault';
import { FieldTypes } from '@/utils/dist/core/models/vault';
-import { useColors, useColorScheme } from '@/hooks/useColorScheme';
+import { useColors } from '@/hooks/useColorScheme';
import { useDb } from '@/context/DbContext';
import { copyToClipboardWithExpiration } from '@/utils/ClipboardUtility';
import { useAuth } from '@/context/AuthContext';
+import { ModalWrapper } from '@/components/common/ModalWrapper';
type FieldHistoryModalProps = {
isOpen: boolean;
@@ -47,7 +46,6 @@ const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({
}) => {
const { t } = useTranslation();
const colors = useColors();
- const colorScheme = useColorScheme();
const dbContext = useDb();
const { getClipboardClearTimeout } = useAuth();
const [history, setHistory] = useState<FieldHistory[]>([]);
@@ -109,34 +107,6 @@ const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({
};
const styles = StyleSheet.create({
- backdrop: {
- alignItems: 'center',
- // Lighter backdrop in dark mode for better contrast against black background
- backgroundColor: colorScheme === 'dark' ? 'rgba(255, 255, 255, 0.15)' : 'rgba(0, 0, 0, 0.5)',
- flex: 1,
- justifyContent: 'center',
- },
- container: {
- backgroundColor: colors.background,
- borderRadius: 12,
- marginHorizontal: 16,
- maxHeight: '80%',
- width: '95%',
- },
- header: {
- borderBottomColor: colors.accentBorder,
- borderBottomWidth: 1,
- padding: 20,
- },
- title: {
- color: colors.text,
- fontSize: 18,
- fontWeight: '600',
- },
- body: {
- maxHeight: 400,
- padding: 20,
- },
loadingContainer: {
alignItems: 'center',
justifyContent: 'center',
@@ -188,11 +158,6 @@ const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({
iconButton: {
padding: 4,
},
- footer: {
- borderTopColor: colors.accentBorder,
- borderTopWidth: 1,
- padding: 16,
- },
closeButton: {
alignItems: 'center',
backgroundColor: colors.accentBackground,
@@ -208,127 +173,132 @@ const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({
},
});
- return (
- <Modal
- visible={isOpen}
- transparent
- animationType="fade"
- onRequestClose={onClose}
- >
- <View style={styles.backdrop}>
- <View style={styles.container}>
- <View style={styles.header}>
- <Text style={styles.title}>{fieldLabel} {t('items.history')}</Text>
- </View>
+ const renderContent = (): React.ReactNode => {
+ if (loading) {
+ return (
+ <View style={styles.loadingContainer}>
+ <ActivityIndicator size="large" color={colors.primary} />
+ </View>
+ );
+ }
- <ScrollView style={styles.body}>
- {loading ? (
- <View style={styles.loadingContainer}>
- <ActivityIndicator size="large" color={colors.primary} />
- </View>
- ) : history.length === 0 ? (
- <View style={styles.emptyContainer}>
- <Text style={styles.emptyText}>
- {t('items.noHistoryAvailable')}
+ if (history.length === 0) {
+ return (
+ <View style={styles.emptyContainer}>
+ <Text style={styles.emptyText}>
+ {t('items.noHistoryAvailable')}
+ </Text>
+ </View>
+ );
+ }
+
+ return (
+ <View>
+ {history.map((record) => {
+ const values = parseValueSnapshot(record.ValueSnapshot);
+
+ return (
+ <View key={record.Id} style={styles.historyItem}>
+ <View style={styles.historyHeader}>
+ <Text style={styles.historyDate}>
+ {formatDate(record.ChangedAt)}
</Text>
</View>
- ) : (
- <View>
- {history.map((record) => {
- const values = parseValueSnapshot(record.ValueSnapshot);
-
- return (
- <View key={record.Id} style={styles.historyItem}>
- <View style={styles.historyHeader}>
- <Text style={styles.historyDate}>
- {formatDate(record.ChangedAt)}
- </Text>
- </View>
- {values.map((value, idx) => {
- const valueId = `${record.Id}-${idx}`;
- const isVisible = visibleValues.has(valueId);
- const displayValue = shouldMaskByDefault && !isVisible
- ? '•'.repeat(value.length)
- : value;
+ {values.map((value, idx) => {
+ const valueId = `${record.Id}-${idx}`;
+ const isVisible = visibleValues.has(valueId);
+ const displayValue = shouldMaskByDefault && !isVisible
+ ? '•'.repeat(value.length)
+ : value;
- const handleCopy = async (): Promise<void> => {
- try {
- const timeoutSeconds = await getClipboardClearTimeout();
- await copyToClipboardWithExpiration(value, timeoutSeconds);
- Toast.show({
- type: 'success',
- text1: t('common.copied'),
- position: 'bottom',
- visibilityTime: 2000,
- });
- } catch (error) {
- console.error('Failed to copy:', error);
- }
- };
+ const handleCopy = async (): Promise<void> => {
+ try {
+ const timeoutSeconds = await getClipboardClearTimeout();
+ await copyToClipboardWithExpiration(value, timeoutSeconds);
+ Toast.show({
+ type: 'success',
+ text1: t('common.copied'),
+ position: 'bottom',
+ visibilityTime: 2000,
+ });
+ } catch (error) {
+ console.error('Failed to copy:', error);
+ }
+ };
- const toggleVisibility = (): void => {
- setVisibleValues(prev => {
- const newSet = new Set(prev);
- if (newSet.has(valueId)) {
- newSet.delete(valueId);
- } else {
- newSet.add(valueId);
- }
- return newSet;
- });
- };
+ const toggleVisibility = (): void => {
+ setVisibleValues(prev => {
+ const newSet = new Set(prev);
+ if (newSet.has(valueId)) {
+ newSet.delete(valueId);
+ } else {
+ newSet.add(valueId);
+ }
+ return newSet;
+ });
+ };
- return (
- <View key={idx} style={styles.historyValue}>
- <Text style={styles.valueText} numberOfLines={1} ellipsizeMode="tail">
- {displayValue}
- </Text>
- <View style={styles.actions}>
- {shouldMaskByDefault && (
- <TouchableOpacity
- onPress={toggleVisibility}
- style={styles.iconButton}
- >
- <MaterialIcons
- name={isVisible ? 'visibility-off' : 'visibility'}
- size={20}
- color={colors.primary}
- />
- </TouchableOpacity>
- )}
- <TouchableOpacity
- onPress={handleCopy}
- style={styles.iconButton}
- >
- <MaterialIcons
- name="content-copy"
- size={18}
- color={colors.textMuted}
- />
- </TouchableOpacity>
- </View>
- </View>
- );
- })}
+ return (
+ <View key={idx} style={styles.historyValue}>
+ <Text style={styles.valueText} numberOfLines={1} ellipsizeMode="tail">
+ {displayValue}
+ </Text>
+ <View style={styles.actions}>
+ {shouldMaskByDefault && (
+ <TouchableOpacity
+ onPress={toggleVisibility}
+ style={styles.iconButton}
+ >
+ <MaterialIcons
+ name={isVisible ? 'visibility-off' : 'visibility'}
+ size={20}
+ color={colors.primary}
+ />
+ </TouchableOpacity>
+ )}
+ <TouchableOpacity
+ onPress={handleCopy}
+ style={styles.iconButton}
+ >
+ <MaterialIcons
+ name="content-copy"
+ size={18}
+ color={colors.textMuted}
+ />
+ </TouchableOpacity>
</View>
- );
- })}
- </View>
- )}
- </ScrollView>
-
- <View style={styles.footer}>
- <TouchableOpacity
- style={styles.closeButton}
- onPress={onClose}
- >
- <Text style={styles.closeButtonText}>{t('common.close')}</Text>
- </TouchableOpacity>
- </View>
- </View>
+ </View>
+ );
+ })}
+ </View>
+ );
+ })}
</View>
- </Modal>
+ );
+ };
+
+ const footer = (
+ <TouchableOpacity
+ style={styles.closeButton}
+ onPress={onClose}
+ >
+ <Text style={styles.closeButtonText}>{t('common.close')}</Text>
+ </TouchableOpacity>
+ );
+
+ return (
+ <ModalWrapper
+ isOpen={isOpen}
+ onClose={onClose}
+ title={`${fieldLabel} ${t('items.history')}`}
+ scrollable
+ maxScrollHeight={400}
+ footer={footer}
+ width="95%"
+ >
+ {renderContent()}
+ </ModalWrapper>
);
};