Skip to content

Commit

Permalink
fix typescript and add ci check (react-native-elements#2909)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeremy Hamilton <jeremy.hamilton@tekfive.com>
  • Loading branch information
flyingcircle and Jeremy Hamilton authored Mar 24, 2021
1 parent 661a3c8 commit c6c8aa7
Show file tree
Hide file tree
Showing 44 changed files with 112 additions and 89 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ install:
- yarn
script:
- yarn lint
- yarn build
- yarn test:ci && codecov --disable=gcov
after_success:
- |
Expand Down
3 changes: 2 additions & 1 deletion src/avatar/Accessory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import {
import { withTheme } from '../config';
import Image, { ImageProps } from '../image/Image';
import Icon, { IconProps } from '../icons/Icon';
import { RneFunctionComponent } from '../helpers';

export type AccessoryProps = Partial<IconProps> &
Partial<ImageProps> & {
underlayColor?: ColorValue;
style?: StyleProp<ViewStyle>;
};

const Accessory: React.FunctionComponent<AccessoryProps> = ({
const Accessory: RneFunctionComponent<AccessoryProps> = ({
size = 10,
style,
underlayColor = '#000',
Expand Down
4 changes: 2 additions & 2 deletions src/avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from 'react-native';
import isEqual from 'lodash.isequal';
import { withTheme } from '../config';
import { renderNode } from '../helpers';
import { renderNode, RneFunctionComponent } from '../helpers';
import Icon, { IconObject } from '../icons/Icon';
import Image, { ImageProps } from '../image/Image';
import Accessory from './Accessory';
Expand Down Expand Up @@ -51,7 +51,7 @@ export type AvatarProps = {
ImageComponent?: React.ComponentClass;
};

interface Avatar extends React.FunctionComponent<AvatarProps> {}
interface Avatar extends RneFunctionComponent<AvatarProps> {}

const AvatarComponent: Avatar = ({
onPress,
Expand Down
7 changes: 2 additions & 5 deletions src/badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
ViewStyle,
} from 'react-native';
import { withTheme } from '../config';
import { ThemeProps } from '../config';
import { renderNode } from '../helpers';
import { renderNode, RneFunctionComponent } from '../helpers';

export type BadgeProps = {
containerStyle?: StyleProp<ViewStyle>;
Expand All @@ -23,9 +22,7 @@ export type BadgeProps = {
status?: 'primary' | 'success' | 'warning' | 'error';
};

const Badge: React.FunctionComponent<BadgeProps & ThemeProps<BadgeProps>> = (
props
) => {
const Badge: RneFunctionComponent<BadgeProps> = (props) => {
const {
containerStyle,
textStyle,
Expand Down
3 changes: 2 additions & 1 deletion src/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { withTheme } from '../config';
import { RneFunctionComponent } from '../helpers';

export type BottomSheetProps = {
containerStyle?: StyleProp<ViewStyle>;
Expand All @@ -22,7 +23,7 @@ const defaultProps = {
isVisible: false,
};

const BottomSheet: React.FunctionComponent<BottomSheetProps> = ({
const BottomSheet: RneFunctionComponent<BottomSheetProps> = ({
containerStyle,
isVisible,
modalProps,
Expand Down
7 changes: 2 additions & 5 deletions src/buttons/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import {
} from 'react-native';
import Color from 'color';
import { withTheme } from '../config';
import { renderNode, color } from '../helpers';
import { renderNode, color, RneFunctionComponent } from '../helpers';
import Icon, { IconNode } from '../icons/Icon';
import { Theme } from '../config/theme';
import { TextProps } from '../text/Text';
import { ThemeProps } from '../config';

const defaultLoadingProps = (
type: 'solid' | 'clear' | 'outline',
Expand Down Expand Up @@ -53,9 +52,7 @@ export type ButtonProps = TouchableOpacityProps &
raised?: boolean;
};

const Button: React.FunctionComponent<ButtonProps & ThemeProps<ButtonProps>> = (
props: ButtonProps & ThemeProps<ButtonProps>
) => {
const Button: RneFunctionComponent<ButtonProps> = (props) => {
useEffect(() => {
if (props.linearGradientProps && !props.ViewComponent) {
console.error(
Expand Down
7 changes: 2 additions & 5 deletions src/buttons/ButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {
TextStyle,
} from 'react-native';
import { withTheme } from '../config';
import { ThemeProps } from '../config';
import { normalizeText, color } from '../helpers';
import { normalizeText, color, RneFunctionComponent } from '../helpers';
import Text from '../text/Text';

export type ButtonGroupProps = {
Expand Down Expand Up @@ -45,9 +44,7 @@ export type ButtonGroupProps = {
vertical?: boolean;
};

const ButtonGroup: React.FunctionComponent<
ButtonGroupProps & ThemeProps<ButtonGroupProps>
> = (props) => {
const ButtonGroup: RneFunctionComponent<ButtonGroupProps> = (props) => {
const { theme, ...rest } = props;
const {
Component = Platform.select<typeof React.Component>({
Expand Down
3 changes: 2 additions & 1 deletion src/buttons/FAB.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { StyleSheet, Animated } from 'react-native';
import Button, { ButtonProps } from './Button';
import { withTheme } from '../config';
import { RneFunctionComponent } from '../helpers';

export type FABProps = ButtonProps & {
color?: string;
Expand All @@ -11,7 +12,7 @@ export type FABProps = ButtonProps & {
upperCase?: boolean;
};

const FAB: React.FunctionComponent<FABProps> = ({
const FAB: RneFunctionComponent<FABProps> = ({
color,
size = 'large',
visible = true,
Expand Down
5 changes: 2 additions & 3 deletions src/card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import CardDivider from './CardDivider';
import CardImage from './CardImage';
import CardFeaturedTitle from './CardFeaturedTitle';
import CardFeaturedSubtitle from './CardFeaturedSubtitle';
import { ThemeProps } from '../config';
import { RneFunctionComponent } from '../helpers';

export type CardProps = {
containerStyle?: StyleProp<ViewStyle>;
wrapperStyle?: StyleProp<ViewStyle>;
};

interface Card
extends React.FunctionComponent<CardProps & ThemeProps<CardProps>> {}
interface Card extends RneFunctionComponent<CardProps> {}

const Card: Card = (props) => {
const {
Expand Down
3 changes: 2 additions & 1 deletion src/card/CardDivider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React from 'react';
import { StyleSheet } from 'react-native';
import { withTheme } from '../config';
import Divider, { DividerProps } from '../divider/Divider';
import { RneFunctionComponent } from '../helpers';

const CardDivider: React.FunctionComponent<DividerProps> = ({
const CardDivider: RneFunctionComponent<DividerProps> = ({
style,
...props
}) => {
Expand Down
3 changes: 2 additions & 1 deletion src/card/CardFeaturedSubtitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Platform, StyleSheet, TextStyle } from 'react-native';
import normalize from '../helpers/normalizeText';
import { fonts, withTheme } from '../config';
import Text, { TextProps } from '../text/Text';
import { RneFunctionComponent } from '../helpers';

const CardFeaturedSubtitle: React.FunctionComponent<TextProps> = ({
const CardFeaturedSubtitle: RneFunctionComponent<TextProps> = ({
theme,
style,
...props
Expand Down
3 changes: 2 additions & 1 deletion src/card/CardFeaturedTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Platform, StyleSheet, TextStyle } from 'react-native';
import normalize from '../helpers/normalizeText';
import { fonts, withTheme } from '../config';
import Text, { TextProps } from '../text/Text';
import { RneFunctionComponent } from '../helpers';

const CardFeaturedTitle: React.FunctionComponent<TextProps> = ({
const CardFeaturedTitle: RneFunctionComponent<TextProps> = ({
theme,
style,
...props
Expand Down
6 changes: 2 additions & 4 deletions src/card/CardImage.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React from 'react';
import { StyleSheet } from 'react-native';
import { withTheme } from '../config';
import { RneFunctionComponent } from '../helpers';
import Image, { ImageProps } from '../image/Image';

const CardImage: React.FunctionComponent<ImageProps> = ({
style,
...props
}) => {
const CardImage: RneFunctionComponent<ImageProps> = ({ style, ...props }) => {
return <Image style={StyleSheet.flatten([styles.image, style])} {...props} />;
};

Expand Down
3 changes: 2 additions & 1 deletion src/card/CardTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Platform, StyleSheet, TextStyle } from 'react-native';
import normalize from '../helpers/normalizeText';
import { fonts, withTheme } from '../config';
import Text, { TextProps } from '../text/Text';
import { RneFunctionComponent } from '../helpers';

const CardTitle: React.FunctionComponent<TextProps> = ({
const CardTitle: RneFunctionComponent<TextProps> = ({
style,
theme,
...props
Expand Down
3 changes: 2 additions & 1 deletion src/checkbox/CheckBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import TextElement from '../text/Text';
import CheckBoxIcon from './CheckBoxIcon';
import { fonts, withTheme } from '../config';
import { CheckBoxIconProps } from './CheckBoxIcon';
import { RneFunctionComponent } from '../helpers';

export type CheckBoxProps = TouchableOpacityProps &
CheckBoxIconProps & {
Expand All @@ -30,7 +31,7 @@ export type CheckBoxProps = TouchableOpacityProps &
fontFamily?: string;
};

const CheckBox: React.FunctionComponent<CheckBoxProps> = (props) => {
const CheckBox: RneFunctionComponent<CheckBoxProps> = (props) => {
const { theme, ...rest } = props;
const {
Component = TouchableOpacity,
Expand Down
6 changes: 2 additions & 4 deletions src/checkbox/CheckBoxIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { ThemeProps } from '../config';
import { RneFunctionComponent } from '../helpers';
import getIconType from '../helpers/getIconType';
import { IconType } from '../icons/Icon';

Expand All @@ -15,9 +15,7 @@ export type CheckBoxIconProps = {
uncheckedColor?: string;
};

const CheckBoxIcon: React.FunctionComponent<
CheckBoxIconProps & ThemeProps<CheckBoxIconProps>
> = ({
const CheckBoxIcon: RneFunctionComponent<CheckBoxIconProps> = ({
checked,
onIconPress,
onLongIconPress,
Expand Down
2 changes: 1 addition & 1 deletion src/config/withTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const ThemedComponent = (
};

function withTheme<P = {}, T = {}>(
WrappedComponent: React.ComponentType<P & ThemeProps<T>>,
WrappedComponent: React.ComponentType<P & Partial<ThemeProps<T>>>,
themeKey: string
):
| React.FunctionComponent<Omit<P, keyof ThemeProps<T>>>
Expand Down
10 changes: 6 additions & 4 deletions src/divider/Divider.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React from 'react';
import { View, StyleSheet, ViewProps } from 'react-native';
import { withTheme } from '../config';
import { ThemeProps } from '../config';
import { RneFunctionComponent } from '../helpers';

export type DividerProps = ViewProps & {
style?: object | any[];
};

const Divider: React.FunctionComponent<
DividerProps & ThemeProps<DividerProps>
> = ({ style, theme, ...rest }) => (
const Divider: RneFunctionComponent<DividerProps> = ({
style,
theme,
...rest
}) => (
<View
style={StyleSheet.flatten([
{
Expand Down
7 changes: 2 additions & 5 deletions src/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import {
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { withTheme } from '../config';
import { renderNode } from '../helpers';
import { renderNode, RneFunctionComponent } from '../helpers';

import Text from '../text/Text';
import Icon, { IconObject } from '../icons/Icon';
import { ThemeProps } from '../config';

type Placement = 'left' | 'center' | 'right';

Expand Down Expand Up @@ -88,9 +87,7 @@ export type HeaderProps = ViewProps & {
elevated: boolean;
};

const Header: React.FunctionComponent<HeaderProps & ThemeProps<HeaderProps>> = (
props: HeaderProps & ThemeProps<HeaderProps>
) => {
const Header: RneFunctionComponent<HeaderProps> = (props) => {
React.useEffect(() => {
const { linearGradientProps, ViewComponent } = props;
if (linearGradientProps && !ViewComponent) {
Expand Down
5 changes: 5 additions & 0 deletions src/helpers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import color from 'color';
import renderNode from './renderNode';
import getIconType from './getIconType';
import normalizeText from './normalizeText';
import { ThemeProps } from '../config';

const Screen = Dimensions.get('window');
const ScreenWidth = Screen.width;
const ScreenHeight = Screen.height;
const isIOS = Platform.OS === 'ios';

export type RneFunctionComponent<T> = React.FunctionComponent<
T & Partial<ThemeProps<T>>
>;

export const patchWebProps = <T extends Record<any, any>>({
updateTheme,
replaceTheme,
Expand Down
6 changes: 2 additions & 4 deletions src/icons/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Color from 'color';
import getIconType from '../helpers/getIconType';
import getIconStyle from '../helpers/getIconStyle';
import { withTheme } from '../config';
import { ThemeProps } from '../config';
import { RneFunctionComponent } from '../helpers';

export type IconType =
| 'material'
Expand Down Expand Up @@ -59,9 +59,7 @@ export type IconProps = IconButtonProps & {
brand?: boolean;
};

const Icon: React.FunctionComponent<IconProps & ThemeProps<IconProps>> = (
props
) => {
const Icon: RneFunctionComponent<IconProps> = (props) => {
const {
type = 'material',
name,
Expand Down
5 changes: 2 additions & 3 deletions src/image/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
ViewStyle,
StyleProp,
} from 'react-native';
import { withTheme } from '../config';
import { ThemeProps } from '../config';
import { ThemeProps, withTheme } from '../config';

export type ImageProps = RNImageProps & {
Component?: typeof React.Component;
Expand All @@ -29,7 +28,7 @@ type ImageState = {
};

class Image extends React.Component<
ImageProps & ThemeProps<ImageProps>,
ImageProps & Partial<ThemeProps<ImageProps>>,
ImageState
> {
static getSize = ImageNative.getSize;
Expand Down
4 changes: 3 additions & 1 deletion src/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export type InputProps = TextInputProps & {
renderErrorMessage?: boolean;
};

class Input extends React.Component<InputProps & ThemeProps<InputProps>> {
class Input extends React.Component<
InputProps & Partial<ThemeProps<InputProps>>
> {
input: any;
shakeAnimationValue = new Animated.Value(0);

Expand Down
3 changes: 2 additions & 1 deletion src/linearProgress/LinearProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from 'react-native';
import { FullTheme } from '../config';
import Color from 'color';
import { RneFunctionComponent } from '../helpers';

export type LinearProgressProps = {
value?: number; // 0 to 1
Expand All @@ -19,7 +20,7 @@ export type LinearProgressProps = {
theme?: FullTheme;
} & ViewProps;

const LinearProgress: React.FunctionComponent<LinearProgressProps> = ({
const LinearProgress: RneFunctionComponent<LinearProgressProps> = ({
value = 0,
variant = 'indeterminate',
color = 'secondary',
Expand Down
Loading

0 comments on commit c6c8aa7

Please sign in to comment.