Skip to content

Props deprecations - CardImage, CardSection, StateScreen #1023

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
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 8 additions & 8 deletions demo/src/screens/componentScreens/CardsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class CardsScreen extends Component<
activeOpacity={1}
marginR-20
>
<Card.Section imageSource={cardImage} imageStyle={{height: '100%'}} />
<Card.Section source={cardImage} imageStyle={{height: '100%'}} />
</Card>
<Card
height={120}
Expand All @@ -61,7 +61,7 @@ export default class CardsScreen extends Component<
borderWidth: 3
}}
>
<Card.Section imageSource={cardImage} imageStyle={{height: '100%'}} />
<Card.Section source={cardImage} imageStyle={{height: '100%'}} />
</Card>
</View>
);
Expand Down Expand Up @@ -122,14 +122,14 @@ export default class CardsScreen extends Component<
>
{isImageOnLeft && (
<Card.Section
imageSource={cardImage}
source={cardImage}
imageStyle={{width: 115, height: '100%'}}
/>
)}
{useSection ? this.renderTextSection() : this.renderText()}
{!isImageOnLeft && (
<Card.Section
imageSource={cardImage}
source={cardImage}
imageStyle={{width: 115, height: '100%'}}
/>
)}
Expand All @@ -147,7 +147,7 @@ export default class CardsScreen extends Component<
]}
style={{padding: 20}}
/>
<Card.Section imageSource={cardImage2} imageStyle={{height: 120}} />
<Card.Section source={cardImage2} imageStyle={{height: 120}} />
</Card>
);
};
Expand Down Expand Up @@ -223,7 +223,7 @@ export default class CardsScreen extends Component<
<Card.Section
flex
backgroundColor={Colors.blue20}
imageSource={featureIcon}
source={featureIcon}
imageStyle={{
width: 25,
height: 25,
Expand All @@ -242,7 +242,7 @@ export default class CardsScreen extends Component<
{'marginL-5': true},
<Card.Section
flex
imageSource={cardImage2}
source={cardImage2}
imageStyle={{height: '100%'}}
content={[
{text: 'Special sale!', text70: true, blue10: true},
Expand Down Expand Up @@ -336,7 +336,7 @@ export default class CardsScreen extends Component<
onPress={() => console.log('press on a card')}
>
<Card.Section
imageSource={post.coverImage}
source={post.coverImage}
imageStyle={{height: 160}}
/>

Expand Down
4 changes: 2 additions & 2 deletions demo/src/screens/componentScreens/EmptyStateScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export default class EmptyStateScreen extends Component {
title='Oppsie (with local image)'
subtitle='Nothing to see here..'
ctaLabel='OK'
imageSource={localImageSource}
source={localImageSource}
/>
</View>
<View style={styles.pageView}>
<StateScreen
title='Oppsie (with remote image)'
subtitle='Nothing to see here..'
ctaLabel='OK'
imageSource={remoteImageSource}
source={remoteImageSource}
/>
</View>
</ScrollView>
Expand Down
6 changes: 3 additions & 3 deletions demo/src/screens/componentScreens/ExpandableSectionScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const elements = [
]}
style={{padding: 20}}
/>
<Card.Section imageSource={cardImage2} imageStyle={{height: 120}} />
<Card.Section source={cardImage2} imageStyle={{height: 120}} />
</Card>,
<Card style={{marginBottom: 10}} onPress={() => {}}>
<Card.Section
Expand All @@ -27,7 +27,7 @@ const elements = [
]}
style={{padding: 20}}
/>
<Card.Section imageSource={cardImage} imageStyle={{height: 120}} />
<Card.Section source={cardImage} imageStyle={{height: 120}} />
</Card>,
<Card style={{marginBottom: 10}} onPress={() => {}}>
<Card.Section
Expand All @@ -37,7 +37,7 @@ const elements = [
]}
style={{padding: 20}}
/>
<Card.Section imageSource={cardImage2} imageStyle={{height: 120}} />
<Card.Section source={cardImage2} imageStyle={{height: 120}} />
</Card>
];

Expand Down
2 changes: 1 addition & 1 deletion demo/src/screens/componentScreens/OverlaysScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default class OverlaysScreen extends Component {
Card.Image Overlay
</Text>
<Card marginB-s4 padding-s2 borderRadius={4} row height={106}>
<Card.Image style={styles.cardImage} imageSource={image} overlayType={Image.overlayTypes.VERTICAL}/>
<Card.Image style={styles.cardImage} source={image} overlayType={Image.overlayTypes.VERTICAL}/>
<View flex marginL-s2 centerV>
<Text text50>{Image.overlayTypes.VERTICAL}</Text>
<Text text70>Ipsum nostrud officia deserunt irure eu.</Text>
Expand Down
22 changes: 10 additions & 12 deletions src/components/card/CardImage.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import React, {PureComponent} from 'react';
import {View, StyleSheet, ImageSourcePropType} from 'react-native';
import {LogService} from '../../services';
// import {BaseComponent} from '../../commons';
import Image, {ImageProps} from '../image';
import * as CardPresenter from './CardPresenter';
import asCardChild, {asCardChildProps} from './asCardChild';
// @ts-ignore
import {LogService} from '../../services';

// TODO: Remove omitting source after imageSource deprecation

// TODO: Remove omitting source after imageSource deprecation (since it's required for Image)
export type CardImageProps = Omit<ImageProps, 'source'> & {
/**
* Image source, either remote source or local. Note: for remote pass object {uri: <remote_uri_string>}
*/
imageSource?: ImageSourcePropType;
source?: ImageSourcePropType; //TODO: Remove after imageSource deprecation - should take it from ImageProps
/**
* Image width
*/
Expand All @@ -31,11 +32,6 @@ export type CardImageProps = Omit<ImageProps, 'source'> & {
* border radius, basically for Android since overflow doesn't work well (deprecated)
*/
borderRadius?: number;
/**
* Image source, either remote source or local. Note: for remote pass object {uri: <remote_uri_string>}
* TODO: Remove after imageSource deprecation - should take it from Image props
*/
source?: ImageSourcePropType;
};

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

this.styles = createStyles(props);

if (props.imageSource) {
LogService.deprecationWarn({component: 'CardImage', oldProp: 'imageSource', newProp: 'source'});
}
if (props.borderRadius) {
LogService.warn(
'uilib: Please stop passing borderRadius to Card.Image, it will get the borderRadius from the Card'
);
LogService.deprecationWarn({component: 'CardImage', oldProp: 'borderRadius'});
Copy link
Collaborator

@M-i-k-e-l M-i-k-e-l Nov 15, 2020

Choose a reason for hiding this comment

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

That's a good idea to add this option, but the current message expects the newProp (actually this is my bad, I need to fix LogService typings).
You can use the warn method for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My suggestion is that we change the LogService deprecationWarn's massage to accommodate this scenario. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Added this option in the other PR

}
this.styles = createStyles(props);
}

render() {
Expand Down
26 changes: 21 additions & 5 deletions src/components/card/CardSection.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import _ from 'lodash';
import React, {PureComponent} from 'react';
import {StyleSheet, ViewStyle, ImageStyle, ImageSourcePropType, StyleProp} from 'react-native';
import {LogService} from '../../services';
import {asBaseComponent} from '../../commons/new';
import View, {ViewPropTypes} from '../view';
import Text, {TextPropTypes} from '../text';
import Image, {ImageProps} from '../image';
import asCardChild, {asCardChildProps} from './asCardChild';


type ContentType = TextPropTypes & {text?: string};

export type CardSectionProps = ViewPropTypes & {
Expand Down Expand Up @@ -35,6 +37,7 @@ export type CardSectionProps = ViewPropTypes & {
* Will be used for the background when provided
*/
imageSource?: ImageSourcePropType;
source?: ImageSourcePropType;
/**
* The style for the background image
*/
Expand All @@ -54,6 +57,14 @@ type Props = CardSectionProps & asCardChildProps;
class CardSection extends PureComponent<Props> {
static displayName = 'Card.Section';

constructor(props: Props) {
super(props);

if (props.imageSource) {
LogService.deprecationWarn({component: 'CardSection', oldProp: 'imageSource', newProp: 'source'});
}
}

renderContent = () => {
const {
content,
Expand Down Expand Up @@ -94,13 +105,15 @@ class CardSection extends PureComponent<Props> {
};

renderImage = () => {
const {imageSource, imageStyle, imageProps, testID} = this.props;
const {source, imageSource, imageStyle, imageProps, testID} = this.props;
const finalSource = source || imageSource;

// not actually needed, instead of adding ts-ignore
if (imageSource) {
if (finalSource) {
return (
<Image
testID={`${testID}.image`}
source={imageSource}
source={finalSource}
style={imageStyle}
customOverlayContent={this.renderContent()}
{...imageProps}
Expand All @@ -111,15 +124,18 @@ class CardSection extends PureComponent<Props> {

render() {
const {
source,
imageSource,
context: {borderStyle},
style,
...others
} = this.props;
const finalSource = source || imageSource;

return (
<View style={[styles.container, borderStyle, style]} {...others}>
{imageSource && this.renderImage()}
{!imageSource && this.renderContent()}
{finalSource && this.renderImage()}
{!finalSource && this.renderContent()}
</View>
);
}
Expand Down
21 changes: 15 additions & 6 deletions src/components/stateScreen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _ from 'lodash';
import PropTypes from 'prop-types';
import React from 'react';
import {StyleSheet} from 'react-native';
import {LogService} from '../../services';
import {Constants} from '../../helpers';
import {Typography, Colors} from '../../style';
import {BaseComponent} from '../../commons';
Expand All @@ -22,6 +23,7 @@ export default class StateScreen extends BaseComponent {
* The image source that's showing at the top. use an image that was required locally
*/
imageSource: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
source: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
/**
* To to show as the title
*/
Expand All @@ -48,23 +50,30 @@ export default class StateScreen extends BaseComponent {
super(props);

if (props.testId) {
console.warn('StateScreen prop \'testId\' is deprecated. Please use RN \'testID\' prop instead.');
LogService.deprecationWarn({component: 'StateScreen', oldProp: 'testId', newProp: 'testID'});

}
if (props.imageSource) {
LogService.deprecationWarn({component: 'StateScreen', oldProp: 'imageSource', newProp: 'source'});
}
}

generateStyles() {
const {imageSource} = this.props;
const isRemoteImage = _.isObject(imageSource) && Boolean(imageSource.uri);
const {source, imageSource} = this.props;
const finalSource = source || imageSource;

const isRemoteImage = _.isObject(finalSource) && Boolean(finalSource.uri);
this.styles = createStyles(isRemoteImage);
}

render() {
// TODO: remove testId after deprecation
const {title, subtitle, imageSource, ctaLabel, onCtaPress, testId, testID} = this.props;
// TODO: remove testId and imageSource after deprecation
const {title, subtitle, source, imageSource, ctaLabel, onCtaPress, testId, testID} = this.props;
const finalSource = source || imageSource;

return (
<View style={this.styles.container} testID={testID || testId}>
<Image style={this.styles.image} resizeMode={'contain'} source={imageSource}/>
<Image style={this.styles.image} resizeMode={'contain'} source={finalSource}/>
<Text style={[this.styles.title]}>{title}</Text>
<Text style={[this.styles.subtitle]}>{subtitle}</Text>
<Button
Expand Down
1 change: 1 addition & 0 deletions typings/components/StateScreen.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {BaseComponent} from '../commons';

export interface StateScreenProps {
imageSource?: ImageSourcePropType;
source?: ImageSourcePropType;
title: string;
subtitle?: ReactNode[];
ctaLabel?: string;
Expand Down