@@ -12,10 +12,11 @@ import { UI_SIZES } from '~/framework/components/constants';
12
12
import { TextInputType } from '~/framework/components/inputs/text/component' ;
13
13
import FlatList from '~/framework/components/list/flat-list' ;
14
14
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' ;
16
16
import MailsContactItem from '~/framework/modules/mails/components/contact-item' ;
17
17
import stylesContactItem from '~/framework/modules/mails/components/contact-item/styles' ;
18
18
import { MailsRecipientGroupItem , MailsRecipientUserItem } from '~/framework/modules/mails/components/recipient-item' ;
19
+ import { HEIGHT_RECIPIENT_CONTAINER } from '~/framework/modules/mails/components/recipient-item/container/styles' ;
19
20
import { MailsRecipientsType , MailsVisible , MailsVisibleType } from '~/framework/modules/mails/model' ;
20
21
import { readVisibles } from '~/framework/modules/mails/storage' ;
21
22
import { MailsRecipientPrefixsI18n } from '~/framework/modules/mails/util' ;
@@ -24,7 +25,8 @@ function removeAccents(text: string): string {
24
25
return text . normalize ( 'NFD' ) . replace ( / [ \u0300 - \u036f ] / g, '' ) ;
25
26
}
26
27
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 ;
28
30
29
31
export const MailsContactField = ( props : MailsContactFieldProps ) => {
30
32
const [ search , setSearch ] = React . useState ( '' ) ;
@@ -93,7 +95,6 @@ export const MailsContactField = (props: MailsContactFieldProps) => {
93
95
React . useEffect ( ( ) => {
94
96
if ( viewContainerRef . current ) {
95
97
setTimeout ( ( ) => {
96
- // console.log('measure', containerLayout.y, containerLayout.height);
97
98
Animated . spring ( topPositionResults , {
98
99
friction : 8 ,
99
100
tension : 50 ,
@@ -119,34 +120,22 @@ export const MailsContactField = (props: MailsContactFieldProps) => {
119
120
}
120
121
} , [ containerLayout , props . scrollViewRef , topPositionResults ] ) ;
121
122
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
- */
128
123
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
132
124
if ( containerLayout . height > 0 && inputFocused ) {
133
125
setTimeout ( ( ) => {
134
126
scrollToInput ( ) ;
135
127
} , 300 ) ;
136
128
}
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 ] ) ;
138
130
139
131
const onOpen = ( ) => {
140
132
setFocused ( true ) ;
141
133
setIsOpen ( true ) ;
142
134
} ;
143
135
144
136
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();
147
137
setInputFocused ( true ) ;
148
138
if ( ! isOpen ) setIsOpen ( true ) ;
149
- if ( search . length >= 3 ) toggleShowList ( ) ;
150
139
props . onFocus ( props . type ) ;
151
140
} ;
152
141
@@ -224,8 +213,6 @@ export const MailsContactField = (props: MailsContactFieldProps) => {
224
213
const newSelectedRecipients = [ ...selectedRecipients , ...items ] ;
225
214
setSelectedRecipients ( newSelectedRecipients ) ;
226
215
props . onChangeRecipient ( newSelectedRecipients , props . type ) ;
227
- // Evite d'appeler scrollToInput, il est déjà appelé car la taille de la view change
228
- // scrollToInput();
229
216
} ;
230
217
231
218
const removeUser = ( user : MailsVisible ) => {
@@ -278,20 +265,14 @@ export const MailsContactField = (props: MailsContactFieldProps) => {
278
265
} ;
279
266
280
267
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 ;
283
269
} , [ filteredUsers ] ) ;
284
270
285
271
return (
286
272
< >
287
273
< View
288
274
style = { [ styles . container , selectedRecipients . length === 0 ? styles . containerEmpty : { } ] }
289
275
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
- */
295
276
onLayout = { e => {
296
277
const { height, width, x, y } = e . nativeEvent . layout ;
297
278
setContainerLayout ( { height, width, x, y } ) ;
0 commit comments