Skip to content

Commit 5cf07a1

Browse files
Merge pull request #57 from SimformSolutionsPvtLtd/feature/UNT-T23537_Strict_TS_Support
feature: UNT-T23537: Strict TS Support
2 parents 67f5d6c + 60dceea commit 5cf07a1

File tree

12 files changed

+90
-51
lines changed

12 files changed

+90
-51
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Props for Spinner Button
163163
| spinnerType | BallIndicator | string | Type of the spinner (BallIndicator, BarIndicator, DotIndicator, MaterialIndicator, PacmanIndicator, PulseIndicator, SkypeIndicator, UIActivityIndicator, WaveIndicator) |
164164
| isLoading | false | boolean | The flag to render a Button or a Spinner. false will render button and true will render spinner |
165165
| indicatorCount | 8 | number | The count property of react-native-indicators |
166-
| size | 40 | number | The size of the Spinner |
166+
| size | 16 | number | The size of the Dot in DotIndicator |
167167
| spinnerOptions | - | object | An object of waveMode for WaveIndicator for WaveIndicator. For more details about these properties, refer [react-native-indicators](https://github.com/n4kz/react-native-indicators) |
168168
| gradientType | - | string | Gradients allow you to show more than one color with a smooth transition between the colors (think Instagram logo). Currently, we are supporting two types of gradient (linear, radial) |
169169
| gradientColors | - | array | Colors can be passed in a different format name, rgba, hex etc. The colors should be ordered the way we want them to be displayed. Eg. colors={[ “purple”, “white” ]} the gradient will move from purple to white |

example/App/DefaultOrBallSpinnerButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const DefaultOrBallSpinnerButton: React.FC = () => {
1919
isLoading={isLoading}
2020
onPress={handleButtonPress}
2121
indicatorCount={10}
22-
gradientType={'linear'}
22+
gradientType={'Linear'}
2323
gradientColors={['#0186DA', '#B631A7']}
2424
gradientColoroffset={['0%', '90%']}
2525
gradientColorAngle={360}

example/App/PacmanSpinnerButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const PacmanSpinnerButton: React.FC = () => {
1919
isLoading={isLoading}
2020
spinnerType="PacmanIndicator"
2121
onPress={handleButtonPress}
22-
gradientType={'linear'}
22+
gradientType={'Linear'}
2323
gradientColors={['#363553', '#903775', '#E8458B',]}
2424
gradientColoroffset={['0%', '20%', '66%']}
2525
gradientColorAngle={25}

example/App/SkypeSpinnerButton.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ const SkypeSpinnerButton: React.FC = () => {
1818
buttonStyle={[styles.buttonStyle, style.btnStyle]}
1919
isLoading={isLoading}
2020
spinnerType="SkypeIndicator"
21-
spinnerOptions={{
22-
maxScale: 2,
23-
}}
2421
onPress={handleButtonPress}
2522
gradientType={'Radial'}
2623
gradientColors={['#AAB6FB', '#30238B']}

src/components/AnimatableView/AnimatableTypes.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export type SpinnerType =
99
| 'PulseIndicator'
1010
| 'SkypeIndicator'
1111
| 'UIActivityIndicator'
12-
| 'WaveIndicator';
12+
| 'WaveIndicator'
13+
| 'BallIndicator';
1314

1415
export type CommonViewProps = {
1516
children: JSX.Element;
@@ -18,8 +19,8 @@ export type CommonViewProps = {
1819
size: number;
1920
spinnerColor: ColorValue;
2021
spinnerType: SpinnerType;
21-
indicatorCount: number;
22-
spinnerOptions: SpinnerOptionsProp;
22+
indicatorCount?: number;
23+
spinnerOptions?: SpinnerOptionsProp;
2324
};
2425

2526
export type AnimatableViewProps = CommonViewProps & {

src/components/Button/ButtonTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export type AnimationType = 'ripple-effect';
44

55
export type ButtonProps = {
66
style?: StyleProp<ViewStyle>;
7-
onPress?: () => void;
7+
onPress: () => void;
88
children: JSX.Element;
99
animatedDuration?: number;
1010
rippleColor?: string;

src/components/ChildrenView/ChildrenViewTypes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Animated, ColorValue } from 'react-native';
2+
import type { GradientType } from '../SpinnerButton';
23

34
export type AnimatedStyleProp = {
45
width: Animated.AnimatedInterpolation<number>;
@@ -10,7 +11,7 @@ export type AnimatedStyleProp = {
1011

1112
export type ChildrenViewProps = {
1213
animatedStyles: AnimatedStyleProp;
13-
gradientType?: string;
14+
gradientType?: GradientType;
1415
gradientColors?: ColorValue[];
1516
gradientColoroffset?: string[];
1617
gradientColorAngle?: number;

src/components/RippleButton/RippleButtonTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import type { StyleProp, ViewStyle } from 'react-native';
22

33
export type RippleProps = {
44
style?: StyleProp<ViewStyle>;
5-
onPress?: () => void;
5+
onPress: () => void;
66
children: JSX.Element;
77
animatedDuration?: number;
88
rippleColor?: string;
99
};
1010

1111
export type RippleButtonProp = {
12-
onPress?: () => void;
12+
onPress: () => void;
1313
animatedDuration?: number;
1414
};

src/components/SpinnerButton/SpinnerButton.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import React from 'react';
22
import { Animated, TouchableOpacity, View } from 'react-native';
33
import type { StyleProp, ViewStyle, ColorValue } from 'react-native';
44
import { AnimatableView, AnimatedView, ChildrenView } from '../../components';
5-
import { getSpinnerStyle, useAnimatedValues } from '../../utils';
5+
import {
6+
DEFAULT_COLOR_WHITE,
7+
getSpinnerStyle,
8+
useAnimatedValues,
9+
} from '../../utils';
610
import type { SpinnerButtonProps } from './SpinnerButtonTypes';
711
import { SpinnerButtonStyle } from '../../styles';
812

@@ -15,12 +19,12 @@ const SpinnerButton: React.FC<SpinnerButtonProps> = ({
1519
buttonContainer,
1620
buttonStyle,
1721
borderStyle,
18-
spinnerColor,
19-
spinnerType,
22+
spinnerColor = DEFAULT_COLOR_WHITE,
23+
spinnerType = 'BallIndicator',
2024
onPress,
2125
children,
2226
indicatorCount,
23-
size,
27+
size = 16,
2428
spinnerOptions,
2529
gradientName,
2630
gradientType,
@@ -38,7 +42,7 @@ const SpinnerButton: React.FC<SpinnerButtonProps> = ({
3842
animateWidth,
3943
animateHeight,
4044
animateRadius,
41-
isLoading,
45+
isLoading = false,
4246
isConnected = true,
4347
disabled = false,
4448
disableStyle,
@@ -47,7 +51,7 @@ const SpinnerButton: React.FC<SpinnerButtonProps> = ({
4751
const isDisable: boolean = disabled || !isConnected;
4852
const isAnimationType: boolean =
4953
animationType !== null && animationType !== undefined;
50-
const gradientColor: ColorValue[] = isDisable
54+
const gradientColor: ColorValue[] | undefined = isDisable
5155
? disableGradientColors || gradientColors
5256
: gradientColors;
5357
const style: StyleProp<ViewStyle> = [
@@ -100,7 +104,7 @@ const SpinnerButton: React.FC<SpinnerButtonProps> = ({
100104
gradientName={gradientName}
101105
children={
102106
<>
103-
{isAnimationType && (
107+
{isAnimationType && typeof animationType === 'string' && (
104108
<AnimatableView
105109
animationType={animationType}
106110
children={children}

src/components/SpinnerButton/SpinnerButtonTypes.ts

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export type SpinnerOptionsProp = {
77
waveMode?: waveModeType;
88
};
99

10+
export type GradientType = 'Linear' | 'Radial';
11+
1012
export type GradientNames =
1113
| 'Warm Flame'
1214
| 'Night Fade'
@@ -177,37 +179,71 @@ export type GradientNames =
177179
| 'Fabled Sunset'
178180
| 'Perfect Blue';
179181

180-
export type SpinnerButtonProps = {
181-
animationType: string;
182-
buttonContainer: StyleProp<ViewStyle>;
183-
buttonStyle: StyleProp<ViewStyle>;
184-
borderStyle: StyleProp<ViewStyle>;
185-
spinnerColor: ColorValue;
186-
spinnerType: SpinnerType;
182+
export interface CommonOptionalProps {
183+
animationType?: string;
184+
buttonContainer?: StyleProp<ViewStyle>;
185+
buttonStyle?: StyleProp<ViewStyle>;
186+
borderStyle?: StyleProp<ViewStyle>;
187+
spinnerColor?: ColorValue;
188+
spinnerType?: SpinnerType;
189+
indicatorCount?: number;
190+
size?: number;
191+
spinnerOptions?: SpinnerOptionsProp;
192+
gradientColors?: ColorValue[];
193+
gradientColoroffset?: string[];
194+
gradientColorAngle?: number;
195+
animatedDuration?: number;
196+
customSpinnerComponent?: JSX.Element;
197+
animateWidth?: number;
198+
animateHeight?: number;
199+
animateRadius?: number;
200+
disabled?: boolean;
201+
isLoading?: boolean;
202+
isConnected?: boolean;
203+
disableStyle?: StyleProp<ViewStyle>;
204+
disableGradientColors?: ColorValue[];
205+
gradientName?: GradientNames;
206+
radialRadiusx?: string | number;
207+
radialRadiusy?: string | number;
208+
radialRadiusRX?: string | number;
209+
radialRadiusRY?: string | number;
210+
gradientRadialRadius?: number;
211+
gradientButtonHeight?: number;
212+
}
213+
214+
export interface SpinnerButtonBaseProps extends CommonOptionalProps {
187215
onPress: () => void;
188216
children: JSX.Element;
189-
indicatorCount: number;
190-
size: number;
191-
spinnerOptions: SpinnerOptionsProp;
192-
gradientType: string;
193-
gradientColors: ColorValue[];
194-
gradientColoroffset: string[];
195-
gradientColorAngle: number;
217+
}
218+
219+
export interface LinearGradientBaseProps extends CommonOptionalProps {
220+
gradientType: 'Linear';
196221
gradientRadialRadius: number;
197222
gradientButtonHeight: number;
223+
}
224+
225+
export interface RadialGradientBaseProps extends CommonOptionalProps {
226+
gradientType: 'Radial';
198227
radialRadiusx: string | number;
199228
radialRadiusy: string | number;
200229
radialRadiusRX: string | number;
201230
radialRadiusRY: string | number;
202-
animatedDuration: number;
203-
customSpinnerComponent?: JSX.Element;
204-
animateWidth: number;
205-
animateHeight: number;
206-
animateRadius: number;
207-
disabled: boolean;
208-
isLoading: boolean;
209-
isConnected: boolean;
210-
disableStyle: StyleProp<ViewStyle>;
211-
disableGradientColors: ColorValue[];
212-
gradientName: GradientNames;
213-
};
231+
gradientRadialRadius: number;
232+
gradientButtonHeight: number;
233+
}
234+
235+
export interface BasicSpinnerButtonBaseProps extends CommonOptionalProps {
236+
gradientType?: never;
237+
}
238+
239+
type BasicSpinnerButtonProps = SpinnerButtonBaseProps &
240+
BasicSpinnerButtonBaseProps;
241+
242+
type LinearGradientProps = SpinnerButtonBaseProps & LinearGradientBaseProps;
243+
244+
type RadialGradientProps = SpinnerButtonBaseProps & RadialGradientBaseProps;
245+
246+
export type SpinnerButtonProps =
247+
| BasicSpinnerButtonProps
248+
| LinearGradientProps
249+
| RadialGradientProps;

0 commit comments

Comments
 (0)