Skip to content

Commit fa0447c

Browse files
authored
Props deprecations - CardImage, CardSection, StateScreen (#1023)
* Props deprecations - CardImage, CardSection, StateScreen * Editing TODO comments; replacing console with LogService; removing deprecated props from demo screens; adding 'source' to StateScreen typings * console to LogService * npm run build:dev
1 parent 49c9723 commit fa0447c

File tree

14 files changed

+70
-46
lines changed

14 files changed

+70
-46
lines changed

demo/src/screens/componentScreens/CardsScreen.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default class CardsScreen extends Component<
4747
activeOpacity={1}
4848
marginR-20
4949
>
50-
<Card.Section imageSource={cardImage} imageStyle={{height: '100%'}} />
50+
<Card.Section source={cardImage} imageStyle={{height: '100%'}} />
5151
</Card>
5252
<Card
5353
height={120}
@@ -61,7 +61,7 @@ export default class CardsScreen extends Component<
6161
borderWidth: 3
6262
}}
6363
>
64-
<Card.Section imageSource={cardImage} imageStyle={{height: '100%'}} />
64+
<Card.Section source={cardImage} imageStyle={{height: '100%'}} />
6565
</Card>
6666
</View>
6767
);
@@ -122,14 +122,14 @@ export default class CardsScreen extends Component<
122122
>
123123
{isImageOnLeft && (
124124
<Card.Section
125-
imageSource={cardImage}
125+
source={cardImage}
126126
imageStyle={{width: 115, height: '100%'}}
127127
/>
128128
)}
129129
{useSection ? this.renderTextSection() : this.renderText()}
130130
{!isImageOnLeft && (
131131
<Card.Section
132-
imageSource={cardImage}
132+
source={cardImage}
133133
imageStyle={{width: 115, height: '100%'}}
134134
/>
135135
)}
@@ -147,7 +147,7 @@ export default class CardsScreen extends Component<
147147
]}
148148
style={{padding: 20}}
149149
/>
150-
<Card.Section imageSource={cardImage2} imageStyle={{height: 120}} />
150+
<Card.Section source={cardImage2} imageStyle={{height: 120}} />
151151
</Card>
152152
);
153153
};
@@ -223,7 +223,7 @@ export default class CardsScreen extends Component<
223223
<Card.Section
224224
flex
225225
backgroundColor={Colors.blue20}
226-
imageSource={featureIcon}
226+
source={featureIcon}
227227
imageStyle={{
228228
width: 25,
229229
height: 25,
@@ -242,7 +242,7 @@ export default class CardsScreen extends Component<
242242
{'marginL-5': true},
243243
<Card.Section
244244
flex
245-
imageSource={cardImage2}
245+
source={cardImage2}
246246
imageStyle={{height: '100%'}}
247247
content={[
248248
{text: 'Special sale!', text70: true, blue10: true},
@@ -336,7 +336,7 @@ export default class CardsScreen extends Component<
336336
onPress={() => console.log('press on a card')}
337337
>
338338
<Card.Section
339-
imageSource={post.coverImage}
339+
source={post.coverImage}
340340
imageStyle={{height: 160}}
341341
/>
342342

demo/src/screens/componentScreens/EmptyStateScreen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ export default class EmptyStateScreen extends Component {
3636
title='Oppsie (with local image)'
3737
subtitle='Nothing to see here..'
3838
ctaLabel='OK'
39-
imageSource={localImageSource}
39+
source={localImageSource}
4040
/>
4141
</View>
4242
<View style={styles.pageView}>
4343
<StateScreen
4444
title='Oppsie (with remote image)'
4545
subtitle='Nothing to see here..'
4646
ctaLabel='OK'
47-
imageSource={remoteImageSource}
47+
source={remoteImageSource}
4848
/>
4949
</View>
5050
</ScrollView>

demo/src/screens/componentScreens/ExpandableSectionScreen.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const elements = [
1717
]}
1818
style={{padding: 20}}
1919
/>
20-
<Card.Section imageSource={cardImage2} imageStyle={{height: 120}} />
20+
<Card.Section source={cardImage2} imageStyle={{height: 120}} />
2121
</Card>,
2222
<Card style={{marginBottom: 10}} onPress={() => {}}>
2323
<Card.Section
@@ -27,7 +27,7 @@ const elements = [
2727
]}
2828
style={{padding: 20}}
2929
/>
30-
<Card.Section imageSource={cardImage} imageStyle={{height: 120}} />
30+
<Card.Section source={cardImage} imageStyle={{height: 120}} />
3131
</Card>,
3232
<Card style={{marginBottom: 10}} onPress={() => {}}>
3333
<Card.Section
@@ -37,7 +37,7 @@ const elements = [
3737
]}
3838
style={{padding: 20}}
3939
/>
40-
<Card.Section imageSource={cardImage2} imageStyle={{height: 120}} />
40+
<Card.Section source={cardImage2} imageStyle={{height: 120}} />
4141
</Card>
4242
];
4343

demo/src/screens/componentScreens/OverlaysScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default class OverlaysScreen extends Component {
7878
Card.Image Overlay
7979
</Text>
8080
<Card marginB-s4 padding-s2 borderRadius={4} row height={106}>
81-
<Card.Image style={styles.cardImage} imageSource={image} overlayType={Image.overlayTypes.VERTICAL}/>
81+
<Card.Image style={styles.cardImage} source={image} overlayType={Image.overlayTypes.VERTICAL}/>
8282
<View flex marginL-s2 centerV>
8383
<Text text50>{Image.overlayTypes.VERTICAL}</Text>
8484
<Text text70>Ipsum nostrud officia deserunt irure eu.</Text>

generatedTypes/commons/new.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ export { default as asBaseComponent, BaseComponentInjectedProps } from './asBase
33
export { default as forwardRef, ForwardRefInjectedProps } from './forwardRef';
44
export { default as withScrollEnabler, WithScrollEnablerProps } from './withScrollEnabler';
55
export { default as withScrollReached, WithScrollReachedProps } from './withScrollReached';
6-
export { default as useToggleValue } from './useToggleValue';
76
export { ContainerModifiers, MarginModifiers, PaddingModifiers, TypographyModifiers, ColorsModifiers, BackgroundColorModifier } from './modifiers';

generatedTypes/components/card/CardImage.d.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export declare type CardImageProps = Omit<ImageProps, 'source'> & {
66
* Image source, either remote source or local. Note: for remote pass object {uri: <remote_uri_string>}
77
*/
88
imageSource?: ImageSourcePropType;
9+
source?: ImageSourcePropType;
910
/**
1011
* Image width
1112
*/
@@ -24,11 +25,6 @@ export declare type CardImageProps = Omit<ImageProps, 'source'> & {
2425
* border radius, basically for Android since overflow doesn't work well (deprecated)
2526
*/
2627
borderRadius?: number;
27-
/**
28-
* Image source, either remote source or local. Note: for remote pass object {uri: <remote_uri_string>}
29-
* TODO: Remove after imageSource deprecation - should take it from Image props
30-
*/
31-
source?: ImageSourcePropType;
3228
};
3329
declare const _default: React.ComponentType<CardImageProps>;
3430
export default _default;

generatedTypes/components/card/CardSection.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export declare type CardSectionProps = ViewPropTypes & {
3232
* Will be used for the background when provided
3333
*/
3434
imageSource?: ImageSourcePropType;
35+
source?: ImageSourcePropType;
3536
/**
3637
* The style for the background image
3738
*/
@@ -67,6 +68,7 @@ declare const _default: React.ComponentClass<ViewPropTypes & {
6768
* Will be used for the background when provided
6869
*/
6970
imageSource?: number | import("react-native").ImageURISource | import("react-native").ImageURISource[] | undefined;
71+
source?: number | import("react-native").ImageURISource | import("react-native").ImageURISource[] | undefined;
7072
/**
7173
* The style for the background image
7274
*/

generatedTypes/components/floatingButton/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { PropsWithChildren } from 'react';
22
import { ButtonPropTypes } from '../button';
33
export interface FloatingButtonProps {
44
/**
@@ -8,11 +8,11 @@ export interface FloatingButtonProps {
88
/**
99
* Button element (all Button's component's props)
1010
*/
11-
button?: ButtonPropTypes;
11+
button?: PropsWithChildren<ButtonPropTypes>;
1212
/**
1313
* Secondary button element (all Button's component's props)
1414
*/
15-
secondaryButton?: ButtonPropTypes;
15+
secondaryButton?: PropsWithChildren<ButtonPropTypes>;
1616
/**
1717
* The bottom margin of the button, or secondary button if passed
1818
*/

generatedTypes/hooks/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as useToggleValue } from './useToggleValue';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const useToggleValue: (initial: any, second?: any) => any[];
2+
export default useToggleValue;

src/components/card/CardImage.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import React, {PureComponent} from 'react';
22
import {View, StyleSheet, ImageSourcePropType} from 'react-native';
3+
import {LogService} from '../../services';
34
// import {BaseComponent} from '../../commons';
45
import Image, {ImageProps} from '../image';
56
import * as CardPresenter from './CardPresenter';
67
import asCardChild, {asCardChildProps} from './asCardChild';
7-
// @ts-ignore
8-
import {LogService} from '../../services';
98

10-
// TODO: Remove omitting source after imageSource deprecation
9+
10+
// TODO: Remove omitting source after imageSource deprecation (since it's required for Image)
1111
export type CardImageProps = Omit<ImageProps, 'source'> & {
1212
/**
1313
* Image source, either remote source or local. Note: for remote pass object {uri: <remote_uri_string>}
1414
*/
1515
imageSource?: ImageSourcePropType;
16+
source?: ImageSourcePropType; //TODO: Remove after imageSource deprecation - should take it from ImageProps
1617
/**
1718
* Image width
1819
*/
@@ -31,11 +32,6 @@ export type CardImageProps = Omit<ImageProps, 'source'> & {
3132
* border radius, basically for Android since overflow doesn't work well (deprecated)
3233
*/
3334
borderRadius?: number;
34-
/**
35-
* Image source, either remote source or local. Note: for remote pass object {uri: <remote_uri_string>}
36-
* TODO: Remove after imageSource deprecation - should take it from Image props
37-
*/
38-
source?: ImageSourcePropType;
3935
};
4036

4137
type Props = CardImageProps & asCardChildProps;
@@ -52,12 +48,14 @@ class CardImage extends PureComponent<Props> {
5248
constructor(props: Props) {
5349
super(props);
5450

51+
this.styles = createStyles(props);
52+
53+
if (props.imageSource) {
54+
LogService.deprecationWarn({component: 'CardImage', oldProp: 'imageSource', newProp: 'source'});
55+
}
5556
if (props.borderRadius) {
56-
LogService.warn(
57-
'uilib: Please stop passing borderRadius to Card.Image, it will get the borderRadius from the Card'
58-
);
57+
LogService.deprecationWarn({component: 'CardImage', oldProp: 'borderRadius'});
5958
}
60-
this.styles = createStyles(props);
6159
}
6260

6361
render() {

src/components/card/CardSection.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import _ from 'lodash';
22
import React, {PureComponent} from 'react';
33
import {StyleSheet, ViewStyle, ImageStyle, ImageSourcePropType, StyleProp} from 'react-native';
4+
import {LogService} from '../../services';
45
import {asBaseComponent} from '../../commons/new';
56
import View, {ViewPropTypes} from '../view';
67
import Text, {TextPropTypes} from '../text';
78
import Image, {ImageProps} from '../image';
89
import asCardChild, {asCardChildProps} from './asCardChild';
910

11+
1012
type ContentType = TextPropTypes & {text?: string};
1113

1214
export type CardSectionProps = ViewPropTypes & {
@@ -35,6 +37,7 @@ export type CardSectionProps = ViewPropTypes & {
3537
* Will be used for the background when provided
3638
*/
3739
imageSource?: ImageSourcePropType;
40+
source?: ImageSourcePropType;
3841
/**
3942
* The style for the background image
4043
*/
@@ -54,6 +57,14 @@ type Props = CardSectionProps & asCardChildProps;
5457
class CardSection extends PureComponent<Props> {
5558
static displayName = 'Card.Section';
5659

60+
constructor(props: Props) {
61+
super(props);
62+
63+
if (props.imageSource) {
64+
LogService.deprecationWarn({component: 'CardSection', oldProp: 'imageSource', newProp: 'source'});
65+
}
66+
}
67+
5768
renderContent = () => {
5869
const {
5970
content,
@@ -94,13 +105,15 @@ class CardSection extends PureComponent<Props> {
94105
};
95106

96107
renderImage = () => {
97-
const {imageSource, imageStyle, imageProps, testID} = this.props;
108+
const {source, imageSource, imageStyle, imageProps, testID} = this.props;
109+
const finalSource = source || imageSource;
110+
98111
// not actually needed, instead of adding ts-ignore
99-
if (imageSource) {
112+
if (finalSource) {
100113
return (
101114
<Image
102115
testID={`${testID}.image`}
103-
source={imageSource}
116+
source={finalSource}
104117
style={imageStyle}
105118
customOverlayContent={this.renderContent()}
106119
{...imageProps}
@@ -111,15 +124,18 @@ class CardSection extends PureComponent<Props> {
111124

112125
render() {
113126
const {
127+
source,
114128
imageSource,
115129
context: {borderStyle},
116130
style,
117131
...others
118132
} = this.props;
133+
const finalSource = source || imageSource;
134+
119135
return (
120136
<View style={[styles.container, borderStyle, style]} {...others}>
121-
{imageSource && this.renderImage()}
122-
{!imageSource && this.renderContent()}
137+
{finalSource && this.renderImage()}
138+
{!finalSource && this.renderContent()}
123139
</View>
124140
);
125141
}

src/components/stateScreen/index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import _ from 'lodash';
22
import PropTypes from 'prop-types';
33
import React from 'react';
44
import {StyleSheet} from 'react-native';
5+
import {LogService} from '../../services';
56
import {Constants} from '../../helpers';
67
import {Typography, Colors} from '../../style';
78
import {BaseComponent} from '../../commons';
@@ -22,6 +23,7 @@ export default class StateScreen extends BaseComponent {
2223
* The image source that's showing at the top. use an image that was required locally
2324
*/
2425
imageSource: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
26+
source: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
2527
/**
2628
* To to show as the title
2729
*/
@@ -48,23 +50,30 @@ export default class StateScreen extends BaseComponent {
4850
super(props);
4951

5052
if (props.testId) {
51-
console.warn('StateScreen prop \'testId\' is deprecated. Please use RN \'testID\' prop instead.');
53+
LogService.deprecationWarn({component: 'StateScreen', oldProp: 'testId', newProp: 'testID'});
54+
55+
}
56+
if (props.imageSource) {
57+
LogService.deprecationWarn({component: 'StateScreen', oldProp: 'imageSource', newProp: 'source'});
5258
}
5359
}
5460

5561
generateStyles() {
56-
const {imageSource} = this.props;
57-
const isRemoteImage = _.isObject(imageSource) && Boolean(imageSource.uri);
62+
const {source, imageSource} = this.props;
63+
const finalSource = source || imageSource;
64+
65+
const isRemoteImage = _.isObject(finalSource) && Boolean(finalSource.uri);
5866
this.styles = createStyles(isRemoteImage);
5967
}
6068

6169
render() {
62-
// TODO: remove testId after deprecation
63-
const {title, subtitle, imageSource, ctaLabel, onCtaPress, testId, testID} = this.props;
70+
// TODO: remove testId and imageSource after deprecation
71+
const {title, subtitle, source, imageSource, ctaLabel, onCtaPress, testId, testID} = this.props;
72+
const finalSource = source || imageSource;
6473

6574
return (
6675
<View style={this.styles.container} testID={testID || testId}>
67-
<Image style={this.styles.image} resizeMode={'contain'} source={imageSource}/>
76+
<Image style={this.styles.image} resizeMode={'contain'} source={finalSource}/>
6877
<Text style={[this.styles.title]}>{title}</Text>
6978
<Text style={[this.styles.subtitle]}>{subtitle}</Text>
7079
<Button

typings/components/StateScreen.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {BaseComponent} from '../commons';
44

55
export interface StateScreenProps {
66
imageSource?: ImageSourcePropType;
7+
source?: ImageSourcePropType;
78
title: string;
89
subtitle?: ReactNode[];
910
ctaLabel?: string;

0 commit comments

Comments
 (0)