Skip to content

Commit b069236

Browse files
authored
Skeleton - add new features (align to private) (#1622)
* Allow customValue and deprecate contentData * Move list related props to listProps * Move list related props to listProps (.d) * Add renderEndContent + some fixes * Fix some missed customValue
1 parent a76b712 commit b069236

File tree

3 files changed

+201
-50
lines changed

3 files changed

+201
-50
lines changed

demo/src/screens/componentScreens/SkeletonViewScreen.tsx

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
View,
1515
Colors
1616
} from 'react-native-ui-lib';
17+
// @ts-expect-error
1718
import * as ExampleScreenPresenter from '../ExampleScreenPresenter';
1819

1920
const AVATAR_SIZE = 48;
@@ -45,6 +46,7 @@ export default class SkeletonViewScreen extends Component {
4546
dataType: DATA_TYPE.List,
4647
listType: LIST_TYPE.Regular,
4748
isLarge: false,
49+
showEndContent: true,
4850
key: 1
4951
};
5052

@@ -67,8 +69,24 @@ export default class SkeletonViewScreen extends Component {
6769
this.setState({isLarge: !isLarge, key: key + 1, isDataAvailable: false});
6870
};
6971

72+
setEndContent = () => {
73+
const {showEndContent, key} = this.state;
74+
this.setState({showEndContent: !showEndContent, key: key + 1, isDataAvailable: false});
75+
};
76+
77+
renderEndContent = () => {
78+
const {showEndContent} = this.state;
79+
if (showEndContent) {
80+
return (
81+
<View flex right paddingR-20>
82+
<SkeletonView width={45} height={18} borderRadius={BorderRadiuses.br10}/>
83+
</View>
84+
);
85+
}
86+
};
87+
7088
renderTopSection = () => {
71-
const {isDataAvailable, isLarge, dataType} = this.state;
89+
const {isDataAvailable, isLarge, showEndContent, dataType} = this.state;
7290
return (
7391
<View marginH-page marginV-s1>
7492
{ExampleScreenPresenter.renderHeader.call(this, 'Skeleton')}
@@ -83,21 +101,30 @@ export default class SkeletonViewScreen extends Component {
83101
})}
84102
<View row centerV spread>
85103
<Button
86-
label={isDataAvailable ? 'Hide data' : 'Show data'}
104+
label={'Show data'}
87105
style={[styles.toggleButton]}
88-
size={Button.sizes.small}
106+
size={Button.sizes.xSmall}
89107
outline={!isDataAvailable}
90108
onPress={this.toggleVisibility}
91109
/>
92110
{dataType === DATA_TYPE.List && (
93111
<Button
94-
label={isLarge ? 'Set items to small' : 'Set items to large'}
112+
label={'Large items'}
95113
style={[styles.toggleButton]}
96-
size={Button.sizes.small}
114+
size={Button.sizes.xSmall}
97115
outline={!isLarge}
98116
onPress={this.setSize}
99117
/>
100118
)}
119+
{dataType === DATA_TYPE.List && (
120+
<Button
121+
label={'End content'}
122+
style={[styles.toggleButton]}
123+
size={Button.sizes.xSmall}
124+
outline={!showEndContent}
125+
onPress={this.setEndContent}
126+
/>
127+
)}
101128
</View>
102129
</View>
103130
);
@@ -119,9 +146,17 @@ export default class SkeletonViewScreen extends Component {
119146
);
120147
};
121148

