memoize images
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useMemo, useRef, useState } from "react";
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import {
|
||||
FlatList,
|
||||
Image,
|
||||
@@ -66,30 +66,36 @@ const ProjectDropDown = ({
|
||||
})
|
||||
: normalizedProjects;
|
||||
|
||||
const toggleDropdown = () => {
|
||||
const toggleDropdown = useCallback(() => {
|
||||
if (isDisabled) {
|
||||
return;
|
||||
}
|
||||
setIsOpen((prev) => !prev);
|
||||
};
|
||||
}, [isDisabled]);
|
||||
|
||||
const closeDropdown = () => setIsOpen(false);
|
||||
const closeDropdown = useCallback(() => setIsOpen(false), []);
|
||||
|
||||
const handleSelect = (project) => {
|
||||
if (!project?.id) return;
|
||||
onSelectProject?.(project);
|
||||
closeDropdown();
|
||||
};
|
||||
const handleSelect = useCallback(
|
||||
(project) => {
|
||||
if (!project?.id) return;
|
||||
onSelectProject?.(project);
|
||||
closeDropdown();
|
||||
},
|
||||
[closeDropdown, onSelectProject],
|
||||
);
|
||||
|
||||
const handleModify = (project, topPosition) => {
|
||||
if (!project?.id) return;
|
||||
onModifyProject?.(project, topPosition);
|
||||
};
|
||||
const handleModify = useCallback(
|
||||
(project, topPosition) => {
|
||||
if (!project?.id) return;
|
||||
onModifyProject?.(project, topPosition);
|
||||
},
|
||||
[onModifyProject],
|
||||
);
|
||||
|
||||
const handleCreate = () => {
|
||||
const handleCreate = useCallback(() => {
|
||||
onCreateProject?.();
|
||||
closeDropdown();
|
||||
};
|
||||
}, [closeDropdown, onCreateProject]);
|
||||
|
||||
const dropdownWidth = useMemo(
|
||||
() => triggerLayout?.width || 0,
|
||||
@@ -124,35 +130,26 @@ const ProjectDropDown = ({
|
||||
/>
|
||||
</BlurView>
|
||||
|
||||
{isOpen && (
|
||||
<BlurView
|
||||
intensity={BUTTON_BLUR_INTENSITY}
|
||||
tint="dark"
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
left: 0,
|
||||
borderRadius: 16,
|
||||
paddingHorizontal: 8,
|
||||
paddingVertical: 8,
|
||||
gap: 9,
|
||||
maxHeight: 400,
|
||||
zIndex: 4,
|
||||
elevation: 4,
|
||||
width: dropdownWidth || "100%",
|
||||
overflow: "hidden",
|
||||
}}
|
||||
>
|
||||
<ProjectRow
|
||||
isTitle={true}
|
||||
isOpen={isOpen}
|
||||
project={currentProject}
|
||||
formatDate={formatDate}
|
||||
onSelect={toggleDropdown}
|
||||
/>
|
||||
<BlurView
|
||||
intensity={BUTTON_BLUR_INTENSITY}
|
||||
tint="dark"
|
||||
pointerEvents={isOpen ? "auto" : "none"}
|
||||
style={[
|
||||
styles.dropdownOverlay,
|
||||
{ width: dropdownWidth || "100%" },
|
||||
!isOpen && styles.dropdownOverlayHidden,
|
||||
]}
|
||||
>
|
||||
<ProjectRow
|
||||
isTitle={true}
|
||||
isOpen={isOpen}
|
||||
project={currentProject}
|
||||
formatDate={formatDate}
|
||||
onSelect={toggleDropdown}
|
||||
/>
|
||||
|
||||
<View style={styles.dropdownOverlayContent}>
|
||||
<FlatList
|
||||
<View style={styles.dropdownOverlayContent}>
|
||||
<FlatList
|
||||
data={dropdownProjects}
|
||||
keyExtractor={(project, index) =>
|
||||
project?.id || project?.title || `project-${index}`
|
||||
@@ -171,14 +168,13 @@ const ProjectDropDown = ({
|
||||
contentContainerStyle={styles.dropdownListContent}
|
||||
style={styles.dropdownList}
|
||||
/>
|
||||
<GradientButton
|
||||
containerStyle={styles.createButtonContainer}
|
||||
title="Commencer à créer"
|
||||
onPress={handleCreate}
|
||||
/>
|
||||
</View>
|
||||
</BlurView>
|
||||
)}
|
||||
<GradientButton
|
||||
containerStyle={styles.createButtonContainer}
|
||||
title="Commencer à créer"
|
||||
onPress={handleCreate}
|
||||
/>
|
||||
</View>
|
||||
</BlurView>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
@@ -227,6 +223,10 @@ const ProjectRow = ({
|
||||
project?.coverUrl ||
|
||||
project?.coverUri ||
|
||||
(typeof project?.cover === "string" ? project.cover : project?.cover?.uri);
|
||||
const imageSource = useMemo(
|
||||
() => (coverUri ? { uri: coverUri } : img.placeholder),
|
||||
[coverUri],
|
||||
);
|
||||
const title =
|
||||
project?.title || (isEmptyProject ? "Nouvelle musique" : "Sans titre");
|
||||
const formattedDate = !isEmptyProject
|
||||
@@ -245,10 +245,7 @@ const ProjectRow = ({
|
||||
onLayout={(event) => setLayout(event.nativeEvent.layout)}
|
||||
style={styles.projectRowPressable}
|
||||
>
|
||||
<Image
|
||||
source={coverUri ? { uri: coverUri } : img.placeholder}
|
||||
style={styles.projectImage}
|
||||
/>
|
||||
<Image source={imageSource} style={styles.projectImage} />
|
||||
<BlurView tint="dark" style={styles.projectInfo}>
|
||||
<View style={styles.projectTexts}>
|
||||
<Text style={styles.projectTitle} numberOfLines={1}>
|
||||
@@ -306,6 +303,22 @@ const styles = StyleSheet.create({
|
||||
position: "relative",
|
||||
zIndex: 3,
|
||||
},
|
||||
dropdownOverlay: {
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
left: 0,
|
||||
borderRadius: 16,
|
||||
paddingHorizontal: 8,
|
||||
paddingVertical: 8,
|
||||
gap: 9,
|
||||
maxHeight: 400,
|
||||
zIndex: 4,
|
||||
elevation: 4,
|
||||
overflow: "hidden",
|
||||
},
|
||||
dropdownOverlayHidden: {
|
||||
opacity: 0,
|
||||
},
|
||||
dropdownOverlayContent: {
|
||||
maxHeight: 260,
|
||||
width: "100%",
|
||||
|
||||
Reference in New Issue
Block a user