1
1
import _ from 'lodash' ;
2
2
import React , { Component } from 'react' ;
3
- import { StyleSheet , ScrollView , Alert } from 'react-native' ;
4
- import { ListItem , SkeletonView , Spacings , Constants , BorderRadiuses , Avatar , Text , View , Image , Button } from 'react-native-ui-lib' ;
3
+ import { Alert , ScrollView , StyleSheet } from 'react-native' ;
4
+ import {
5
+ Avatar ,
6
+ BorderRadiuses ,
7
+ Button ,
8
+ Constants ,
9
+ Image ,
10
+ ListItem ,
11
+ SkeletonView ,
12
+ Spacings ,
13
+ Text ,
14
+ View ,
15
+ Colors
16
+ } from 'react-native-ui-lib' ;
5
17
import * as ExampleScreenPresenter from '../ExampleScreenPresenter' ;
18
+ import { ButtonSize } from '../../../../src/components/button' ;
6
19
7
20
const AVATAR_SIZE = 48 ;
8
21
9
- const THUMBNAIL_URL =
10
- 'https://static.wixstatic.com/media/8616c2ac52ee4d0294dd3c7e578228a1.jpg/v1/fit/w_300,h_600,q_85/8616c2ac52ee4d0294dd3c7e578228a1.jpg' ;
11
-
12
22
const IMAGE_URIS = [
13
23
'https://static.wixstatic.com/media/17db2bb89a1d405886bf6c5f90c776e8.jpg' ,
14
24
'https://static.wixstatic.com/media/ed8de924f9a04bc1b7f43137378d696e.jpg' ,
15
25
'https://static.wixstatic.com/media/ea3157fe992346728dd08cc2e4560e1c.jpg'
16
26
] ;
17
27
18
- const NUMBER_OF_ITEMS_TO_SHOW = 5 ;
28
+ const NUMBER_OF_ITEMS_TO_SHOW = 10 ;
19
29
20
30
const DATA_TYPE = {
21
31
List : 'list' ,
@@ -31,7 +41,12 @@ const LIST_TYPE = {
31
41
} ;
32
42
33
43
export default class SkeletonViewScreen extends Component {
34
- state = { isDataAvailable : false , dataType : DATA_TYPE . List , listType : LIST_TYPE . Regular , isLarge : false , key : 1 } ;
44
+ state = {
45
+ isDataAvailable : false ,
46
+ dataType : DATA_TYPE . List ,
47
+ listType : LIST_TYPE . Regular ,
48
+ isLarge : false ,
49
+ key : 1 } ;
35
50
36
51
increaseKey = ( ) => {
37
52
const { key} = this . state ;
@@ -70,15 +85,15 @@ export default class SkeletonViewScreen extends Component {
70
85
< Button
71
86
label = { isDataAvailable ? 'Hide data' : 'Show data' }
72
87
style = { [ styles . toggleButton ] }
73
- size = { ' small' }
88
+ size = { ButtonSize . small }
74
89
outline = { ! isDataAvailable }
75
90
onPress = { this . toggleVisibility }
76
91
/>
77
92
{ dataType === DATA_TYPE . List && (
78
93
< Button
79
94
label = { isLarge ? 'Set items to small' : 'Set items to large' }
80
95
style = { [ styles . toggleButton ] }
81
- size = { ' small' }
96
+ size = { ButtonSize . small }
82
97
outline = { ! isLarge }
83
98
onPress = { this . setSize }
84
99
/>
@@ -88,35 +103,56 @@ export default class SkeletonViewScreen extends Component {
88
103
) ;
89
104
} ;
90
105
91
- itemPressed = props => {
92
- Alert . alert ( 'Item pressed' , 'Title:' + props . title ) ;
93
- } ;
94
-
95
- renderListItemsData = ( { contentProps : { hasAvatar, hasThumbnail} } ) => {
96
- const { isLarge} = this . state ;
97
- const thumbnail = hasThumbnail ? { source : { uri : THUMBNAIL_URL } } : undefined ;
106
+ renderListItemsData = ( ) => {
107
+ const { listType} = this . state ;
108
+ const hasAvatar = listType === LIST_TYPE . Avatar ;
109
+ const hasThumbnail = listType === LIST_TYPE . Thumbnail ;
98
110
99
111
return (
100
112
< React . Fragment >
101
113
{ _ . times ( NUMBER_OF_ITEMS_TO_SHOW , index => {
102
114
return (
103
115
< ListItem
104
- key = { `list-item-${ index } ` }
105
- testID = { `list-item-${ index } ` }
106
- title = { `Small list item ${ index + 1 } ` }
107
- subtitle = { 'Some text' }
108
- description = { isLarge ? 'Other text' : undefined }
109
- avatar = { hasAvatar ? { source : this . getRandomAvatar ( ) , animate : false } : undefined }
110
- thumbnail = { thumbnail }
111
- onPress = { this . itemPressed }
112
- />
116
+ activeBackgroundColor = { Colors . dark60 }
117
+ activeOpacity = { 0.3 }
118
+ height = { 77.5 }
119
+ onPress = { ( ) => Alert . alert ( `pressed on order #${ index + 1 } ` ) }
120
+ >
121
+ {
122
+ hasAvatar
123
+ && < ListItem . Part left >
124
+ < Avatar
125
+ source = { this . getRandomAvatar ( ) }
126
+ containerStyle = { { marginStart : 14 } }
127
+ />
128
+ </ ListItem . Part >
129
+ }
130
+ {
131
+ hasThumbnail
132
+ && < ListItem . Part left >
133
+ < Image
134
+ source = { this . getRandomAvatar ( ) }
135
+ style = { { height : 54 , width : 54 , marginLeft : 14 } }
136
+ />
137
+ </ ListItem . Part >
138
+ }
139
+
140
+ < ListItem . Part middle column containerStyle = { [ styles . border , { marginLeft : 18 } ] } >
141
+ < ListItem . Part containerStyle = { { marginBottom : 3 } } >
142
+ < Text text60 numberOfLines = { 1 } > { `User ${ index + 1 } ` } </ Text >
143
+ </ ListItem . Part >
144
+ < ListItem . Part >
145
+ < Text text70 numberOfLines = { 1 } > Member</ Text >
146
+ </ ListItem . Part >
147
+ </ ListItem . Part >
148
+ </ ListItem >
113
149
) ;
114
150
} ) }
115
151
</ React . Fragment >
116
152
) ;
117
153
} ;
118
154
119
- renderListItems = ( hasAvatar , hasThumbnail ) => {
155
+ renderListItems = ( hasAvatar : boolean , hasThumbnail : boolean ) => {
120
156
const { isDataAvailable, isLarge} = this . state ;
121
157
const contentType = hasAvatar
122
158
? SkeletonView . contentTypes . AVATAR
@@ -149,7 +185,7 @@ export default class SkeletonViewScreen extends Component {
149
185
return this . renderListItems ( false , true ) ;
150
186
} ;
151
187
152
- getImageSize = ( ) => ( Constants . screenWidth - IMAGE_URIS . length * Spacings . page ) / IMAGE_URIS . length ;
188
+ getImageSize = ( ) => ( Constants . screenWidth - IMAGE_URIS . length * Spacings . s5 ) / IMAGE_URIS . length ;
153
189
154
190
renderImagesData = ( ) => {
155
191
const imageSize = this . getImageSize ( ) ;
@@ -181,7 +217,7 @@ export default class SkeletonViewScreen extends Component {
181
217
) ;
182
218
} ;
183
219
184
- getRandomInt = max => {
220
+ getRandomInt = ( max : number ) => {
185
221
return Math . floor ( Math . random ( ) * max ) ;
186
222
} ;
187
223
@@ -305,10 +341,15 @@ const styles = StyleSheet.create({
305
341
paddingTop : Spacings . s5 ,
306
342
paddingLeft : Spacings . s5
307
343
} ,
344
+ avatar : {
345
+ marginHorizontal : 14
346
+ } ,
308
347
image : {
309
- flex : 1
348
+ flex : 1 ,
349
+ borderRadius : BorderRadiuses . br20 ,
310
350
} ,
311
- avatar : {
312
- marginRight : 20
351
+ border : {
352
+ borderBottomWidth : StyleSheet . hairlineWidth ,
353
+ borderColor : Colors . dark70
313
354
}
314
355
} ) ;
0 commit comments