122-
renderListItemsData = (contentData?: any) => {
123-
const {isLarge} = this.state;
124-
const {hasAvatar, hasThumbnail} = contentData || {};
149+
renderEndLabel = () => {
150+
return (
151+
<View centerV paddingR-20>
152+
<Text>Verified</Text>
153+
</View>
154+
);
155+
}
156+
157+
renderListItemsData = (customValue?: any) => {
158+
const {isLarge, showEndContent} = this.state;
159+
const {hasAvatar, hasThumbnail} = customValue || {};
125160

126161
return (
127162
<React.Fragment>
@@ -153,6 +188,7 @@ export default class SkeletonViewScreen extends Component {
153188
</ListItem.Part>
154189
)}
155190
</ListItem.Part>
191+
{showEndContent && this.renderEndLabel()}
156192
</ListItem>
157193
);
158194
})}
@@ -171,11 +207,10 @@ export default class SkeletonViewScreen extends Component {
171207
return (
172208
<SkeletonView
173209
template={SkeletonView.templates.LIST_ITEM}
174-
contentType={contentType}
175-
size={size}
210+
listProps={{size, contentType, renderEndContent: this.renderEndContent}}
176211
showContent={isDataAvailable}
177212
renderContent={this.renderListItemsData}
178-
contentData={{hasAvatar, hasThumbnail}}
213+
customValue={{hasAvatar, hasThumbnail}}
179214
times={NUMBER_OF_ITEMS_TO_SHOW}
180215
/>
181216
);

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

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,59 @@ declare enum ContentType {
1212
AVATAR = "avatar",
1313
THUMBNAIL = "thumbnail"
1414
}
15+
export interface SkeletonListProps {
16+
/**
17+
* The size of the skeleton view.
18+
* Types: SMALL and LARGE (using SkeletonView.sizes.###)
19+
*/
20+
size?: Size;
21+
/**
22+
* Add content to the skeleton.
23+
* Types: AVATAR and THUMBNAIL (using SkeletonView.contentTypes.###)
24+
*/
25+
contentType?: ContentType;
26+
/**
27+
* Whether to hide the list item template separator
28+
*/
29+
hideSeparator?: boolean;
30+
/**
31+
* Whether to show the last list item template separator
32+
*/
33+
showLastSeparator?: boolean;
34+
/**
35+
* Extra content to be rendered on the end of the list item
36+
*/
37+
renderEndContent?: () => React.ReactElement | undefined;
38+
}
1539
export interface SkeletonViewProps extends AccessibilityProps {
1640
/**
1741
* The content has been loaded, start fading out the skeleton and fading in the content
1842
*/
1943
showContent?: boolean;
2044
/**
21-
* Custom value of any type to pass on to SkeletonView and receive back in the renderContent callback
45+
* A function that will render the content once the content is ready (i.e. showContent is true).
46+
* The method will be called with the Skeleton's customValue (i.e. renderContent(props?.customValue))
2247
*/
23-
contentData?: any;
48+
renderContent?: (customValue?: any) => React.ReactNode;
2449
/**
25-
* A function that will render the content once the content is ready (i.e. showContent is true).
26-
* The method will be called with the Skeleton's contentData (i.e. renderContent(props?.contentData))
50+
* Custom value of any type to pass on to SkeletonView and receive back in the renderContent callback.
51+
*/
52+
customValue?: any;
53+
/**
54+
* @deprecated
55+
* - Please use customValue instead.
56+
* - Custom value of any type to pass on to SkeletonView and receive back in the renderContent callback.
2757
*/
28-
renderContent?: (contentData?: any) => React.ReactNode;
58+
contentData?: any;
2959
/**
3060
* The type of the skeleton view.
3161
* Types: LIST_ITEM and TEXT_CONTENT (using SkeletonView.templates.###)
3262
*/
3363
template?: Template;
64+
/**
65+
* Props that are available when using template={SkeletonView.templates.LIST_ITEM}
66+
*/
67+
listProps?: SkeletonListProps;
3468
/**
3569
* An object that holds the number of times the skeleton will appear, and (optionally) the key.
3670
* The key will actually be `${key}-${index}` if a key is given or `${index}` if no key is given.
@@ -44,21 +78,29 @@ export interface SkeletonViewProps extends AccessibilityProps {
4478
*/
4579
timesKey?: string;
4680
/**
47-
* The size of the skeleton view.
48-
* Types: SMALL and LARGE (using SkeletonView.sizes.###)
81+
* @deprecated
82+
* - Pass via listProps instead.
83+
* - The size of the skeleton view.
84+
* - Types: SMALL and LARGE (using SkeletonView.sizes.###)
4985
*/
5086
size?: Size;
5187
/**
52-
* Add content to the skeleton.
53-
* Types: AVATAR and THUMBNAIL (using SkeletonView.contentTypes.###)
88+
* @deprecated
89+
* - Pass via listProps instead.
90+
* - Add content to the skeleton.
91+
* - Types: AVATAR and THUMBNAIL (using SkeletonView.contentTypes.###)
5492
*/
5593
contentType?: ContentType;
5694
/**
57-
* Whether to hide the list item template separator
95+
* @deprecated
96+
* - Pass via listProps instead.
97+
* - Whether to hide the list item template separator
5898
*/
5999
hideSeparator?: boolean;
60100
/**
61-
* Whether to show the last list item template separator
101+
* @deprecated
102+
* - Pass via listProps instead.
103+
* - Whether to show the last list item template separator
62104
*/
63105
showLastSeparator?: boolean;
64106
/**
@@ -124,7 +166,11 @@ declare class SkeletonView extends Component<SkeletonViewProps, SkeletonState> {
124166
width: number;
125167
height: number;
126168
};
127-
getContentSize: () => 48 | 40;
169+
get size(): Size | undefined;
170+
get contentSize(): 48 | 40;
171+
get contentType(): ContentType | undefined;
172+
get hideSeparator(): boolean | undefined;
173+
get showLastSeparator(): boolean | undefined;
128174
renderListItemLeftContent: () => JSX.Element | undefined;
129175
renderStrip: (isMain: boolean, length: number, marginTop: number) => JSX.Element;
130176
renderListItemContentStrips: () => JSX.Element;

0 commit comments

Comments
 (0)