Skip to content

Commit 7d7c8d3

Browse files
authored
Dialog and Modal fix for web (#2450)
* Dialog and Modal fix for web * Button, Icon, picker - usePickerLabel cahnges according to web using * Fixed the selected indicator color * picker icon color change on selected item * Fixed eslint error * Fixed svgimage component web file * checkbox fix, icon changed default size for web * Removed unnecessary logs, files unnecessary changes * SvgImage web default size changed back to 16 * Checkbox - cheanged Animated.Image to AnimatedIcon, Icon now wrraped by forwardRef * Fixed type issues in Chips index * Checkbox removed forward ref from prop types * added ref to Image in Icon * Fixed tintColor in AnimatedIcon * Chip index - removed reformat from th ePR * checkbox props changed back, icon size logic reformat, usePickerLabel changed the logic back * fixed review notes * Fixed size issue in icon
1 parent 1fab050 commit 7d7c8d3

File tree

7 files changed

+68
-32
lines changed

7 files changed

+68
-32
lines changed

src/components/button/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Colors, Typography, BorderRadiuses} from 'style';
66
import TouchableOpacity from '../touchableOpacity';
77
import Text from '../text';
88
import Image from '../image';
9+
import Icon from '../icon';
910

1011
import {ButtonSize, ButtonAnimationDirection, ButtonProps, ButtonState, Props, DEFAULT_PROPS} from './ButtonTypes';
1112
export {ButtonSize, ButtonAnimationDirection, ButtonProps};
@@ -290,6 +291,11 @@ class Button extends PureComponent<Props, ButtonState> {
290291
if (typeof iconSource === 'function') {
291292
return iconSource(iconStyle);
292293
} else {
294+
if (Constants.isWeb) {
295+
return (
296+
<Icon style={iconStyle} tintColor={Colors.$iconDefault} source={iconSource} testID={`${testID}.icon`}/>
297+
);
298+
}
293299
return <Image source={iconSource} supportRTL={supportRTL} style={iconStyle} testID={`${testID}.icon`}/>;
294300
}
295301
}

src/components/checkbox/index.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {asBaseComponent} from '../../commons/new';
1616
import TouchableOpacity from '../touchableOpacity';
1717
import Text, {TextProps} from '../text';
1818
import View from '../view';
19+
import Icon from '../icon';
1920

