Skip to content

Commit 3d0cecb

Browse files
authored
Overlay component borderRadius fix (#3058)
* fixed borderRadius in Overlay component, added exmaple in the Image screen * fixed review notes * revert isVertical const
1 parent f890f88 commit 3d0cecb

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

demo/src/screens/componentScreens/ImageScreen.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class ImageScreen extends Component<{}, State> {
7070
showErrorImage: false,
7171
showSvg: false,
7272
svgType: SvgType.File,
73-
sizeType: SizeType.None
73+
sizeType: SizeType.None,
74+
borderRadius: 0
7475
};
7576

7677
getSvgSource() {
@@ -113,7 +114,7 @@ class ImageScreen extends Component<{}, State> {
113114
}
114115

115116
renderImage() {
116-
const {cover, overlayType, overlayIntensity, margin, showErrorImage} = this.state;
117+
const {cover, overlayType, overlayIntensity, margin, showErrorImage, borderRadius} = this.state;
117118
return (
118119
<Image
119120
key={`${overlayType}-${overlayIntensity}`}
@@ -127,6 +128,7 @@ class ImageScreen extends Component<{}, State> {
127128
height={!cover ? DEFAULT_SIZE : undefined}
128129
customOverlayContent={this.renderOverlayContent()}
129130
{...{[`margin-${margin}`]: true}}
131+
borderRadius={borderRadius}
130132
/>
131133
);
132134
}
@@ -157,6 +159,7 @@ class ImageScreen extends Component<{}, State> {
157159
{renderRadioGroup.call(this, 'Overlay Intensity', 'overlayIntensity', Image.overlayIntensityType)}
158160
</View>
159161
{renderSliderOption.call(this, 'Margin(margin-XX)', 'margin', {step: 4, min: 0, max: 40})}
162+
{renderSliderOption.call(this, 'Border Radius', 'borderRadius', {step: 5, min: 0, max: 100})}
160163
</>
161164
);
162165
}

src/components/overlay/index.tsx

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export enum OverlayIntensityType {
2121
HIGH = 'high'
2222
}
2323

24-
export type OverlayTypeType = typeof OVERLY_TYPES[keyof typeof OVERLY_TYPES];
24+
export type OverlayTypeType = (typeof OVERLY_TYPES)[keyof typeof OVERLY_TYPES];
2525

2626
export type OverlayTypes = Pick<ImageProps, 'borderRadius'> & {
2727
/**
@@ -88,8 +88,7 @@ class Overlay extends PureComponent<OverlayTypes> {
8888
};
8989

9090
renderImage = (style: any, source: ImageSourcePropType) => {
91-
const {borderRadius} = this.props;
92-
return <Image style={[styles.container, style]} resizeMode={'stretch'} source={source} borderRadius={borderRadius}/>;
91+
return <Image style={[styles.container, style]} resizeMode={'stretch'} source={source}/>;
9392
};
9493

9594
getImageSource = (type?: OverlayTypeType, intensity?: OverlayTypes['intensity']) => {
@@ -105,24 +104,24 @@ class Overlay extends PureComponent<OverlayTypes> {
105104
};
106105

107106
render() {
108-
const {type, intensity, customContent} = this.props;
107+
const {type, intensity, customContent, borderRadius} = this.props;
109108
const imageSource = this.getImageSource(type, intensity);
110109

111-
if (type === OVERLY_TYPES.VERTICAL) {
112-
return (
113-
<>
114-
{this.renderImage([this.getStyleByType(OVERLY_TYPES.TOP), styles.vertical], imageSource)}
115-
{this.renderImage([this.getStyleByType(OVERLY_TYPES.BOTTOM), styles.vertical], imageSource)}
116-
{customContent && this.renderCustomContent()}
117-
</>
118-
);
119-
}
120-
121110
return (
122-
<>
123-
{type && this.renderImage(this.getStyleByType(), imageSource)}
124-
{customContent && this.renderCustomContent()}
125-
</>
111+
<View flex style={{overflow: 'hidden', borderRadius}}>
112+
{type === OVERLY_TYPES.VERTICAL ? (
113+
<>
114+
{this.renderImage([this.getStyleByType(OVERLY_TYPES.TOP), styles.vertical], imageSource)}
115+
{this.renderImage([this.getStyleByType(OVERLY_TYPES.BOTTOM), styles.vertical], imageSource)}
116+
{customContent && this.renderCustomContent()}
117+
</>
118+
) : (
119+
<>
120+
{type && this.renderImage(this.getStyleByType(), imageSource)}
121+
{customContent && this.renderCustomContent()}
122+
</>
123+
)}
124+
</View>
126125
);
127126
}
128127
}
@@ -134,14 +133,12 @@ const styles = StyleSheet.create({
134133
},
135134
top: {
136135
bottom: undefined,
137-
top: 0,
138136
height: '75%'
139137
},
140138
bottom: {
141-
bottom: 0,
142139
top: undefined,
143-
height: '75%',
144-
transform: [{scaleY: -1}]
140+
transform: [{scaleY: -1}],
141+
height: '75%'
145142
},
146143
vertical: {
147144
height: '40%'

0 commit comments

Comments
 (0)