-
Notifications
You must be signed in to change notification settings - Fork 734
Migrate Card & Card.Image to typescript #805
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
Changes from all commits
484f553
2f1aeac
ca14bce
ee8a946
1405898
1d88a5d
745b8ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import React from 'react'; | ||
declare const CardContext: React.Context<{}>; | ||
export default CardContext; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { ImageSourcePropType } from 'react-native'; | ||
import { ImageProps } from '../image'; | ||
export declare type CardImageProps = ImageProps & { | ||
/** | ||
* Image source, either remote source or local. Note: for remote pass object {uri: <remote_uri_string>} | ||
*/ | ||
imageSource?: ImageSourcePropType; | ||
/** | ||
* Image width | ||
*/ | ||
width?: number | string; | ||
/** | ||
* Image height | ||
*/ | ||
height?: number | string; | ||
/** | ||
* The Image position which determines the appropriate flex-ness of the image and border radius (for Android) | ||
* this prop derived automatically from Card parent component if it rendered as a direct child of the | ||
* Card component | ||
*/ | ||
position?: string[]; | ||
/** | ||
* border radius, basically for Android since overflow doesn't work well (deprecated) | ||
*/ | ||
borderRadius?: number; | ||
}; | ||
declare const _default: React.ComponentType<CardImageProps>; | ||
export default _default; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export declare function extractPositionValues(position: string[] | undefined): { | ||
top: boolean; | ||
left: boolean; | ||
right: boolean; | ||
bottom: boolean; | ||
}; | ||
export declare function generateBorderRadiusStyle({ position, borderRadius }: { | ||
position: string[] | undefined; | ||
borderRadius: number | undefined; | ||
}): { | ||
[key: string]: number | undefined; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { ViewStyle } from 'react-native'; | ||
import { ViewPropTypes } from '../view'; | ||
import { TextPropTypes } from '../text'; | ||
import { ImageProps } from '../image'; | ||
declare type ContentType = TextPropTypes & { | ||
text?: string; | ||
}; | ||
export declare type CardSectionProps = ViewPropTypes & { | ||
/** | ||
* Text content for the CardSection. | ||
* Example: content={[{text: 'You’re Invited!', text70: true, dark10: true}]} | ||
*/ | ||
content?: ContentType[]; | ||
/** | ||
* Style for the content | ||
*/ | ||
contentStyle?: ViewStyle; | ||
/** | ||
* Image props for a leading icon to render before the text | ||
*/ | ||
leadingIcon?: ImageProps; | ||
/** | ||
* Image props for a trailing icon to render after the text | ||
*/ | ||
trailingIcon?: ImageProps; | ||
}; | ||
declare const _default: React.ComponentType<CardSectionProps>; | ||
export default _default; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import React from 'react'; | ||
declare function asCardChild<T>(WrappedComponent: React.ComponentType<any>): React.ComponentType<T>; | ||
export default asCardChild; | ||
export declare type asCardChildProps = { | ||
context?: any; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from 'react'; | ||
import { ViewStyle } from 'react-native'; | ||
import { ViewPropTypes } from '../view'; | ||
import { TouchableOpacityProps } from '../touchableOpacity'; | ||
export declare type CardPropTypes = ViewPropTypes & TouchableOpacityProps & { | ||
/** | ||
* card custom width | ||
*/ | ||
width?: number | string; | ||
/** | ||
* card custom height | ||
*/ | ||
height?: number | string; | ||
/** | ||
* should inner card flow direction be horizontal | ||
*/ | ||
row?: boolean; | ||
/** | ||
* card border radius (will be passed to inner Card.Image component) | ||
*/ | ||
borderRadius?: number; | ||
/** | ||
* action for when pressing the card | ||
*/ | ||
onPress?: () => void; | ||
/** | ||
* whether the card should have shadow or not | ||
*/ | ||
enableShadow?: boolean; | ||
/** | ||
* elevation value (Android only) | ||
*/ | ||
elevation?: number; | ||
/** | ||
* enable blur effect (iOS only) | ||
*/ | ||
enableBlur?: boolean; | ||
/** | ||
* blur option for blur effect according to @react-native-community/blur lib (make sure enableBlur is on) | ||
*/ | ||
blurOptions?: object; | ||
/** | ||
* Additional styles for the top container | ||
*/ | ||
containerStyle?: ViewStyle; | ||
/** | ||
* Adds visual indication that the card is selected | ||
*/ | ||
selected?: boolean; | ||
/** | ||
* Custom options for styling the selection indication | ||
*/ | ||
selectionOptions?: { | ||
icon?: number; | ||
iconColor?: string; | ||
color?: string; | ||
borderWidth?: number; | ||
indicatorSize?: number; | ||
hideIndicator?: boolean; | ||
}; | ||
}; | ||
declare const _default: React.ComponentType<CardPropTypes>; | ||
export default _default; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import React, {PureComponent} from 'react'; | ||
import {View, StyleSheet, ImageSourcePropType} from 'react-native'; | ||
// 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'; | ||
|
||
export type CardImageProps = ImageProps & { | ||
/** | ||
* Image source, either remote source or local. Note: for remote pass object {uri: <remote_uri_string>} | ||
*/ | ||
imageSource?: ImageSourcePropType; | ||
/** | ||
* Image width | ||
*/ | ||
width?: number | string; | ||
/** | ||
* Image height | ||
*/ | ||
height?: number | string; | ||
/** | ||
* The Image position which determines the appropriate flex-ness of the image and border radius (for Android) | ||
* this prop derived automatically from Card parent component if it rendered as a direct child of the | ||
* Card component | ||
*/ | ||
position?: string[]; | ||
/** | ||
* border radius, basically for Android since overflow doesn't work well (deprecated) | ||
*/ | ||
borderRadius?: number; | ||
}; | ||
|
||
type Props = CardImageProps & asCardChildProps; | ||
|
||
/** | ||
* @description: Card.Image, part of the Card component belongs inside a Card (better be a direct child) | ||
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/CardsScreen.js | ||
*/ | ||
class CardImage extends PureComponent<Props> { | ||
static displayName = 'Card.Image'; | ||
|
||
styles: any; | ||
|
||
constructor(props: Props) { | ||
super(props); | ||
|
||
if (props.borderRadius) { | ||
LogService.warn( | ||
'uilib: Please stop passing borderRadius to Card.Image, it will get the borderRadius from the Card' | ||
); | ||
} | ||
this.styles = createStyles(props); | ||
} | ||
|
||
render() { | ||
const { | ||
imageSource, | ||
style, | ||
testID, | ||
overlayType, | ||
context: {borderStyle} | ||
} = this.props; | ||
if (imageSource) { | ||
return ( | ||
<View style={[this.styles.container, borderStyle, style]}> | ||
<Image | ||
testID={testID} | ||
source={imageSource} | ||
style={[this.styles.image]} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where do you pass the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was just this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What not call it |
||
overlayType={overlayType} | ||
/> | ||
</View> | ||
); | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
function createStyles({width, height, context: {position}}: Props) { | ||
const {top, left, right, bottom} = CardPresenter.extractPositionValues( | ||
position | ||
); | ||
return StyleSheet.create({ | ||
container: { | ||
height: left || right ? undefined : height, | ||
width: top || bottom ? undefined : width, | ||
overflow: 'hidden' | ||
}, | ||
image: { | ||
width: undefined, | ||
height: undefined, | ||
flex: 1, | ||
resizeMode: 'cover' | ||
} | ||
}); | ||
} | ||
|
||
export default asCardChild<CardImageProps>(CardImage); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import _ from 'lodash'; | ||
|
||
export function extractPositionValues(position) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of turning position to an enum? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think position is not a string but an array. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it can be an array of enums, I have code for it, I can create a PR later and if you can decide if you like the idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, let's save it for later.. this PR is getting too messy |
||
export function extractPositionValues(position: string[] | undefined) { | ||
const top = _.includes(position, 'top'); | ||
const left = _.includes(position, 'left'); | ||
const right = _.includes(position, 'right'); | ||
|
@@ -9,8 +9,8 @@ export function extractPositionValues(position) { | |
return {top, left, right, bottom}; | ||
} | ||
|
||
export function generateBorderRadiusStyle({position, borderRadius}) { | ||
const borderRadiusStyle = {}; | ||
export function generateBorderRadiusStyle({position, borderRadius}: {position: string[] | undefined, borderRadius: number | undefined}) { | ||
const borderRadiusStyle: {[key: string]: number | undefined} = {}; | ||
|
||
const {top, left, right, bottom} = extractPositionValues(position); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to add some (or all) of the ones below here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is that the other types will be part of Card
Card.Image, Card.Section..
But now I see it's not working so well...
I will check it