Skip to content

Commit 41c00e6

Browse files
authored
Image - add OverlayIntensity (#1584)
* Image - add OverlayIntensity * Remove unused code * Modify opacity according to intensity and color * Fix typings
1 parent 0406a99 commit 41c00e6

20 files changed

+105
-22
lines changed

demo/src/screens/componentScreens/ImageScreen.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {Component} from 'react';
22
import {ScrollView} from 'react-native';
3-
import {View, Text, Image, Colors, Assets} from 'react-native-ui-lib';
3+
import {View, Text, Image, Colors, Assets, OverlayTypes} from 'react-native-ui-lib';
44
import {renderBooleanOption, renderRadioGroup, renderSliderOption} from '../ExampleScreenPresenter';
55

66
const IMAGE_URL =
@@ -38,11 +38,24 @@ enum SizeType {
3838
Percentage = '50%'
3939
}
4040

41-
class ImageScreen extends Component {
41+
interface State {
42+
cover: boolean;
43+
showOverlayContent: boolean;
44+
overlayType: 'none' | OverlayTypes['type'];
45+
overlayIntensity: OverlayTypes['intensity'];
46+
margin: number;
47+
showErrorImage: boolean;
48+
showSvg: boolean;
49+
isFile: boolean;
50+
sizeType: SizeType;
51+
}
52+
53+
class ImageScreen extends Component<{}, State> {
4254
state = {
4355
cover: true,
4456
showOverlayContent: false,
4557
overlayType: 'none',
58+
overlayIntensity: Image.overlayIntensityType.LOW,
4659
margin: 0,
4760
showErrorImage: false,
4861
showSvg: false,
@@ -75,13 +88,15 @@ class ImageScreen extends Component {
7588
}
7689

7790
renderImage() {
78-
const {cover, overlayType, margin, showErrorImage} = this.state;
91+
const {cover, overlayType, overlayIntensity, margin, showErrorImage} = this.state;
7992
return (
8093
<Image
94+
key={`${overlayType}-${overlayIntensity}`}
8195
source={{uri: showErrorImage ? BROKEN_URL : IMAGE_URL}}
8296
errorSource={Assets.images.demo.brokenImage}
8397
cover={cover}
8498
overlayType={overlayType !== 'none' ? overlayType : undefined}
99+
overlayIntensity={overlayIntensity}
85100
style={!cover && {width: DEFAULT_SIZE, height: DEFAULT_SIZE}}
86101
customOverlayContent={this.renderOverlayContent()}
87102
{...{[`margin-${margin}`]: true}}
@@ -109,7 +124,10 @@ class ImageScreen extends Component {
109124
{renderBooleanOption.call(this, 'Show as Cover Image', 'cover')}
110125
{renderBooleanOption.call(this, 'Show Overlay Content', 'showOverlayContent')}
111126
{renderBooleanOption.call(this, 'Show Error Image', 'showErrorImage')}
112-
{renderRadioGroup.call(this, 'Overlay Type', 'overlayType', {none: 'none', ...Image.overlayTypes})}
127+
<View row spread>
128+
{renderRadioGroup.call(this, 'Overlay Type', 'overlayType', {none: 'none', ...Image.overlayTypes})}
129+
{renderRadioGroup.call(this, 'Overlay Intensity', 'overlayIntensity', Image.overlayIntensityType)}
130+
</View>
113131
{renderSliderOption.call(this, 'Margin(margin-XX)', 'margin', {step: 4, min: 0, max: 40})}
114132
</>
115133
);

generatedTypes/src/components/image/index.d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { PureComponent } from 'react';
22
import { ImageProps as RNImageProps, ImageSourcePropType, NativeSyntheticEvent, ImageErrorEventData } from 'react-native';
33
import { ForwardRefInjectedProps, BaseComponentInjectedProps, MarginModifiers } from '../../commons/new';
4-
import { OverlayTypeType } from '../overlay';
4+
import { OverlayTypeType, OverlayIntensityType } from '../overlay';
55
export declare type ImageProps = RNImageProps & MarginModifiers & {
66
/**
77
* custom source transform handler for manipulating the image source (great for size control)
@@ -36,6 +36,10 @@ export declare type ImageProps = RNImageProps & MarginModifiers & {
3636
* https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/OverlaysScreen.tsx
3737
*/
3838
overlayType?: OverlayTypeType;
39+
/**
40+
* The intensity of the overlay ('LOW' | 'MEDIUM' | 'HIGH'), default is 'LOW'.
41+
*/
42+
overlayIntensity?: OverlayIntensityType;
3943
/**
4044
* Pass a custom color for the overlay
4145
*/
@@ -73,6 +77,7 @@ declare class Image extends PureComponent<Props, State> {
7377
BOTTOM: string;
7478
SOLID: string;
7579
};
80+
static overlayIntensityType: typeof OverlayIntensityType;
7681
sourceTransformer?: (props: any) => ImageSourcePropType;
7782
constructor(props: Props);
7883
static getDerivedStateFromProps(nextProps: Partial<Props>, prevState: State): {
@@ -123,6 +128,10 @@ declare const _default: React.ComponentClass<RNImageProps & Partial<Record<"marg
123128
* https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/OverlaysScreen.tsx
124129
*/
125130
overlayType?: string | undefined;
131+
/**
132+
* The intensity of the overlay ('LOW' | 'MEDIUM' | 'HIGH'), default is 'LOW'.
133+
*/
134+
overlayIntensity?: OverlayIntensityType | undefined;
126135
/**
127136
* Pass a custom color for the overlay
128137
*/

generatedTypes/src/components/overlay/index.d.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@ declare const OVERLY_TYPES: {
66
BOTTOM: string;
77
SOLID: string;
88
};
9+
export declare enum OverlayIntensityType {
10+
LOW = "low",
11+
MEDIUM = "medium",
12+
HIGH = "high"
13+
}
914
export declare type OverlayTypeType = typeof OVERLY_TYPES[keyof typeof OVERLY_TYPES];
1015
export declare type OverlayTypes = {
1116
/**
1217
* The type of overlay to set on top of the image
1318
*/
1419
type?: OverlayTypeType;
20+
/**
21+
* The intensity of the gradient, default is 'LOW'.
22+
*/
23+
intensity?: OverlayIntensityType;
1524
/**
1625
* The overlay color
1726
*/
@@ -34,9 +43,8 @@ declare class Overlay extends PureComponent<OverlayTypes> {
3443
BOTTOM: string;
3544
SOLID: string;
3645
};
46+
static intensityTypes: typeof OverlayIntensityType;
3747
getStyleByType(type?: string | undefined): ("" | {
38-
backgroundColor: string;
39-
} | undefined)[] | ("" | {
4048
bottom: undefined;
4149
top: number;
4250
height: string;
@@ -51,9 +59,12 @@ declare class Overlay extends PureComponent<OverlayTypes> {
5159
}[];
5260
} | {
5361
tintColor: string;
54-
} | undefined)[] | undefined;
62+
} | undefined)[] | {
63+
backgroundColor: string;
64+
} | undefined;
5565
renderCustomContent: () => JSX.Element;
5666
renderImage: (style: any, source: ImageSourcePropType) => JSX.Element;
67+
getImageSource: (type?: string | undefined, intensity?: OverlayIntensityType | undefined) => any;
5768
render(): JSX.Element;
5869
}
5970
export default Overlay;

src/components/image/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Constants from '../../helpers/Constants';
1414
import {asBaseComponent, ForwardRefInjectedProps, BaseComponentInjectedProps, MarginModifiers} from '../../commons/new';
1515
// @ts-ignore
1616
import Assets from '../../assets';
17-
import Overlay, {OverlayTypeType} from '../overlay';
17+
import Overlay, {OverlayTypeType, OverlayIntensityType} from '../overlay';
1818
import SvgImage from './SvgImage';
1919

2020

@@ -52,6 +52,10 @@ export type ImageProps = RNImageProps & MarginModifiers & {
5252
* https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/OverlaysScreen.tsx
5353
*/
5454
overlayType?: OverlayTypeType;
55+
/**
56+
* The intensity of the overlay ('LOW' | 'MEDIUM' | 'HIGH'), default is 'LOW'.
57+
*/
58+
overlayIntensity?: OverlayIntensityType;
5559
/**
5660
* Pass a custom color for the overlay
5761
*/
@@ -89,6 +93,7 @@ class Image extends PureComponent<Props, State> {
8993
};
9094

9195
public static overlayTypes = Overlay.overlayTypes;
96+
public static overlayIntensityType = Overlay.intensityTypes;
9297

9398
sourceTransformer?: (props: any) => ImageSourcePropType;
9499

@@ -171,6 +176,7 @@ class Image extends PureComponent<Props, State> {
171176
cover,
172177
aspectRatio,
173178
overlayType,
179+
overlayIntensity,
174180
overlayColor,
175181
customOverlayContent,
176182
modifiers,
@@ -199,7 +205,12 @@ class Image extends PureComponent<Props, State> {
199205
source={source}
200206
>
201207
{(overlayType || customOverlayContent) && (
202-
<Overlay type={overlayType} color={overlayColor} customContent={customOverlayContent}/>
208+
<Overlay
209+
type={overlayType}
210+
intensity={overlayIntensity}
211+
color={overlayColor}
212+
customContent={customOverlayContent}
213+
/>
203214
)}
204215
</ImageView>
205216
);
561 Bytes
Loading
1.22 KB
Loading
1.66 KB
Loading
3.19 KB
Loading
5.57 KB
Loading

0 commit comments

Comments
 (0)