Skip to content

Commit 200f28b

Browse files
authored
support margin modifiers in SkeletonView (#1807)
1 parent 0def2da commit 200f28b

File tree

3 files changed

+73
-23
lines changed

3 files changed

+73
-23
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { Component } from 'react';
22
import { Animated, StyleProp, ViewStyle, AccessibilityProps } from 'react-native';
3+
import { BaseComponentInjectedProps, MarginModifiers } from '../../commons/new';
34
export declare enum Template {
45
LIST_ITEM = "listItem",
56
TEXT_CONTENT = "content"
@@ -36,7 +37,7 @@ export interface SkeletonListProps {
3637
*/
3738
renderEndContent?: () => React.ReactElement | undefined;
3839
}
39-
export interface SkeletonViewProps extends AccessibilityProps {
40+
export interface SkeletonViewProps extends AccessibilityProps, MarginModifiers {
4041
/**
4142
* The content has been loaded, start fading out the skeleton and fading in the content
4243
*/
@@ -138,7 +139,8 @@ interface SkeletonState {
138139
* @image: https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/Skeleton/Skeleton.gif?raw=true
139140
* @notes: View requires installing the 'react-native-shimmer-placeholder' and 'react-native-linear-gradient' library
140141
*/
141-
declare class SkeletonView extends Component<SkeletonViewProps, SkeletonState> {
142+
declare type InternalSkeletonViewProps = SkeletonViewProps & BaseComponentInjectedProps;
143+
declare class SkeletonView extends Component<InternalSkeletonViewProps, SkeletonState> {
142144
static defaultProps: {
143145
size: Size;
144146
borderRadius: number;
@@ -147,9 +149,9 @@ declare class SkeletonView extends Component<SkeletonViewProps, SkeletonState> {
147149
static sizes: typeof Size;
148150
static contentTypes: typeof ContentType;
149151
fadeInAnimation?: Animated.CompositeAnimation;
150-
constructor(props: SkeletonViewProps);
152+
constructor(props: InternalSkeletonViewProps);
151153
componentDidMount(): void;
152-
componentDidUpdate(prevProps: SkeletonViewProps): void;
154+
componentDidUpdate(prevProps: InternalSkeletonViewProps): void;
153155
fade(isFadeIn: boolean, onAnimationEnd?: Animated.EndCallback): Animated.CompositeAnimation;
154156
showChildren: () => void;
155157
getAccessibilityProps: (accessibilityLabel: any) => {

src/components/skeletonView/index.tsx

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {StyleSheet, Animated, Easing, StyleProp, ViewStyle, AccessibilityProps}
44
import {BorderRadiuses, Colors, Dividers, Spacings} from '../../style';
55
import {createShimmerPlaceholder, LinearGradientPackage} from 'optionalDeps';
66
import View from '../view';
7-
import {Constants, asBaseComponent} from '../../commons/new';
7+
import {Constants, asBaseComponent, BaseComponentInjectedProps, MarginModifiers} from '../../commons/new';
88
import {extractAccessibilityProps} from '../../commons/modifiers';
99

1010
const LinearGradient = LinearGradientPackage?.default;
@@ -53,7 +53,7 @@ export interface SkeletonListProps {
5353
renderEndContent?: () => React.ReactElement | undefined;
5454
}
5555

56-
export interface SkeletonViewProps extends AccessibilityProps {
56+
export interface SkeletonViewProps extends AccessibilityProps, MarginModifiers {
5757
/**
5858
* The content has been loaded, start fading out the skeleton and fading in the content
5959
*/
@@ -157,7 +157,10 @@ interface SkeletonState {
157157
* @image: https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/Skeleton/Skeleton.gif?raw=true
158158
* @notes: View requires installing the 'react-native-shimmer-placeholder' and 'react-native-linear-gradient' library
159159
*/
160-
class SkeletonView extends Component<SkeletonViewProps, SkeletonState> {
160+
161+
type InternalSkeletonViewProps = SkeletonViewProps & BaseComponentInjectedProps;
162+
163+
class SkeletonView extends Component<InternalSkeletonViewProps, SkeletonState> {
161164
static defaultProps = {
162165
size: Size.SMALL,
163166
// listProps: {size: Size.SMALL}, TODO: once size is deprecated remove it and add this
@@ -170,7 +173,7 @@ class SkeletonView extends Component<SkeletonViewProps, SkeletonState> {
170173

171174
fadeInAnimation?: Animated.CompositeAnimation;
172175

173-
constructor(props: SkeletonViewProps) {
176+
constructor(props: InternalSkeletonViewProps) {
174177
super(props);
175178

176179
this.state = {
@@ -193,7 +196,7 @@ class SkeletonView extends Component<SkeletonViewProps, SkeletonState> {
193196
}
194197
}
195198

196-
componentDidUpdate(prevProps: SkeletonViewProps) {
199+
componentDidUpdate(prevProps: InternalSkeletonViewProps) {
197200
if (this.props.showContent && !prevProps.showContent) {
198201
this.fadeInAnimation?.stop();
199202
this.fade(false, this.showChildren);
@@ -407,22 +410,66 @@ class SkeletonView extends Component<SkeletonViewProps, SkeletonState> {
407410
return null;
408411
}
409412

410-
const {times, timesKey, renderContent, testID} = this.props;
413+
const {
414+
times,
415+
timesKey,
416+
renderContent,
417+
showContent,
418+
customValue,
419+
contentData,
420+
template,
421+
listProps,
422+
size,
423+
contentType,
424+
hideSeparator,
425+
showLastSeparator,
426+
height,
427+
width,
428+
borderRadius,
429+
circle,
430+
style,
431+
testID,
432+
...others
433+
} = this.props;
434+
435+
const passedProps = {
436+
showContent,
437+
renderContent,
438+
customValue,
439+
contentData,
440+
template,
441+
listProps,
442+
size,
443+
contentType,
444+
hideSeparator,
445+
showLastSeparator,
446+
height,
447+
width,
448+
borderRadius,
449+
circle,
450+
style,
451+
testID
452+
};
411453

412454
if (times) {
413-
return _.times(times, index => {
414-
const key = timesKey ? `${timesKey}-${index}` : `${index}`;
415-
return (
416-
<SkeletonView
417-
{...this.props}
418-
key={key}
419-
testID={`${testID}-${index}`}
420-
renderContent={index === 0 ? renderContent : this.renderNothing}
421-
hideSeparator={this.hideSeparator || (!this.showLastSeparator && index === times - 1)}
422-
times={undefined}
423-
/>
424-
);
425-
});
455+
return (
456+
<View {...others}>
457+
{_.times(times, index => {
458+
const key = timesKey ? `${timesKey}-${index}` : `${index}`;
459+
return (
460+
<SkeletonView
461+
modifiers={{}}
462+
{...passedProps}
463+
key={key}
464+
testID={`${testID}-${index}`}
465+
renderContent={index === 0 ? renderContent : this.renderNothing}
466+
hideSeparator={this.hideSeparator || (!this.showLastSeparator && index === times - 1)}
467+
times={undefined}
468+
/>
469+
);
470+
})}
471+
</View>
472+
);
426473
} else {
427474
return this.renderSkeleton();
428475
}

src/components/skeletonView/skeletonView.api.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "SkeletonView",
33
"category": "layoutsAndTemplates",
44
"description": "Allows showing a temporary skeleton view while your real view is loading",
5+
"modifiers": ["margin"],
56
"note": "Requires installing the 'react-native-shimmer-placeholder' and 'react-native-linear-gradient' libraries",
67
"example": "https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/SkeletonViewScreen.tsx",
78
"images": ["https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/Skeleton/Skeleton.gif?raw=true"],

0 commit comments

Comments
 (0)