Skip to content
Open
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
19 changes: 9 additions & 10 deletions src/screens/PasswordScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function PinOverlay({ onUnlock, onCancel, title }: { onUnlock: (pin: string) =>
}

// ─── Password Row ─────────────────────────────────────────────────────────────
function PasswordRowComponent({ item, onEdit, onDelete }: { item: PasswordEntry; onEdit: () => void; onDelete: () => void }) {
function PasswordRowComponent({ item, onEdit, onDelete }: { item: PasswordEntry; onEdit: (item: PasswordEntry) => void; onDelete: (id: string) => void }) {
const { colors } = useAppTheme();
const s = useMemo(() => makeRowStyles(colors), [colors]);
const [revealed, setRevealed] = useState(false);
Expand All @@ -120,10 +120,10 @@ function PasswordRowComponent({ item, onEdit, onDelete }: { item: PasswordEntry;
{item.notes ? <Text style={s.notes}>{item.notes}</Text> : null}
</View>
<View style={s.actions}>
<TouchableOpacity style={s.editBtn} onPress={onEdit}>
<TouchableOpacity style={s.editBtn} onPress={() => onEdit(item)}>
<MaterialIcons name="edit" size={17} color={colors.primary} />
</TouchableOpacity>
<TouchableOpacity style={s.delBtn} onPress={onDelete}>
<TouchableOpacity style={s.delBtn} onPress={() => onDelete(item.id)}>
<MaterialIcons name="delete-outline" size={17} color="#EF4444" />
</TouchableOpacity>
</View>
Expand Down Expand Up @@ -255,6 +255,11 @@ export default function PasswordScreen() {
return <PinOverlay title="Imposta PIN (4 cifre)" onUnlock={handlePinSetup} onCancel={() => setPinMode(null)} />;
}

// Performance optimization: stabilize renderItem callback to prevent cascading re-renders of memoized PasswordRow items
const renderItem = useCallback(({ item }: { item: PasswordEntry }) => (
<PasswordRow item={item} onEdit={openEdit} onDelete={deleteEntry} />
), [openEdit, deleteEntry]);

return (
<View style={s.root}>
{/* Toolbar */}
Expand Down Expand Up @@ -284,13 +289,7 @@ export default function PasswordScreen() {
<FlatList
data={entries}
keyExtractor={item => item.id}
renderItem={({ item }) => (
<PasswordRow
item={item}
onEdit={() => openEdit(item)}
onDelete={() => deleteEntry(item.id)}
/>
)}
renderItem={renderItem}
contentContainerStyle={{ padding: 16, paddingBottom: 96 }}
ListEmptyComponent={
<View style={s.empty}>
Expand Down
5 changes: 3 additions & 2 deletions src/screens/PhonebookScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,9 @@ export default function PhonebookScreen() {
});
}, []);

const openAdd = () => { setEditing(null); setModalVisible(true); };
const openEdit = (c: Contact) => { setEditing(c); setModalVisible(true); };
// Performance optimization: stabilize callbacks to prevent unnecessary ContactRow re-renders
const openAdd = useCallback(() => { setEditing(null); setModalVisible(true); }, []);
const openEdit = useCallback((c: Contact) => { setEditing(c); setModalVisible(true); }, []);

// Filter
const filtered = contacts.filter(c => {
Expand Down
Loading