Skip to content

Commit 85fc835

Browse files
works
1 parent 9ea941f commit 85fc835

File tree

2 files changed

+79
-38
lines changed

2 files changed

+79
-38
lines changed

demo/src/screens/componentScreens/SkeletonViewScreen.js renamed to demo/src/screens/componentScreens/SkeletonViewScreen.tsx

Lines changed: 72 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
import _ from 'lodash';
22
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';
517
import * as ExampleScreenPresenter from '../ExampleScreenPresenter';
18+
import {ButtonSize} from '../../../../src/components/button';
619

720
const AVATAR_SIZE = 48;
821

9-
const THUMBNAIL_URL =
10-
'https://static.wixstatic.com/media/8616c2ac52ee4d0294dd3c7e578228a1.jpg/v1/fit/w_300,h_600,q_85/8616c2ac52ee4d0294dd3c7e578228a1.jpg';
11-
1222
const IMAGE_URIS = [
1323
'https://static.wixstatic.com/media/17db2bb89a1d405886bf6c5f90c776e8.jpg',
1424
'https://static.wixstatic.com/media/ed8de924f9a04bc1b7f43137378d696e.jpg',
1525
'https://static.wixstatic.com/media/ea3157fe992346728dd08cc2e4560e1c.jpg'
1626
];
1727

18-
const NUMBER_OF_ITEMS_TO_SHOW = 5;
28+
const NUMBER_OF_ITEMS_TO_SHOW = 10;
1929

2030
const DATA_TYPE = {
2131
List: 'list',
@@ -31,7 +41,12 @@ const LIST_TYPE = {
3141
};
3242

3343
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};
3550

3651
increaseKey = () => {
3752
const {key} = this.state;
@@ -70,15 +85,15 @@ export default class SkeletonViewScreen extends Component {
7085
<Button
7186
label={isDataAvailable ? 'Hide data' : 'Show data'}
7287
style={[styles.toggleButton]}
73-
size={'small'}
88+
size={ButtonSize.small}
7489
outline={!isDataAvailable}
7590
onPress={this.toggleVisibility}
7691
/>
7792
{dataType === DATA_TYPE.List && (
7893
<Button
7994
label={isLarge ? 'Set items to small' : 'Set items to large'}
8095
style={[styles.toggleButton]}
81-
size={'small'}
96+
size={ButtonSize.small}
8297
outline={!isLarge}
8398
onPress={this.setSize}
8499
/>
@@ -88,35 +103,56 @@ export default class SkeletonViewScreen extends Component {
88103
);
89104
};
90105

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;
98110

99111
return (
100112
<React.Fragment>
101113
{_.times(NUMBER_OF_ITEMS_TO_SHOW, index => {
102114
return (
103115
<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>
113149
);
114150
})}
115151
</React.Fragment>
116152
);
117153
};
118154

119-
renderListItems = (hasAvatar, hasThumbnail) => {
155+
renderListItems = (hasAvatar: boolean, hasThumbnail: boolean) => {
120156
const {isDataAvailable, isLarge} = this.state;
121157
const contentType = hasAvatar
122158
? SkeletonView.contentTypes.AVATAR
@@ -149,7 +185,7 @@ export default class SkeletonViewScreen extends Component {
149185
return this.renderListItems(false, true);
150186
};
151187

152-
getImageSize = () => (Constants.screenWidth - IMAGE_URIS.length * Spacings.page) / IMAGE_URIS.length;
188+
getImageSize = () => (Constants.screenWidth - IMAGE_URIS.length * Spacings.s5) / IMAGE_URIS.length;
153189

154190
renderImagesData = () => {
155191
const imageSize = this.getImageSize();
@@ -181,7 +217,7 @@ export default class SkeletonViewScreen extends Component {
181217
);
182218
};
183219

184-
getRandomInt = max => {
220+
getRandomInt = (max: number) => {
185221
return Math.floor(Math.random() * max);
186222
};
187223

@@ -305,10 +341,15 @@ const styles = StyleSheet.create({
305341
paddingTop: Spacings.s5,
306342
paddingLeft: Spacings.s5
307343
},
344+
avatar: {
345+
marginHorizontal: 14
346+
},
308347
image: {
309-
flex: 1
348+
flex: 1,
349+
borderRadius: BorderRadiuses.br20,
310350
},
311-
avatar: {
312-
marginRight: 20
351+
border: {
352+
borderBottomWidth: StyleSheet.hairlineWidth,
353+
borderColor: Colors.dark70
313354
}
314355
});

src/components/skeleton/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import {BorderRadiuses, Colors, Dividers, Spacings} from '../../style';
55
import {createShimmerPlaceholder, LinearGradientPackage} from 'optionalDeps';
66
import {Constants} from 'helpers';
77
import View from '../view';
8-
import EndCallback = Animated.EndCallback;
98
import {asBaseComponent} from '../../commons/new';
109
import {extractAccessibilityProps} from '../../commons/modifiers';
11-
const ShimmerPlaceholder = createShimmerPlaceholder(LinearGradientPackage?.LinearGradient);
10+
11+
const LinearGradient = LinearGradientPackage?.default
12+
13+
const ShimmerPlaceholder = createShimmerPlaceholder(LinearGradient);
1214

1315
const ANIMATION_DURATION = 400;
1416

@@ -142,7 +144,7 @@ class SkeletonView extends Component<SkeletonProps, SkeletonState> {
142144
}
143145
}
144146

145-
fade(isFadeIn: boolean, onAnimationEnd?: EndCallback) {
147+
fade(isFadeIn: boolean, onAnimationEnd?: Animated.EndCallback) {
146148
const animation = Animated.timing(this.state.opacity, {
147149
toValue: isFadeIn ? 1 : 0,
148150
easing: Easing.ease,
@@ -323,8 +325,7 @@ class SkeletonView extends Component<SkeletonProps, SkeletonState> {
323325

324326
if (times) {
325327
return (
326-
<React.Fragment>
327-
{_.times(times, index => {
328+
_.times(times, index => {
328329
const key = timesKey ? `${timesKey}-${index}` : `${index}`;
329330
return (
330331
<SkeletonView
@@ -336,8 +337,7 @@ class SkeletonView extends Component<SkeletonProps, SkeletonState> {
336337
times={undefined}
337338
/>
338339
);
339-
})}
340-
</React.Fragment>
340+
})
341341
);
342342
} else {
343343
return this.renderSkeleton();

0 commit comments

Comments
 (0)