@@ -10,12 +10,11 @@ import Text from '../text';
10
10
import Image from '../image' ;
11
11
import AnimatedImage from '../../animations/animatedImage' ;
12
12
13
-
14
13
export const STATUS_MODES = {
15
14
ONLINE : 'ONLINE' ,
16
15
OFFLINE : 'OFFLINE' ,
17
16
AWAY : 'AWAY' ,
18
- NONE : 'NONE'
17
+ NONE : 'NONE' ,
19
18
} ;
20
19
21
20
/**
@@ -105,15 +104,15 @@ export default class Avatar extends BaseComponent {
105
104
/**
106
105
* Press handler
107
106
*/
108
- onPress : PropTypes . func
107
+ onPress : PropTypes . func ,
109
108
} ;
110
109
111
110
static defaultProps = {
112
111
animate : false ,
113
112
backgroundColor : Colors . dark80 ,
114
113
size : 50 ,
115
114
labelColor : Colors . dark10 ,
116
- status : STATUS_MODES . NONE
115
+ status : STATUS_MODES . NONE ,
117
116
} ;
118
117
119
118
generateStyles ( ) {
@@ -141,14 +140,24 @@ export default class Avatar extends BaseComponent {
141
140
return badgeColor ;
142
141
}
143
142
143
+ getBadgePosition ( ) {
144
+ const { size} = this . props ;
145
+ const badgeSize = 13.5 ;
146
+ const radius = size / 2 ;
147
+ const x = Math . sqrt ( radius ** 2 * 2 ) ;
148
+ const y = x - radius ;
149
+ const shift = Math . sqrt ( y ** 2 / 2 ) - badgeSize / 2 ;
150
+ return { top : shift , right : shift } ;
151
+ }
152
+
144
153
renderBadge ( ) {
145
154
const { testID, isOnline, status} = this . props ;
146
155
const badgeColor = this . getBadgeColor ( isOnline , status ) ;
147
156
if ( badgeColor === null ) {
148
157
return false ;
149
158
}
150
159
return (
151
- < View style = { this . styles . onlineBadge } testID = { `${ testID } .onlineBadge` } >
160
+ < View style = { [ this . styles . onlineBadge , this . getBadgePosition ( ) ] } testID = { `${ testID } .onlineBadge` } >
152
161
< View style = { [ this . styles . onlineBadgeInner , { backgroundColor : badgeColor } ] } />
153
162
</ View >
154
163
) ;
@@ -176,7 +185,7 @@ export default class Avatar extends BaseComponent {
176
185
onImageLoadError,
177
186
testID,
178
187
imageProps,
179
- imageStyle
188
+ imageStyle,
180
189
} = this . props ;
181
190
const hasImage = ! _ . isUndefined ( imageSource ) ;
182
191
const ImageContainer = animate ? AnimatedImage : Image ;
@@ -205,7 +214,9 @@ export default class Avatar extends BaseComponent {
205
214
206
215
return (
207
216
< Container style = { [ this . styles . container , containerStyle ] } testID = { testID } onPress = { onPress } >
208
- < View style = { [ this . styles . initialsContainer , { backgroundColor} , hasImage && this . styles . initialsContainerWithInset ] } >
217
+ < View
218
+ style = { [ this . styles . initialsContainer , { backgroundColor} , hasImage && this . styles . initialsContainerWithInset ] }
219
+ >
209
220
< Text numberOfLines = { 1 } style = { [ this . styles . initials , { color} ] } >
210
221
{ label }
211
222
</ Text >
@@ -218,7 +229,7 @@ export default class Avatar extends BaseComponent {
218
229
}
219
230
}
220
231
221
- function createStyles ( { size, labelColor, imageSource } ) {
232
+ function createStyles ( { size, labelColor} ) {
222
233
const borderRadius = size / 2 ;
223
234
const fontSizeToImageSizeRatio = 0.32 ;
224
235
const styles = StyleSheet . create ( {
@@ -227,38 +238,38 @@ function createStyles({size, labelColor, imageSource}) {
227
238
justifyContent : 'center' ,
228
239
width : size ,
229
240
height : size ,
230
- borderRadius
241
+ borderRadius,
231
242
} ,
232
243
initialsContainer : {
233
244
...StyleSheet . absoluteFillObject ,
234
245
alignItems : 'center' ,
235
246
justifyContent : 'center' ,
236
- borderRadius
247
+ borderRadius,
237
248
} ,
238
249
initialsContainerWithInset : {
239
250
top : 1 ,
240
251
right : 1 ,
241
252
bottom : 1 ,
242
- left : 1
253
+ left : 1 ,
243
254
} ,
244
255
/*eslint-disable*/
245
256
initials : {
246
257
fontSize : size * fontSizeToImageSizeRatio ,
247
258
color : labelColor ,
248
- backgroundColor : 'transparent'
259
+ backgroundColor : 'transparent' ,
249
260
} ,
250
261
/*eslint-enable*/
251
262
defaultImage : {
252
263
width : size ,
253
264
height : size ,
254
- borderRadius
265
+ borderRadius,
255
266
} ,
256
267
image : {
257
268
...StyleSheet . absoluteFillObject ,
258
269
position : 'absolute' ,
259
270
width : size ,
260
271
height : size ,
261
- borderRadius
272
+ borderRadius,
262
273
} ,
263
274
onlineBadge : {
264
275
height : 13.5 ,
@@ -267,18 +278,16 @@ function createStyles({size, labelColor, imageSource}) {
267
278
borderRadius : 999 ,
268
279
backgroundColor : Colors . white ,
269
280
position : 'absolute' ,
270
- right : imageSource ? - 1.5 : 0 ,
271
- top : 4.5
272
281
} ,
273
282
onlineBadgeInner : {
274
283
flex : 1 ,
275
- borderRadius : 999
284
+ borderRadius : 999 ,
276
285
// backgroundColor: Colors.green30,
277
286
} ,
278
287
fixAbsolutePosition : {
279
288
position : undefined ,
280
289
left : undefined ,
281
- bottom : undefined
290
+ bottom : undefined ,
282
291
} ,
283
292
ribbon : {
284
293
position : 'absolute' ,
@@ -287,8 +296,8 @@ function createStyles({size, labelColor, imageSource}) {
287
296
backgroundColor : Colors . blue30 ,
288
297
borderRadius : BorderRadiuses . br100 ,
289
298
paddingHorizontal : 6 ,
290
- paddingVertical : 3
291
- }
299
+ paddingVertical : 3 ,
300
+ } ,
292
301
} ) ;
293
302
294
303
return styles ;
0 commit comments