Skip to content

Commit e35cf04

Browse files
authored
Add margin modifiers support to Image component (#853)
1 parent fec2974 commit e35cf04

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

demo/src/screens/componentScreens/ImageScreen.tsx

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

55
import cameraIcon from '../../assets/icons/cameraSelected.png';
66

@@ -12,7 +12,8 @@ class ImageScreen extends Component {
1212
state = {
1313
cover: true,
1414
showOverlayContent: false,
15-
overlayType: 'none'
15+
overlayType: 'none',
16+
margin: 0
1617
};
1718

1819
renderOverlayContent() {
@@ -38,8 +39,9 @@ class ImageScreen extends Component {
3839
}
3940
}
4041
}
42+
4143
render() {
42-
const {cover, overlayType} = this.state;
44+
const {cover, overlayType, margin} = this.state;
4345

4446
return (
4547
<View flex>
@@ -50,6 +52,7 @@ class ImageScreen extends Component {
5052
overlayType={overlayType !== 'none' ? overlayType : undefined}
5153
style={!cover && {width: DEFAULT_SIZE, height: DEFAULT_SIZE}}
5254
customOverlayContent={this.renderOverlayContent()}
55+
{...{[`margin-${margin}`]: true}}
5356
/>
5457
</View>
5558
<View height={2} bg-grey60/>
@@ -59,6 +62,7 @@ class ImageScreen extends Component {
5962
{renderBooleanOption.call(this, 'Show as Cover Image', 'cover')}
6063
{renderBooleanOption.call(this, 'Show Overlay Content', 'showOverlayContent')}
6164
{renderRadioGroup.call(this, 'Overlay Type', 'overlayType', {none: 'none', ...Image.overlayTypes})}
65+
{renderSliderOption.call(this, 'Margin(margin-XX)', 'margin', {step: 4, min: 0, max: 40})}
6266
</View>
6367
<Text text40>Image Screen</Text>
6468
</View>

generatedTypes/components/image/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { PureComponent } from 'react';
22
import { ImageProps as RNImageProps, ImageSourcePropType } from 'react-native';
3-
import { ForwardRefInjectedProps } from '../../commons/new';
3+
import { ForwardRefInjectedProps, BaseComponentInjectedProps, MarginModifiers } from '../../commons/new';
44
import { OverlayTypeType } from '../overlay';
5-
export declare type ImageProps = RNImageProps & {
5+
export declare type ImageProps = RNImageProps & MarginModifiers & {
66
/**
77
* custom source transform handler for manipulating the image source (great for size control)
88
*/
@@ -45,7 +45,7 @@ export declare type ImageProps = RNImageProps & {
4545
*/
4646
customOverlayContent?: JSX.Element;
4747
};
48-
declare type Props = ImageProps & ForwardRefInjectedProps;
48+
declare type Props = ImageProps & ForwardRefInjectedProps & BaseComponentInjectedProps;
4949
/**
5050
* @description: Image wrapper with extra functionality like source transform and assets support
5151
* @extends: Image

src/components/image/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import React, {PureComponent} from 'react';
44
import hoistNonReactStatic from 'hoist-non-react-statics';
55
import {Image as RNImage, ImageProps as RNImageProps, StyleSheet, ImageBackground, ImageSourcePropType} from 'react-native';
66
import Constants from '../../helpers/Constants';
7-
import {asBaseComponent, ForwardRefInjectedProps} from '../../commons/new';
7+
import {asBaseComponent, ForwardRefInjectedProps, BaseComponentInjectedProps, MarginModifiers} from '../../commons/new';
88
// @ts-ignore
99
import Assets from '../../assets';
1010
import Overlay, {OverlayTypeType} from '../overlay';
1111

12-
export type ImageProps = RNImageProps & {
12+
export type ImageProps = RNImageProps & MarginModifiers & {
1313
/**
1414
* custom source transform handler for manipulating the image source (great for size control)
1515
*/
@@ -53,7 +53,7 @@ export type ImageProps = RNImageProps & {
5353
customOverlayContent?: JSX.Element;
5454
};
5555

56-
type Props = ImageProps & ForwardRefInjectedProps;
56+
type Props = ImageProps & ForwardRefInjectedProps & BaseComponentInjectedProps;
5757

5858
/**
5959
* @description: Image wrapper with extra functionality like source transform and assets support
@@ -122,10 +122,12 @@ class Image extends PureComponent<Props> {
122122
overlayType,
123123
overlayColor,
124124
customOverlayContent,
125+
modifiers,
125126
...others
126127
} = this.props;
127128
const shouldFlipRTL = supportRTL && Constants.isRTL;
128129
const ImageView = this.shouldUseImageBackground() ? ImageBackground : RNImage;
130+
const {margins} = modifiers;
129131

130132
return (
131133
// @ts-ignore
@@ -136,6 +138,7 @@ class Image extends PureComponent<Props> {
136138
cover && styles.coverImage,
137139
this.isGif() && styles.gifImage,
138140
aspectRatio && {aspectRatio},
141+
margins,
139142
style
140143
]}
141144
accessible={false}

0 commit comments

Comments
 (0)