Skip to content

Dialog and Modal fix for web #2450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
28ebf0a
Dialog and Modal fix for web
adids1221 Feb 7, 2023
8af3a08
Button, Icon, picker - usePickerLabel cahnges according to web using
adids1221 Feb 20, 2023
7da78b7
Merge branch 'master' into fix/Picker_web_dialog
adids1221 Feb 20, 2023
542a303
Fixed the selected indicator color
adids1221 Feb 20, 2023
7ef136f
picker icon color change on selected item
adids1221 Feb 20, 2023
5a62d37
Fixed eslint error
adids1221 Feb 20, 2023
6a12cbc
Fixed svgimage component web file
adids1221 Feb 20, 2023
18db757
checkbox fix, icon changed default size for web
adids1221 Feb 26, 2023
a22f365
Merge branch 'master' into fix/Picker_web_dialog
adids1221 Feb 26, 2023
9cbb7e4
Removed unnecessary logs, files unnecessary changes
adids1221 Feb 26, 2023
43e545b
SvgImage web default size changed back to 16
adids1221 Feb 26, 2023
c45054a
Checkbox - cheanged Animated.Image to AnimatedIcon, Icon now wrraped …
adids1221 Feb 27, 2023
825e697
Merge branch 'master' into fix/Picker_web_dialog
adids1221 Feb 27, 2023
0e2f1f9
Fixed type issues in Chips index
adids1221 Feb 27, 2023
9b3927e
Checkbox removed forward ref from prop types
adids1221 Mar 8, 2023
b38fd1b
added ref to Image in Icon
adids1221 Mar 8, 2023
c66976e
Fixed tintColor in AnimatedIcon
adids1221 Mar 8, 2023
3ae70d3
Chip index - removed reformat from th ePR
adids1221 Mar 8, 2023
4a08e9c
checkbox props changed back, icon size logic reformat, usePickerLabel…
adids1221 Mar 9, 2023
7000ef2
Merge branch 'master' into fix/Picker_web_dialog
adids1221 Mar 13, 2023
53f50d9
fixed review notes
adids1221 Mar 13, 2023
215862d
Fixed size issue in icon
adids1221 Mar 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Colors, Typography, BorderRadiuses} from 'style';
import TouchableOpacity from '../touchableOpacity';
import Text from '../text';
import Image from '../image';
import Icon from '../icon';

