Skip to content

Feat/ support passing colors to skeletonView #1905

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 5 commits into from
Mar 17, 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
5 changes: 5 additions & 0 deletions generatedTypes/src/components/skeletonView/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ export interface SkeletonViewProps extends AccessibilityProps, MarginModifiers {
* The width of the skeleton view
*/
width?: number;
/**
* The colors of the skeleton view, the array length has to be >=2
* default: [Colors.grey70, Colors.grey60, Colors.grey70]
*/
colors?: string[];
/**
* The border radius of the skeleton view
*/
Expand Down
11 changes: 9 additions & 2 deletions src/components/skeletonView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ export interface SkeletonViewProps extends AccessibilityProps, MarginModifiers {
* The width of the skeleton view
*/
width?: number;
/**
* The colors of the skeleton view, the array length has to be >=2
* default: [Colors.grey70, Colors.grey60, Colors.grey70]
*/
colors?: string[]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems to work with empty (black) or even four colors, did not even see a recommendation.
I'd add the default here and to the API.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Correction, tested on Android and it has to be >=2

/**
* The border radius of the skeleton view
*/
Expand Down Expand Up @@ -229,7 +234,7 @@ class SkeletonView extends Component<InternalSkeletonViewProps, SkeletonState> {

getDefaultSkeletonProps = (input?: {circleOverride: boolean; style: StyleProp<ViewStyle>}) => {
const {circleOverride, style} = input || {};
const {circle, width = 0, height = 0} = this.props;
const {circle, colors, width = 0, height = 0} = this.props;
let {borderRadius} = this.props;
let size;
if (circle || circleOverride) {
Expand All @@ -238,7 +243,7 @@ class SkeletonView extends Component<InternalSkeletonViewProps, SkeletonState> {
}

return {
shimmerColors: [Colors.grey70, Colors.grey60, Colors.grey70],
shimmerColors: colors || [Colors.grey70, Colors.grey60, Colors.grey70],
isReversed: Constants.isRTL,
style: [{borderRadius}, style],
width: size || width,
Expand Down Expand Up @@ -425,6 +430,7 @@ class SkeletonView extends Component<InternalSkeletonViewProps, SkeletonState> {
showLastSeparator,
height,
width,
colors,
borderRadius,
circle,
style,
Expand All @@ -445,6 +451,7 @@ class SkeletonView extends Component<InternalSkeletonViewProps, SkeletonState> {
showLastSeparator,
height,
width,
colors,
borderRadius,
circle,
style,
Expand Down
6 changes: 6 additions & 0 deletions src/components/skeletonView/skeletonView.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
{"name": "timesKey", "type": "string", "description": "A key prefix for the duplicated SkeletonViews"},
{"name": "height", "type": "number", "description": "The height of the skeleton view"},
{"name": "width", "type": "number", "description": "The width of the skeleton view"},
{
"name": "colors",
"type": "string[]",
"description": "The colors of the skeleton view, the array length has to be >=2",
"default": "[Colors.grey70, Colors.grey60, Colors.grey70]"
},
{"name": "borderRadius", "type": "number", "description": "The border radius of the skeleton view"},
{
"name": "circle",
Expand Down