Skip to content

Commit

Permalink
fix: make ListIcon color optional (#1379)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaulz authored and Trancever committed Oct 11, 2019
1 parent 189ae02 commit 2a392b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/components/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,28 @@ import {
} from 'react-native';
import { Consumer as SettingsConsumer } from '../core/settings';
import { accessibilityProps } from './MaterialCommunityIcon';
import { withTheme } from '../core/theming';
import { Theme } from '../types';

type IconSourceBase = string | ImageSourcePropType;

export type IconSource =
| IconSourceBase
| Readonly<{ source: IconSourceBase; direction: 'rtl' | 'ltr' | 'auto' }>
| ((props: IconProps) => React.ReactNode);
| ((props: IconProps & { color: string }) => React.ReactNode);

type IconProps = {
color: string;
size: number;
allowFontScaling?: boolean;
};

type Props = IconProps & {
color?: string;
source: any;
/**
* @optional
*/
theme: Theme;
};

const isImageSource = (source: any) =>
Expand Down Expand Up @@ -58,7 +64,7 @@ export const isValidIcon = (source: any) =>
export const isEqualIcon = (a: any, b: any) =>
a === b || getIconId(a) === getIconId(b);

const Icon = ({ source, color, size, ...rest }: Props) => {
const Icon = ({ source, color, size, theme, ...rest }: Props) => {
const direction =
// @ts-ignore
typeof source === 'object' && source.direction && source.source
Expand All @@ -73,6 +79,7 @@ const Icon = ({ source, color, size, ...rest }: Props) => {
typeof source === 'object' && source.direction && source.source
? source.source
: source;
const iconColor = color || theme.colors.text;

if (isImageSource(s)) {
return (
Expand Down Expand Up @@ -100,18 +107,18 @@ const Icon = ({ source, color, size, ...rest }: Props) => {
{({ icon }) => {
return icon({
name: s,
color,
color: iconColor,
size,
direction,
});
}}
</SettingsConsumer>
);
} else if (typeof s === 'function') {
return s({ color, size, direction });
return s({ color: iconColor, size, direction });
}

return null;
};

export default Icon;
export default withTheme(Icon);
2 changes: 1 addition & 1 deletion src/components/List/ListIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Props = {
/**
* Color for the icon.
*/
color: string;
color?: string;
style?: StyleProp<ViewStyle>;
};

Expand Down

0 comments on commit 2a392b9

Please sign in to comment.