Skip to content

Commit 2962e8e

Browse files
authored
Fix/skeleton types (#1998)
* Skeleton related types fixes * Prettify * Add relevant modifiers to SkeletonViewProps * Revert default type
1 parent f96c37e commit 2962e8e

File tree

5 files changed

+33
-31
lines changed

5 files changed

+33
-31
lines changed

demo/src/screens/ExampleScreenPresenter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface RadioGroupOptions {
2222
useValueAsLabel?: boolean;
2323
}
2424

25-
export function renderHeader(title: string, others: TextProps) {
25+
export function renderHeader(title: string, others?: TextProps) {
2626
return (
2727
<Text text30 $textDefault {...others}>
2828
{title}

demo/src/screens/componentScreens/SkeletonViewScreen.tsx

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

2019
const AVATAR_SIZE = 48;
@@ -153,7 +152,7 @@ export default class SkeletonViewScreen extends Component {
153152
<Text>Verified</Text>
154153
</View>
155154
);
156-
}
155+
};
157156

158157
renderListItemsData = (customValue?: any) => {
159158
const {isLarge, showEndContent} = this.state;
@@ -163,13 +162,7 @@ export default class SkeletonViewScreen extends Component {
163162
<React.Fragment>
164163
{_.times(NUMBER_OF_ITEMS_TO_SHOW, index => {
165164
return (
166-
<ListItem
167-
key={index}
168-
activeBackgroundColor={Colors.grey60}
169-
activeOpacity={0.3}
170-
height={90}
171-
onPress={() => Alert.alert(`pressed on order #${index + 1}`)}
172-
>
165+
<ListItem key={index} height={90} onPress={() => Alert.alert(`pressed on order #${index + 1}`)}>
173166
{hasAvatar && this.renderAvatar()}
174167
{hasThumbnail && this.renderThumbnail()}
175168
<ListItem.Part middle column containerStyle={[styles.border, {marginLeft: 18}]}>
@@ -248,16 +241,17 @@ export default class SkeletonViewScreen extends Component {
248241
const imageSize = this.getImageSize();
249242

250243
return (
251-
<View row spread margin-page>
252-
<SkeletonView
253-
width={imageSize}
254-
height={imageSize}
255-
showContent={isDataAvailable}
256-
renderContent={this.renderImagesData}
257-
accessibilityLabel={'Loading image'}
258-
times={IMAGE_URIS.length}
259-
/>
260-
</View>
244+
<SkeletonView
245+
row
246+
spread
247+
margin-page
248+
width={imageSize}
249+
height={imageSize}
250+
showContent={isDataAvailable}
251+
renderContent={this.renderImagesData}
252+
accessibilityLabel={'Loading image'}
253+
times={IMAGE_URIS.length}
254+
/>
261255
);
262256
};
263257

@@ -337,11 +331,11 @@ export default class SkeletonViewScreen extends Component {
337331
borderRadius={5}
338332
style={{marginTop: 5}}
339333
showContent={isDataAvailable}
340-
renderContent={() => <Button label='Info' size={'small'} link/>}
334+
renderContent={() => <Button label={'Info'} size={Button.sizes.small} link/>}
341335
/>
342336
</View>
343337
<SkeletonView
344-
shimmerStyle={{width: '100%'/* , height: 30 */}}
338+
shimmerStyle={{width: '100%' /* , height: 30 */}}
345339
height={10}
346340
borderRadius={5}
347341
showContent={isDataAvailable}
@@ -350,7 +344,7 @@ export default class SkeletonViewScreen extends Component {
350344
/>
351345
</View>
352346
);
353-
}
347+
};
354348

355349
renderContent = () => {
356350
const {isDataAvailable} = this.state;

src/commons/new.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export {default as Config} from './Config';
99

1010
export {
1111
ContainerModifiers,
12+
AlignmentModifiers,
1213
MarginModifiers,
1314
PaddingModifiers,
1415
TypographyModifiers,

src/components/listItem/types.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {PureComponent} from 'react';
2-
import {ViewStyle} from 'react-native';
2+
import {StyleProp, ViewStyle} from 'react-native';
33
import {TouchableOpacityProps} from '../touchableOpacity';
44

55
export type ListItemProps = {
@@ -59,7 +59,7 @@ export type ListItemPartProps = {
5959
/**
6060
* container style
6161
*/
62-
containerStyle?: ViewStyle;
62+
containerStyle?: StyleProp<ViewStyle>;
6363
};
6464

6565
/**

src/components/skeletonView/index.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ 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, BaseComponentInjectedProps, MarginModifiers} from '../../commons/new';
7+
import {
8+
Constants,
9+
asBaseComponent,
10+
BaseComponentInjectedProps,
11+
AlignmentModifiers,
12+
PaddingModifiers,
13+
MarginModifiers
14+
} from '../../commons/new';
815
import {extractAccessibilityProps} from '../../commons/modifiers';
916

1017
const LinearGradient = LinearGradientPackage?.default;
@@ -53,7 +60,7 @@ export interface SkeletonListProps {
5360
renderEndContent?: () => React.ReactElement | undefined;
5461
}
5562

56-
export interface SkeletonViewProps extends AccessibilityProps, MarginModifiers {
63+
export interface SkeletonViewProps extends AccessibilityProps, AlignmentModifiers, PaddingModifiers, MarginModifiers {
5764
/**
5865
* The content has been loaded, start fading out the skeleton and fading in the content
5966
*/
@@ -132,7 +139,7 @@ export interface SkeletonViewProps extends AccessibilityProps, MarginModifiers {
132139
* The colors of the skeleton view, the array length has to be >=2
133140
* default: [Colors.grey70, Colors.grey60, Colors.grey70]
134141
*/
135-
colors?: string[]
142+
colors?: string[];
136143
/**
137144
* The border radius of the skeleton view
138145
*/
@@ -141,7 +148,7 @@ export interface SkeletonViewProps extends AccessibilityProps, MarginModifiers {
141148
* Whether the skeleton is a circle (will override the borderRadius)
142149
*/
143150
circle?: boolean;
144-
/**
151+
/**
145152
* Additional style to the skeleton view
146153
*/
147154
shimmerStyle?: StyleProp<ViewStyle>;
@@ -245,7 +252,7 @@ class SkeletonView extends Component<InternalSkeletonViewProps, SkeletonState> {
245252
if (circle || circleOverride) {
246253
borderRadius = BorderRadiuses.br100;
247254
size = Math.max(width || 0, height);
248-
}
255+
}
249256

250257
return {
251258
shimmerColors: colors || [Colors.$backgroundNeutral, Colors.$backgroundNeutralMedium, Colors.$backgroundNeutral],
@@ -366,7 +373,7 @@ class SkeletonView extends Component<InternalSkeletonViewProps, SkeletonState> {
366373
renderAdvanced = () => {
367374
const {children, renderContent, showContent, style, ...others} = this.props;
368375
const data = showContent && _.isFunction(renderContent) ? renderContent(this.props) : children;
369-
376+
370377
return (
371378
<View style={style} {...this.getAccessibilityProps('Loading content')} {...others}>
372379
<ShimmerPlaceholder {...this.getDefaultSkeletonProps()} {...others}>

0 commit comments

Comments
 (0)