Skip to content

Commit 4e27785

Browse files
authored
Feat/skeleton view full width (#1950)
* SkeletonView - adding 'fullWidth' prop * SkeletonView - support width as string * rename const * types * merge fix * Skeleton - expose ShimmerStyle to allow full width * Adding new prop to api * fix * removing d.ts
1 parent 5b10bd6 commit 4e27785

File tree

4 files changed

+53
-204
lines changed

4 files changed

+53
-204
lines changed

demo/src/screens/componentScreens/SkeletonViewScreen.tsx

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ const NUMBER_OF_ITEMS_TO_SHOW = 10;
2929

3030
const DATA_TYPE = {
3131
List: 'list',
32+
Content: 'content',
3233
Images: 'images',
3334
Avatars: 'avatars',
34-
Content: 'content'
35+
Custom: 'custom'
3536
};
3637

3738
const LIST_TYPE = {
@@ -317,6 +318,40 @@ export default class SkeletonViewScreen extends Component {
317318
);
318319
};
319320

321+
renderCustom = () => {
322+
const {isDataAvailable} = this.state;
323+
324+
return (
325+
<View margin-20>
326+
<View row spread marginB-8>
327+
<SkeletonView
328+
width={120}
329+
height={20}
330+
borderRadius={5}
331+
showContent={isDataAvailable}
332+
renderContent={() => <Text text60BO>Lorem Ipsum</Text>}
333+
/>
334+
<SkeletonView
335+
width={40}
336+
height={10}
337+
borderRadius={5}
338+
style={{marginTop: 5}}
339+
showContent={isDataAvailable}
340+
renderContent={() => <Button label='Info' size={'small'} link/>}
341+
/>
342+
</View>
343+
<SkeletonView
344+
shimmerStyle={{width: '100%'/* , height: 30 */}}
345+
height={10}
346+
borderRadius={5}
347+
showContent={isDataAvailable}
348+
renderContent={() => <Text>Lorem Ipsum is simply dummy text of the industry.</Text>}
349+
colors={[Colors.red70, Colors.red50, Colors.red70]}
350+
/>
351+
</View>
352+
);
353+
}
354+
320355
renderContent = () => {
321356
const {isDataAvailable} = this.state;
322357
return (
@@ -345,12 +380,14 @@ export default class SkeletonViewScreen extends Component {
345380
case LIST_TYPE.Thumbnail:
346381
return this.renderListItemsWithThumbnail();
347382
}
383+
case DATA_TYPE.Content:
384+
return this.renderContent();
348385
case DATA_TYPE.Images:
349386
return this.renderImages();
350387
case DATA_TYPE.Avatars:
351388
return this.renderAvatarStrip();
352-
case DATA_TYPE.Content:
353-
return this.renderContent();
389+
case DATA_TYPE.Custom:
390+
return this.renderCustom();
354391
}
355392
};
356393

@@ -385,7 +422,7 @@ const styles = StyleSheet.create({
385422
paddingLeft: Spacings.s5
386423
},
387424
avatar: {
388-
marginHorizontal: 14
425+
marginVertical: 8
389426
},
390427
image: {
391428
flex: 1,

generatedTypes/src/components/skeletonView/index.d.ts

Lines changed: 0 additions & 196 deletions
This file was deleted.

src/components/skeletonView/index.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ export interface SkeletonViewProps extends AccessibilityProps, MarginModifiers {
141141
* Whether the skeleton is a circle (will override the borderRadius)
142142
*/
143143
circle?: boolean;
144+
/**
145+
* Additional style to the skeleton view
146+
*/
147+
shimmerStyle?: StyleProp<ViewStyle>;
144148
/**
145149
* Override container styles
146150
*/
@@ -234,20 +238,22 @@ class SkeletonView extends Component<InternalSkeletonViewProps, SkeletonState> {
234238

235239
getDefaultSkeletonProps = (input?: {circleOverride: boolean; style: StyleProp<ViewStyle>}) => {
236240
const {circleOverride, style} = input || {};
237-
const {circle, colors, width = 0, height = 0} = this.props;
241+
const {circle, colors, width, height = 0, shimmerStyle} = this.props;
238242
let {borderRadius} = this.props;
239243
let size;
244+
240245
if (circle || circleOverride) {
241246
borderRadius = BorderRadiuses.br100;
242-
size = Math.max(width, height);
243-
}
247+
size = Math.max(width || 0, height);
248+
}
244249

245250
return {
246251
shimmerColors: colors || [Colors.$backgroundNeutral, Colors.$backgroundNeutralMedium, Colors.$backgroundNeutral],
247252
isReversed: Constants.isRTL,
248253
style: [{borderRadius}, style],
249254
width: size || width,
250-
height: size || height
255+
height: size || height,
256+
shimmerStyle
251257
};
252258
};
253259

@@ -360,6 +366,7 @@ class SkeletonView extends Component<InternalSkeletonViewProps, SkeletonState> {
360366
renderAdvanced = () => {
361367
const {children, renderContent, showContent, style, ...others} = this.props;
362368
const data = showContent && _.isFunction(renderContent) ? renderContent(this.props) : children;
369+
363370
return (
364371
<View style={style} {...this.getAccessibilityProps('Loading content')}>
365372
<ShimmerPlaceholder {...this.getDefaultSkeletonProps()} {...others}>

src/components/skeletonView/skeletonView.api.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"type": "boolean",
5050
"description": "Whether the skeleton is a circle (will override the borderRadius)"
5151
},
52+
{"name": "shimmerStyle", "type": "ViewStyle", "description": "Additional style to the skeleton view"},
5253
{"name": "style", "type": "ViewStyle", "description": "Override container styles"},
5354
{"name": "testID", "type": "string", "description": "The component test id"}
5455
],

0 commit comments

Comments
 (0)