Skip to content

Commit 2001c99

Browse files
committed
fix(mails) coco-4040, fix dynamic height recipient container calculation
1 parent dbab12c commit 2001c99

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

src/framework/modules/mails/components/fields/contact/component.tsx

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import { UI_SIZES } from '~/framework/components/constants';
1212
import { TextInputType } from '~/framework/components/inputs/text/component';
1313
import FlatList from '~/framework/components/list/flat-list';
1414
import { Svg } from '~/framework/components/picture';
15-
import { BodyText, HeadingSText, SmallBoldText, SmallText } from '~/framework/components/text';
15+
import { BodyText, HeadingSText, SmallBoldText, SmallText, TextSizeStyle } from '~/framework/components/text';
1616
import MailsContactItem from '~/framework/modules/mails/components/contact-item';
1717
import stylesContactItem from '~/framework/modules/mails/components/contact-item/styles';
1818
import { MailsRecipientGroupItem, MailsRecipientUserItem } from '~/framework/modules/mails/components/recipient-item';
19+
import { HEIGHT_RECIPIENT_CONTAINER } from '~/framework/modules/mails/components/recipient-item/container/styles';
1920
import { MailsRecipientsType, MailsVisible, MailsVisibleType } from '~/framework/modules/mails/model';
2021
import { readVisibles } from '~/framework/modules/mails/storage';
2122
import { MailsRecipientPrefixsI18n } from '~/framework/modules/mails/util';
@@ -24,7 +25,8 @@ function removeAccents(text: string): string {
2425
return text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
2526
}
2627

27-
const INITIAL_HEIGHT_INPUT = 60;
28+
const HEIGHT_HEADER_RESULTS = UI_SIZES.spacing.small + TextSizeStyle.Normal.lineHeight;
29+
const INITIAL_HEIGHT_INPUT = UI_SIZES.spacing.small * 2 + UI_SIZES.spacing.tiny * 2 + TextSizeStyle.Medium.lineHeight;
2830

2931
export const MailsContactField = (props: MailsContactFieldProps) => {
3032
const [search, setSearch] = React.useState('');
@@ -93,7 +95,6 @@ export const MailsContactField = (props: MailsContactFieldProps) => {
9395
React.useEffect(() => {
9496
if (viewContainerRef.current) {
9597
setTimeout(() => {
96-
// console.log('measure', containerLayout.y, containerLayout.height);
9798
Animated.spring(topPositionResults, {
9899
friction: 8,
99100
tension: 50,
@@ -119,34 +120,22 @@ export const MailsContactField = (props: MailsContactFieldProps) => {
119120
}
120121
}, [containerLayout, props.scrollViewRef, topPositionResults]);
121122

122-
/**
123-
* J'ai retiré tout appel de scrollToInput dans les autres fonctions
124-
* car il est déjà appelé dans useEffect quand la taille de la view change
125-
* et ça évite de trigger le scrollToInput à chaque fois et donc une ui laggy
126-
* La taille de la view change quand on ajoute ou supprime un recipient, ce qui trigger ce useEffect
127-
*/
128123
React.useEffect(() => {
129-
// Trouver la bonne condition pour ne pas faire de scroll si le champ n'est pas ouvert ou s'il n'est pas focus
130-
// À chaud, je dirais que c'est ici que tu dois travailler pour éviter le scroll quand tu supprimes des recipients dans un autre champ
131-
// Je n'ai pas pris le temps de chercher la bonne condition
132124
if (containerLayout.height > 0 && inputFocused) {
133125
setTimeout(() => {
134126
scrollToInput();
135127
}, 300);
136128
}
137-
}, [containerLayout, isOpen, scrollToInput, showList, inputFocused]); // TODO: mettre à jour les dépendances, je n'ai pas clean suite à quelques tests
129+
}, [containerLayout, isOpen, scrollToInput, showList, inputFocused]);
138130

139131
const onOpen = () => {
140132
setFocused(true);
141133
setIsOpen(true);
142134
};
143135

144136
const onFocus = () => {
145-
// Je crois que c'était un test, je ne sais plus pourquoi je l'ai commenté, à voir si ça pose problème
146-
// scrollToInput();
147137
setInputFocused(true);
148138
if (!isOpen) setIsOpen(true);
149-
if (search.length >= 3) toggleShowList();
150139
props.onFocus(props.type);
151140
};
152141

@@ -224,8 +213,6 @@ export const MailsContactField = (props: MailsContactFieldProps) => {
224213
const newSelectedRecipients = [...selectedRecipients, ...items];
225214
setSelectedRecipients(newSelectedRecipients);
226215
props.onChangeRecipient(newSelectedRecipients, props.type);
227-
// Evite d'appeler scrollToInput, il est déjà appelé car la taille de la view change
228-
// scrollToInput();
229216
};
230217

231218
const removeUser = (user: MailsVisible) => {
@@ -278,20 +265,14 @@ export const MailsContactField = (props: MailsContactFieldProps) => {
278265
};
279266

280267
const heightResults = React.useMemo(() => {
281-
//TODO: à dynamiser (nb de résultats * hauteur d'un item + header + offset)
282-
return filteredUsers.length * 58 + 40 + 100;
268+
return filteredUsers.length * HEIGHT_RECIPIENT_CONTAINER + HEIGHT_HEADER_RESULTS + UI_SIZES.spacing.small * 2 + 100;
283269
}, [filteredUsers]);
284270

285271
return (
286272
<>
287273
<View
288274
style={[styles.container, selectedRecipients.length === 0 ? styles.containerEmpty : {}]}
289275
ref={viewContainerRef}
290-
/**
291-
* Pour rappel, je pense que le problème vient du fait qu'il y a une différence entre Android et iOS dans les valeurs retours de measure().
292-
* Android mesure depuis le parent immédiat (il n'a pas l'air d'en trouver un à ce moment là ou il le trouve mais la view est situé à 0 dans l'espace) alors qu'iOS mesure depuis la root view ou le composant le plus haut.
293-
* onLayout c'est le petit cousin de feu onComponentDidMount, ça t'assure que les valeurs retournées sont celles calculées après que le render soit fait côté natif.
294-
*/
295276
onLayout={e => {
296277
const { height, width, x, y } = e.nativeEvent.layout;
297278
setContainerLayout({ height, width, x, y });

src/framework/modules/mails/components/recipient-item/container/styles.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { StyleSheet } from 'react-native';
22

33
import theme from '~/app/theme';
44
import { UI_SIZES } from '~/framework/components/constants';
5+
import { TextSizeStyle } from '~/framework/components/text';
6+
7+
export const HEIGHT_RECIPIENT_CONTAINER = UI_SIZES.spacing.minor * 2 + TextSizeStyle.Normal.lineHeight * 2;
58

69
export default StyleSheet.create({
710
container: {

0 commit comments

Comments
 (0)