Skip to content

Commit 92af834

Browse files
authored
Use Icon component for icons (#1778)
1 parent cb09ec1 commit 92af834

File tree

17 files changed

+113
-54
lines changed

17 files changed

+113
-54
lines changed

demo/src/screens/MainScreen.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
View,
1212
Text,
1313
TouchableOpacity,
14-
Image,
14+
Icon,
1515
Button,
1616
TabController,
1717
Incubator
@@ -180,7 +180,7 @@ class MainScreen extends Component {
180180
filterText ? (
181181
<Button link iconSource={Assets.icons.demo.close} grey10 onPress={this.clearSearch}/>
182182
) : (
183-
<Image source={Assets.icons.demo.search}/>
183+
<Icon source={Assets.icons.demo.search}/>
184184
)
185185
}
186186
/>
@@ -210,7 +210,7 @@ class MainScreen extends Component {
210210
<Text style={[item.deprecate && styles.entryTextDeprecated]} grey10 text50>
211211
{item.title}
212212
</Text>
213-
<Image source={chevronIcon} style={{tintColor: Colors.grey10}} supportRTL/>
213+
<Icon source={chevronIcon} style={{tintColor: Colors.grey10}} supportRTL/>
214214
</TouchableOpacity>
215215
);
216216
} else {

demo/src/screens/componentScreens/ImageScreen.tsx

Lines changed: 3 additions & 3 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, OverlayTypes} from 'react-native-ui-lib';
3+
import {View, Text, Icon, Image, Colors, Assets, OverlayTypes} from 'react-native-ui-lib';
44
import {renderBooleanOption, renderRadioGroup, renderSliderOption} from '../ExampleScreenPresenter';
55

66
const IMAGE_URL =
@@ -94,7 +94,7 @@ class ImageScreen extends Component<{}, State> {
9494
return (
9595
<View padding-20 flex bottom={overlayType === Image.overlayTypes.BOTTOM}>
9696
<View row centerV>
97-
<Image
97+
<Icon
9898
style={{margin: 5, marginRight: 10}}
9999
source={Assets.icons.demo.camera}
100100
tintColor={overlayType !== 'none' ? Colors.white : undefined}
@@ -106,7 +106,7 @@ class ImageScreen extends Component<{}, State> {
106106
</View>
107107
);
108108
} else {
109-
return <Image style={{margin: 5}} source={Assets.icons.demo.camera}/>;
109+
return <Icon style={{margin: 5}} source={Assets.icons.demo.camera}/>;
110110
}
111111
}
112112
}

