Skip to content

Feat/skeleton view full width #1950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions demo/src/screens/componentScreens/SkeletonViewScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ const NUMBER_OF_ITEMS_TO_SHOW = 10;

const DATA_TYPE = {
List: 'list',
Content: 'content',
Images: 'images',
Avatars: 'avatars',
Content: 'content'
Custom: 'custom'
};

const LIST_TYPE = {
Expand Down Expand Up @@ -317,6 +318,40 @@ export default class SkeletonViewScreen extends Component {
);
};

renderCustom = () => {
const {isDataAvailable} = this.state;

return (
<View margin-20>
<View row spread marginB-8>
<SkeletonView
width={120}
height={20}
borderRadius={5}
showContent={isDataAvailable}
renderContent={() => <Text text60BO>Lorem Ipsum</Text>}
/>
<SkeletonView
width={40}
height={10}
borderRadius={5}
style={{marginTop: 5}}
showContent={isDataAvailable}
renderContent={() => <Button label='Info' size={'small'} link/>}
/>
</View>
<SkeletonView
shimmerStyle={{width: '100%'/* , height: 30 */}}
height={10}
borderRadius={5}
showContent={isDataAvailable}
renderContent={() => <Text>Lorem Ipsum is simply dummy text of the industry.</Text>}
colors={[Colors.red70, Colors.red50, Colors.red70]}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if you left this on purpose, I don't like it too much.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did. To remove it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, but it might be a matter of taste, so it's up to you

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it since it a "custom" example

/>
</View>
);
}

renderContent = () => {
const {isDataAvailable} = this.state;
return (
Expand Down Expand Up @@ -345,12 +380,14 @@ export default class SkeletonViewScreen extends Component {
case LIST_TYPE.Thumbnail:
return this.renderListItemsWithThumbnail();
}
case DATA_TYPE.Content:
return this.renderContent();
case DATA_TYPE.Images:
return this.renderImages();
case DATA_TYPE.Avatars:
return this.renderAvatarStrip();
case DATA_TYPE.Content:
return this.renderContent();
case DATA_TYPE.Custom:
return this.renderCustom();
}
};

Expand Down Expand Up @@ -385,7 +422,7 @@ const styles = StyleSheet.create({
paddingLeft: Spacings.s5
},
avatar: {
marginHorizontal: 14
marginVertical: 8
},
image: {
flex: 1,
Expand Down
196 changes: 0 additions & 196 deletions generatedTypes/src/components/skeletonView/index.d.ts

This file was deleted.

15 changes: 11 additions & 4 deletions src/components/skeletonView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ export interface SkeletonViewProps extends AccessibilityProps, MarginModifiers {
* Whether the skeleton is a circle (will override the borderRadius)
*/
circle?: boolean;
/**
* Additional style to the skeleton view
*/
shimmerStyle?: StyleProp<ViewStyle>;
/**
* Override container styles
*/
Expand Down Expand Up @@ -234,20 +238,22 @@ class SkeletonView extends Component<InternalSkeletonViewProps, SkeletonState> {

getDefaultSkeletonProps = (input?: {circleOverride: boolean; style: StyleProp<ViewStyle>}) => {
const {circleOverride, style} = input || {};
const {circle, colors, width = 0, height = 0} = this.props;
const {circle, colors, width, height = 0, shimmerStyle} = this.props;
let {borderRadius} = this.props;
let size;

if (circle || circleOverride) {
borderRadius = BorderRadiuses.br100;
size = Math.max(width, height);
}
size = Math.max(width || 0, height);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix!

}

return {
shimmerColors: colors || [Colors.grey70, Colors.grey60, Colors.grey70],
isReversed: Constants.isRTL,
style: [{borderRadius}, style],
width: size || width,
height: size || height
height: size || height,
shimmerStyle
};
};

Expand Down Expand Up @@ -360,6 +366,7 @@ class SkeletonView extends Component<InternalSkeletonViewProps, SkeletonState> {
renderAdvanced = () => {
const {children, renderContent, showContent, style, ...others} = this.props;
const data = showContent && _.isFunction(renderContent) ? renderContent(this.props) : children;

return (
<View style={style} {...this.getAccessibilityProps('Loading content')}>
<ShimmerPlaceholder {...this.getDefaultSkeletonProps()} {...others}>
Expand Down
1 change: 1 addition & 0 deletions src/components/skeletonView/skeletonView.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"type": "boolean",
"description": "Whether the skeleton is a circle (will override the borderRadius)"
},
{"name": "shimmerStyle", "type": "ViewStyle", "description": "Additional style to the skeleton view"},
{"name": "style", "type": "ViewStyle", "description": "Override container styles"},
{"name": "testID", "type": "string", "description": "The component test id"}
],
Expand Down