import {ButtonSize, ButtonAnimationDirection, ButtonProps, ButtonState, Props, DEFAULT_PROPS} from './ButtonTypes';
export {ButtonSize, ButtonAnimationDirection, ButtonProps};
Expand Down Expand Up @@ -290,6 +291,11 @@ class Button extends PureComponent<Props, ButtonState> {
if (typeof iconSource === 'function') {
return iconSource(iconStyle);
} else {
if (Constants.isWeb) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we're not using Icon all of the time? both for web and mobile?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if we will user Icon and the user don't pass any tintColor the Icon will get the default color.
So if we change it to Icon it will break some users.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we need to migrate to Icon IMO, we can do it v8.
Can you add it to the v8 spreadsheet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done added to the spreadsheet.

return (
<Icon style={iconStyle} tintColor={Colors.$iconDefault} source={iconSource} testID={`${testID}.icon`}/>
);
}
return <Image source={iconSource} supportRTL={supportRTL} style={iconStyle} testID={`${testID}.icon`}/>;
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/components/checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {asBaseComponent} from '../../commons/new';
import TouchableOpacity from '../touchableOpacity';
import Text, {TextProps} from '../text';
import View from '../view';
import Icon from '../icon';

const DEFAULT_SIZE = 24;
const DEFAULT_COLOR = Colors.$backgroundPrimaryHeavy;
Expand Down Expand Up @@ -94,6 +95,8 @@ interface CheckboxState {
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/CheckboxScreen.tsx
* @gif: https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/Checkbox/Checkbox.gif?raw=true
*/

const AnimatedIcon = Animated.createAnimatedComponent(Icon);
class Checkbox extends Component<CheckboxProps, CheckboxState> {
static displayName = 'Checkbox';

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

renderCheckbox() {
const {selectedIcon, label, testID, style, containerStyle, ...others} = this.props;

return (
//@ts-ignore
<TouchableOpacity
Expand All @@ -222,14 +224,11 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
{backgroundColor: this.getBackgroundColor()}
]}
>
<Animated.Image
style={[
this.styles.selectedIcon,
{transform: this.animationStyle.transform},
{tintColor: this.getTintColor()}
]}
<AnimatedIcon
style={[this.styles.selectedIcon, {transform: this.animationStyle.transform}]}
source={selectedIcon || Assets.icons.checkSmall}
testID={`${testID}.selected`}
tintColor={this.getTintColor()}
/>
</Animated.View>
}
Expand Down
1 change: 1 addition & 0 deletions src/components/chip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ const Chip = ({

return (
<Icon
//@ts-expect-error
source={isLeftIcon ? iconSource : rightIconSource}
testID={`${testID}.icon`}
tintColor={Colors.$iconDefault}
Expand Down
9 changes: 6 additions & 3 deletions src/components/dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export interface DialogProps extends AlignmentModifiers, RNPartialProps {
* The props that will be passed to the pannable header
*/
pannableHeaderProps?: any;
/**
* Additional props for the modal.
/**
* Additional props for the modal.
*/
modalProps?: ModalProps;
/**
Expand Down Expand Up @@ -213,7 +213,10 @@ class Dialog extends Component<DialogProps, DialogState> {
containerStyle={this.styles.flexType}
style={this.styles.flexType}
>
<Container directions={[panDirection]} style={[this.styles.overflow, this.styles.flexType, containerStyle]}>
<Container
directions={[panDirection]}
style={[this.styles.overflow, !Constants.isWeb && this.styles.flexType, containerStyle]}
>
{this.renderPannableHeader([panDirection])}
{children}
</Container>
Expand Down
35 changes: 27 additions & 8 deletions src/components/icon/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import isUndefined from 'lodash/isUndefined';
import React, {useMemo} from 'react';
import React, {useMemo, forwardRef} from 'react';
import {Image, ImageProps, StyleSheet} from 'react-native';
import {asBaseComponent, BaseComponentInjectedProps, MarginModifiers, Constants} from '../../commons/new';
import {getAsset, isSvg} from '../../utils/imageUtils';
import {getAsset, isSvg, isBase64ImageContent} from '../../utils/imageUtils';
import SvgImage from '../svgImage';

export type IconProps = ImageProps &
Expand Down Expand Up @@ -37,8 +37,20 @@ export type IconProps = ImageProps &

type Props = IconProps & BaseComponentInjectedProps;

const Icon = (props: Props) => {
const {size, tintColor, style, supportRTL, source, assetGroup, assetName, modifiers, ...others} = props;
const defaultWebIconSize = 16;

const Icon = forwardRef((props: Props, ref: any) => {
const {
size = Constants.isWeb ? defaultWebIconSize : undefined,
tintColor,
style,
supportRTL,
source,
assetGroup,
assetName,
modifiers,
...others
} = props;
const {margins} = modifiers;
const iconSize = size ? {width: size, height: size} : undefined;
const shouldFlipRTL = supportRTL && Constants.isRTL;
Expand All @@ -50,16 +62,23 @@ const Icon = (props: Props) => {
return source;
}, [source, assetGroup, assetName]);

return isSvg(source) ? (
<SvgImage data={source} {...props}/>
) : (
const renderImage = () => (
<Image
{...others}
ref={ref}
source={iconSource}
style={[style, margins, iconSize, shouldFlipRTL && styles.rtlFlipped, !!tintColor && {tintColor}]}
/>
);
};

const renderSvg = () => <SvgImage data={source} {...props}/>;

if (typeof source === 'string' && isBase64ImageContent(source) && Constants.isWeb) {
return renderImage();
}

return isSvg(source) ? renderSvg() : renderImage();
});

Icon.displayName = 'Icon';
Icon.defaultProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Modal extends Component<ModalProps> {
renderTouchableOverlay() {
const {testID, overlayBackgroundColor, onBackgroundPress, accessibilityLabel = 'Dismiss'} = this.props;
if (_.isFunction(onBackgroundPress) || !!overlayBackgroundColor) {
const isScreenReaderEnabled = Constants.accessibility.isScreenReaderEnabled;
const isScreenReaderEnabled = !Constants.isWeb && Constants.accessibility.isScreenReaderEnabled;
const accessibilityProps = isScreenReaderEnabled
? {accessible: true, accessibilityLabel, accessibilityRole: 'button'}
: undefined;
Expand Down
34 changes: 21 additions & 13 deletions src/components/svgImage/index.web.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, {useState} from 'react';
import Image from '../image';
import {isSvg, isSvgUri, isBase64ImageContent} from '../../utils/imageUtils';

const EMPTY_STYLE = '{}';
const DEFAULT_SIZE = 16;
export interface SvgImageProps {
/**
* the asset tint
Expand All @@ -12,29 +14,36 @@ export interface SvgImageProps {
}

function SvgImage(props: SvgImageProps) {
const {
data,
style,
...other
} = props;
const {data, style, tintColor, ...others} = props;

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


const [svgStyleCss, setSvgStyleCss] = useState<string>(EMPTY_STYLE);
const [postCssStyleCalled, setPostCssStyleCalled] = useState(false);

const createStyleSvgCss = async (PostCssPackage: {postcss: any, cssjs:any}) => {
const createStyleSvgCss = async (PostCssPackage: {postcss: any; cssjs: any}) => {
setPostCssStyleCalled(true);
const {postcss, cssjs} = PostCssPackage;
postcss().process(styleObj, {parser: cssjs})
postcss()
.process(styleObj, {parser: cssjs})
.then((style: {css: any}) => setSvgStyleCss(`{${style.css}}`));
};

if (isSvgUri(data)) {
return <img {...other} src={data.uri} style={styleObj}/>;
return <img {...others} src={data.uri} style={styleObj}/>;
} else if (isBase64ImageContent(data)) {
return <img {...other} src={data} style={styleObj}/>;
if (tintColor) {
return (
<Image
source={{uri: data}}
width={DEFAULT_SIZE}
height={DEFAULT_SIZE}
style={[style, {tintColor}]}
{...others}
/>
);
}
return <img {...others} src={data} style={styleObj}/>;
} else if (data) {
const PostCssPackage = require('../../optionalDependencies').PostCssPackage;
if (PostCssPackage) {
Expand All @@ -43,16 +52,15 @@ function SvgImage(props: SvgImageProps) {
return null;
}
const svgStyleTag = `<style> svg ${svgStyleCss} </style>`;

return (
<div
{...other}
{...others}
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{__html: svgStyleTag + data}}
/>
);
}

}
return null;
}
Expand Down