2021
const DEFAULT_SIZE = 24;
2122
const DEFAULT_COLOR = Colors.$backgroundPrimaryHeavy;
@@ -94,6 +95,8 @@ interface CheckboxState {
9495
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/CheckboxScreen.tsx
9596
* @gif: https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/Checkbox/Checkbox.gif?raw=true
9697
*/
98+
99+
const AnimatedIcon = Animated.createAnimatedComponent(Icon);
97100
class Checkbox extends Component<CheckboxProps, CheckboxState> {
98101
static displayName = 'Checkbox';
99102

@@ -203,7 +206,6 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
203206

204207
renderCheckbox() {
205208
const {selectedIcon, label, testID, style, containerStyle, ...others} = this.props;
206-
207209
return (
208210
//@ts-ignore
209211
<TouchableOpacity
@@ -222,14 +224,11 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
222224
{backgroundColor: this.getBackgroundColor()}
223225
]}
224226
>
225-
<Animated.Image
226-
style={[
227-
this.styles.selectedIcon,
228-
{transform: this.animationStyle.transform},
229-
{tintColor: this.getTintColor()}
230-
]}
227+
<AnimatedIcon
228+
style={[this.styles.selectedIcon, {transform: this.animationStyle.transform}]}
231229
source={selectedIcon || Assets.icons.checkSmall}
232230
testID={`${testID}.selected`}
231+
tintColor={this.getTintColor()}
233232
/>
234233
</Animated.View>
235234
}

src/components/chip/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ const Chip = ({
170170

171171
return (
172172
<Icon
173+
//@ts-expect-error
173174
source={isLeftIcon ? iconSource : rightIconSource}
174175
testID={`${testID}.icon`}
175176
tintColor={Colors.$iconDefault}

src/components/dialog/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export interface DialogProps extends AlignmentModifiers, RNPartialProps {
7171
* The props that will be passed to the pannable header
7272
*/
7373
pannableHeaderProps?: any;
74-
/**
75-
* Additional props for the modal.
74+
/**
75+
* Additional props for the modal.
7676
*/
7777
modalProps?: ModalProps;
7878
/**
@@ -213,7 +213,10 @@ class Dialog extends Component<DialogProps, DialogState> {
213213
containerStyle={this.styles.flexType}
214214
style={this.styles.flexType}
215215
>
216-
<Container directions={[panDirection]} style={[this.styles.overflow, this.styles.flexType, containerStyle]}>
216+
<Container
217+
directions={[panDirection]}
218+
style={[this.styles.overflow, !Constants.isWeb && this.styles.flexType, containerStyle]}
219+
>
217220
{this.renderPannableHeader([panDirection])}
218221
{children}
219222
</Container>

src/components/icon/index.tsx

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import isUndefined from 'lodash/isUndefined';
2-
import React, {useMemo} from 'react';
2+
import React, {useMemo, forwardRef} from 'react';
33
import {Image, ImageProps, StyleSheet} from 'react-native';
44
import {asBaseComponent, BaseComponentInjectedProps, MarginModifiers, Constants} from '../../commons/new';
5-
import {getAsset, isSvg} from '../../utils/imageUtils';
5+
import {getAsset, isSvg, isBase64ImageContent} from '../../utils/imageUtils';
66
import SvgImage from '../svgImage';
77

88
export type IconProps = ImageProps &
@@ -37,8 +37,20 @@ export type IconProps = ImageProps &
3737

3838
type Props = IconProps & BaseComponentInjectedProps;
3939

40-
const Icon = (props: Props) => {
41-
const {size, tintColor, style, supportRTL, source, assetGroup, assetName, modifiers, ...others} = props;
40+
const defaultWebIconSize = 16;
41+
42+
const Icon = forwardRef((props: Props, ref: any) => {
43+
const {
44+
size = Constants.isWeb ? defaultWebIconSize : undefined,
45+
tintColor,
46+
style,
47+
supportRTL,
48+
source,
49+
assetGroup,
50+
assetName,
51+
modifiers,
52+
...others
53+
} = props;
4254
const {margins} = modifiers;
4355
const iconSize = size ? {width: size, height: size} : undefined;
4456
const shouldFlipRTL = supportRTL && Constants.isRTL;
@@ -50,16 +62,23 @@ const Icon = (props: Props) => {
5062
return source;
5163
}, [source, assetGroup, assetName]);
5264

53-
return isSvg(source) ? (
54-
<SvgImage data={source} {...props}/>
55-
) : (
65+
const renderImage = () => (
5666
<Image
5767
{...others}
68+
ref={ref}
5869
source={iconSource}
5970
style={[style, margins, iconSize, shouldFlipRTL && styles.rtlFlipped, !!tintColor && {tintColor}]}
6071
/>
6172
);
62-
};
73+
74+
const renderSvg = () => <SvgImage data={source} {...props}/>;
75+
76+
if (typeof source === 'string' && isBase64ImageContent(source) && Constants.isWeb) {
77+
return renderImage();
78+
}
79+
80+
return isSvg(source) ? renderSvg() : renderImage();
81+
});
6382

6483
Icon.displayName = 'Icon';
6584
Icon.defaultProps = {

src/components/modal/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Modal extends Component<ModalProps> {
8080
renderTouchableOverlay() {
8181
const {testID, overlayBackgroundColor, onBackgroundPress, accessibilityLabel = 'Dismiss'} = this.props;
8282
if (_.isFunction(onBackgroundPress) || !!overlayBackgroundColor) {
83-
const isScreenReaderEnabled = Constants.accessibility.isScreenReaderEnabled;
83+
const isScreenReaderEnabled = !Constants.isWeb && Constants.accessibility.isScreenReaderEnabled;
8484
const accessibilityProps = isScreenReaderEnabled
8585
? {accessible: true, accessibilityLabel, accessibilityRole: 'button'}
8686
: undefined;

src/components/svgImage/index.web.tsx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React, {useState} from 'react';
2+
import Image from '../image';
23
import {isSvg, isSvgUri, isBase64ImageContent} from '../../utils/imageUtils';
34

45
const EMPTY_STYLE = '{}';
6+
const DEFAULT_SIZE = 16;
57
export interface SvgImageProps {
68
/**
79
* the asset tint
@@ -12,29 +14,36 @@ export interface SvgImageProps {
1214
}
1315

1416
function SvgImage(props: SvgImageProps) {
15-
const {
16-
data,
17-
style,
18-
...other
19-
} = props;
17+
const {data, style, tintColor, ...others} = props;
2018

2119
const styleObj = Object.assign({}, ...(style || []));
2220

23-
2421
const [svgStyleCss, setSvgStyleCss] = useState<string>(EMPTY_STYLE);
2522
const [postCssStyleCalled, setPostCssStyleCalled] = useState(false);
2623

27-
const createStyleSvgCss = async (PostCssPackage: {postcss: any, cssjs:any}) => {
24+
const createStyleSvgCss = async (PostCssPackage: {postcss: any; cssjs: any}) => {
2825
setPostCssStyleCalled(true);
2926
const {postcss, cssjs} = PostCssPackage;
30-
postcss().process(styleObj, {parser: cssjs})
27+
postcss()
28+
.process(styleObj, {parser: cssjs})
3129
.then((style: {css: any}) => setSvgStyleCss(`{${style.css}}`));
3230
};
3331

3432
if (isSvgUri(data)) {
35-
return <img {...other} src={data.uri} style={styleObj}/>;
33+
return <img {...others} src={data.uri} style={styleObj}/>;
3634
} else if (isBase64ImageContent(data)) {
37-
return <img {...other} src={data} style={styleObj}/>;
35+
if (tintColor) {
36+
return (
37+
<Image
38+
source={{uri: data}}
39+
width={DEFAULT_SIZE}
40+
height={DEFAULT_SIZE}
41+
style={[style, {tintColor}]}
42+
{...others}
43+
/>
44+
);
45+
}
46+
return <img {...others} src={data} style={styleObj}/>;
3847
} else if (data) {
3948
const PostCssPackage = require('../../optionalDependencies').PostCssPackage;
4049
if (PostCssPackage) {
@@ -43,16 +52,15 @@ function SvgImage(props: SvgImageProps) {
4352
return null;
4453
}
4554
const svgStyleTag = `<style> svg ${svgStyleCss} </style>`;
46-
55+
4756
return (
4857
<div
49-
{...other}
58+
{...others}
5059
// eslint-disable-next-line react/no-danger
5160
dangerouslySetInnerHTML={{__html: svgStyleTag + data}}
5261
/>
5362
);
5463
}
55-
5664
}
5765
return null;
5866
}

0 commit comments

Comments
 (0)