demo/src/screens/componentScreens/PickerScreen.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import _ from 'lodash';
22
import React, {Component} from 'react';
3-
import {ScrollView, Image} from 'react-native';
4-
import {View, Colors, Dialog, Text, Picker, Avatar, Assets, PanningProvider, Typography} from 'react-native-ui-lib'; //eslint-disable-line
3+
import {ScrollView} from 'react-native';
4+
import {View, Colors, Icon, Dialog, Text, Picker, Avatar, Assets, PanningProvider, Typography} from 'react-native-ui-lib'; //eslint-disable-line
55
import contactsData from '../../data/conversations';
66
import tagIcon from '../../assets/icons/tags.png';
77
import dropdown from '../../assets/icons/chevronDown.png';
@@ -172,7 +172,7 @@ export default class PickerScreen extends Component {
172172
renderPicker={({label}) => {
173173
return (
174174
<View row>
175-
<Image style={{marginRight: 1, height: 16, resizeMode: 'contain'}} source={tagIcon}/>
175+
<Icon style={{marginRight: 1, height: 16, resizeMode: 'contain'}} source={tagIcon}/>
176176
<Text grey10 text80>
177177
{label} Posts
178178
</Text>
@@ -225,7 +225,7 @@ export default class PickerScreen extends Component {
225225
{item.name}
226226
</Text>
227227
</View>
228-
{props.isSelected && <Image source={Assets.icons.check}/>}
228+
{props.isSelected && <Icon source={Assets.icons.check}/>}
229229
</View>
230230
)}
231231
getItemLabel={item => item.name}

demo/src/screens/componentScreens/SliderScreen.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {Component} from 'react';
22
import {StyleSheet, ScrollView} from 'react-native';
3-
import {Colors, View, Text, Image, Slider, GradientSlider, ColorSliderGroup, Constants} from 'react-native-ui-lib';
3+
import {Colors, View, Text, Icon, Slider, GradientSlider, ColorSliderGroup, Constants} from 'react-native-ui-lib';
44

55
const INITIAL_VALUE = 0;
66
const COLOR = Colors.blue30;
@@ -49,7 +49,7 @@ export default class SliderScreen extends Component<SliderScreenProps, SliderScr
4949
</Text>
5050

5151
<View row centerV style={Constants.isRTL && styles.ltr}>
52-
<Image assetName={'megaphone'} style={styles.image}/>
52+
<Icon assetName={'search'} style={styles.image}/>
5353
<Slider
5454
onValueChange={this.onSliderValueChange}
5555
value={INITIAL_VALUE}

demo/src/screens/componentScreens/ToastsScreen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import _ from 'lodash';
22
import React, {Component} from 'react';
33
import {StyleSheet} from 'react-native';
4-
import {Assets, Colors, View, Button, Text, Image, TouchableOpacity, Toast} from 'react-native-ui-lib';
4+
import {Assets, Colors, View, Button, Text, Icon, TouchableOpacity, Toast} from 'react-native-ui-lib';
55

66

77
const colors = [Colors.green30, Colors.red30, Colors.violet30];
@@ -34,7 +34,7 @@ export default class ToastsScreen extends Component {
3434
return (
3535
<TouchableOpacity key={color} onPress={() => this.setState({selectedColor: color})}>
3636
<View center style={[styles.color, {backgroundColor}, isSelected && styles.selected]}>
37-
{color === 'none' && <Image source={plusIcon} tintColor={Colors.black}/>}
37+
{color === 'none' && <Icon source={plusIcon} tintColor={Colors.black}/>}
3838
</View>
3939
</TouchableOpacity>
4040
);

demo/src/screens/incubatorScreens/PanViewScreen.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
Constants,
1212
Modal,
1313
BorderRadiuses,
14-
Image,
14+
Icon,
1515
TouchableOpacity
1616
} from 'react-native-ui-lib';
1717
const {PanView} = Incubator;
@@ -157,7 +157,7 @@ class PanViewScreen extends Component {
157157
<Text text50 marginB-s2>
158158
Scrollable
159159
</Text>
160-
<Image source={Assets.icons.demo.chevronDown}/>
160+
<Icon source={Assets.icons.demo.chevronDown}/>
161161
</View>
162162
</ScrollView>
163163
{showToast && this.renderToast()}

demo/src/screens/realExamples/ProductPage/index.tsx

Lines changed: 2 additions & 2 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 {Assets, View, Text, Colors, Image, Button, Carousel, Picker} from 'react-native-ui-lib';
3+
import {Assets, View, Text, Icon, Colors, Image, Button, Carousel, Picker} from 'react-native-ui-lib';
44
import _ from 'lodash';
55

66
const colorOptions: {[key: string]: {name: string; color: string}} = {
@@ -40,7 +40,7 @@ class Product extends Component {
4040
return (
4141
<ScrollView>
4242
<View>
43-
<Image
43+
<Icon
4444
style={{position: 'absolute', top: 10, right: 10, zIndex: 100, tintColor: Colors.white}}
4545
source={Assets.icons.demo.share}
4646
/>

expoDemo/MainScreen.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {useCallback} from 'react';
22
import {SectionList, StyleSheet} from 'react-native';
3-
import {Colors, View, Text, TouchableOpacity, Spacings, Image, Assets, Incubator} from 'react-native-ui-lib';
3+
import {Colors, View, Text, TouchableOpacity, Spacings, Icon, Assets, Incubator} from 'react-native-ui-lib';
44
import {menuStructure} from 'unicorn-demo-app';
55
import _ from 'lodash';
66
import fuzzysearch from 'fuzzysearch';
@@ -83,7 +83,7 @@ export default function MainScreen({navigation}) {
8383
preset={null}
8484
text70
8585
fieldStyle={styles.fieldStyle}
86-
leadingAccessory={<Image source={Assets.icons.search} marginH-s2/>}
86+
leadingAccessory={<Icon source={Assets.icons.search} marginH-s2/>}
8787
/>
8888
}
8989
sections={sections}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React from 'react';
22
import { StyleProp, ViewStyle, ViewProps, ImageStyle, TextStyle, ImageSourcePropType } from 'react-native';
33
import { AvatarProps } from '../avatar';
44
import { BadgeProps } from '../badge';
5-
import { ImageProps } from '../image';
65
import { TouchableOpacityProps } from '../touchableOpacity';
6+
import { IconProps } from '../icon';
77
export declare type ChipProps = ViewProps & TouchableOpacityProps & {
88
/**
99
* Chip's size. Number or a width and height object.
@@ -63,7 +63,7 @@ export declare type ChipProps = ViewProps & TouchableOpacityProps & {
6363
/**
6464
* Additional icon props
6565
*/
66-
iconProps?: Omit<ImageProps, 'source'>;
66+
iconProps?: Omit<IconProps, 'source'>;
6767
/**
6868
* Icon style
6969
*/
@@ -164,7 +164,7 @@ declare const _default: React.ComponentClass<ViewProps & TouchableOpacityProps &
164164
/**
165165
* Additional icon props
166166
*/
167-
iconProps?: Omit<ImageProps, "source"> | undefined;
167+
iconProps?: Omit<IconProps, "source"> | undefined;
168168
/**
169169
* Icon style
170170
*/

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import React from 'react';
22
import { ImageProps } from 'react-native';
33
import { BaseComponentInjectedProps, MarginModifiers } from '../../commons/new';
44
export declare type IconProps = ImageProps & MarginModifiers & {
5+
/**
6+
* if provided icon source will be driven from asset name
7+
*/
8+
assetName?: string;
9+
/**
10+
* the asset group, default is "icons"
11+
*/
12+
assetGroup?: string;
513
/**
614
* the icon tint
715
*/
@@ -10,6 +18,10 @@ export declare type IconProps = ImageProps & MarginModifiers & {
1018
* the icon size
1119
*/
1220
size?: number;
21+
/**
22+
* whether the icon should flip horizontally on RTL
23+
*/
24+
supportRTL?: boolean;
1325
};
1426
/**
1527
* @description: Icon component
@@ -19,16 +31,13 @@ export declare type IconProps = ImageProps & MarginModifiers & {
1931
declare type Props = IconProps & BaseComponentInjectedProps;
2032
declare const _default: React.ComponentClass<ImageProps & Partial<Record<"margin" | "marginL" | "marginT" | "marginR" | "marginB" | "marginH" | "marginV", boolean>> & {
2133
/**
22-
* the icon tint
34+
* if provided icon source will be driven from asset name
2335
*/
24-
tintColor?: string | undefined;
36+
assetName?: string | undefined;
2537
/**
26-
* the icon size
38+
* the asset group, default is "icons"
2739
*/
28-
size?: number | undefined;
29-
} & {
30-
useCustomTheme?: boolean | undefined;
31-
}, any> & React.NamedExoticComponent<ImageProps & Partial<Record<"margin" | "marginL" | "marginT" | "marginR" | "marginB" | "marginH" | "marginV", boolean>> & {
40+
assetGroup?: string | undefined;
3241
/**
3342
* the icon tint
3443
*/
@@ -37,7 +46,17 @@ declare const _default: React.ComponentClass<ImageProps & Partial<Record<"margin
3746
* the icon size
3847
*/
3948
size?: number | undefined;
40-
} & BaseComponentInjectedProps> & {
41-
readonly type: (props: Props) => JSX.Element;
49+
/**
50+
* whether the icon should flip horizontally on RTL
51+
*/
52+
supportRTL?: boolean | undefined;
53+
} & {
54+
useCustomTheme?: boolean | undefined;
55+
}, any> & {
56+
(props: Props): JSX.Element;
57+
displayName: string;
58+
defaultProps: {
59+
assetGroup: string;
60+
};
4261
};
4362
export default _default;

src/components/card/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {Colors, BorderRadiuses} from '../../style';
66
import {Constants, asBaseComponent, forwardRef, BaseComponentInjectedProps, ForwardRefInjectedProps} from '../../commons/new';
77
import View, {ViewProps} from '../view';
88
import TouchableOpacity, {TouchableOpacityProps} from '../touchableOpacity';
9-
import Image from '../image';
9+
import Icon from '../icon';
1010
import CardImage from './CardImage';
1111
import CardSection, {CardSectionProps} from './CardSection';
1212
import {BlurViewPackage} from '../../optionalDependencies';
@@ -230,7 +230,7 @@ class Card extends PureComponent<PropTypes, State> {
230230
>
231231
{!selectionOptions.hideIndicator && (
232232
<View style={[this.styles.selectedIndicator, {backgroundColor: selectionColor}]}>
233-
<Image
233+
<Icon
234234
style={this.styles.selectedIcon}
235235
source={_.get(selectionOptions, 'icon', DEFAULT_SELECTION_PROPS.icon)}
236236
/>

src/components/chip/index.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import {asBaseComponent} from '../../commons/new';
66
import {BorderRadiuses, Spacings} from 'style';
77
import Avatar, {AvatarProps} from '../avatar';
88
import Badge, {BadgeProps} from '../badge';
9-
import Image, {ImageProps} from '../image';
109
import Text from '../text';
1110
import TouchableOpacity, {TouchableOpacityProps} from '../touchableOpacity';
1211
import View from '../view';
12+
import Icon, {IconProps} from '../icon';
1313

1414

1515
export type ChipProps = ViewProps & TouchableOpacityProps & {
@@ -76,7 +76,7 @@ export type ChipProps = ViewProps & TouchableOpacityProps & {
7676
/**
7777
* Additional icon props
7878
*/
79-
iconProps?: Omit<ImageProps, 'source'>;
79+
iconProps?: Omit<IconProps, 'source'>;
8080
/**
8181
* Icon style
8282
*/
@@ -169,8 +169,7 @@ const Chip = ({
169169
const isLeftIcon = iconPosition === 'left';
170170

171171
return (
172-
<Image
173-
// @ts-ignore
172+
<Icon
174173
source={isLeftIcon ? iconSource : rightIconSource}
175174
testID={`${testID}.icon`}
176175
{...iconProps}
@@ -201,8 +200,7 @@ const Chip = ({
201200
hitSlop={{top: 10, bottom: 10, left: 10, right: 10}}
202201
testID={`${testID}.dismiss`}
203202
>
204-
<Image
205-
// @ts-ignore
203+
<Icon
206204
source={dismissIcon}
207205
tintColor={dismissColor}
208206
style={[dismissIconStyle]}

src/components/chipsInput/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import _ from 'lodash';
22
import React, {Component} from 'react';
3-
import {NativeModules, StyleSheet, ViewStyle, Image, TextInput, NativeSyntheticEvent, TextInputKeyPressEventData, findNodeHandle, ScrollView, ScrollViewProps, TextInputProps as RNTextInputProps} from 'react-native';
3+
import {NativeModules, StyleSheet, ViewStyle, TextInput, NativeSyntheticEvent, TextInputKeyPressEventData, findNodeHandle, ScrollView, ScrollViewProps, TextInputProps as RNTextInputProps} from 'react-native';
44
import {Colors, BorderRadiuses, ThemeManager, Typography, Spacings} from '../../style';
55
import Assets from '../../assets';
66
import {LogService} from '../../services';
@@ -11,6 +11,7 @@ import View from '../view';
1111
import TouchableOpacity from '../touchableOpacity';
1212
import Text from '../text';
1313
import Chip, {ChipProps} from '../chip';
14+
import Icon from '../icon';
1415
import {getValidationBasedColor, getCounterTextColor, getCounterText, getChipDismissColor, isDisabled} from './Presenter';
1516
import {TextFieldProps} from '../../../typings/components/Inputs';
1617

@@ -309,7 +310,7 @@ class ChipsInput extends Component<OwnProps, State> {
309310
return (
310311
<View row centerV>
311312
{shouldMarkTag && (
312-
<Image
313+
<Icon
313314
style={[styles.removeIcon, tag.invalid && styles.basicTagStyle && styles.invalidTagRemoveIcon]}
314315
source={Assets.icons.x}
315316
/>)

src/components/icon/icon.api.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
"modifiers": ["margin"],
88
"example": "https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/IconScreen.tsx",
99
"props": [
10+
{"name": "assetName", "type": "string", "description": "if provided icon source will be driven from asset name"},
11+
{"name": "assetGroup", "type": "string", "description": "the asset group, default is icons"},
1012
{"name": "tintColor", "type": "string", "description": "The icon tint"},
11-
{"name": "size", "type": "number", "description": "The icon size"}
13+
{"name": "size", "type": "number", "description": "The icon size"},
14+
{"name": "supportRTL", "type": "boolean", "description": "whether the image should flip horizontally on RTL locals"}
1215
]
1316
}

0 commit comments

Comments
 (0)