Skip to content

Commit e191615

Browse files
Feat: UNT-T4799:
Apply animation on button width and corner, like visualized as converting the rectangle to circle shape and visa versa. Support to border [type(line, dot, dash), width, color]. Support Animation duration, alpha with morphing. Support custom spinner.
1 parent a851628 commit e191615

22 files changed

+466
-243
lines changed

Example/App/App.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { ScrollView } from 'react-native';
2+
import { ScrollView, View } from 'react-native';
33
import styles from './styles/AppStyles';
44
import DefaultOrBallSpinnerButton from './DefaultOrBallSpinnerButton';
55
import BarSpinnerButton from './BarSpinnerButton';
@@ -15,12 +15,12 @@ const App = () => {
1515
return (
1616
<ScrollView style={styles.safeArea}>
1717
<DefaultOrBallSpinnerButton />
18-
<BarSpinnerButton />
1918
<DotSpinnerButton />
20-
<MaterialSpinnerButton />
2119
<PacmanSpinnerButton />
22-
<PulseSpinnerButton />
2320
<SkypeSpinnerButton />
21+
<BarSpinnerButton />
22+
<MaterialSpinnerButton />
23+
<PulseSpinnerButton />
2424
<UIActivitySpinnerButton />
2525
<WaveSpinnerButton />
2626
</ScrollView>

Example/App/BarSpinnerButton.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const BarSpinnerButton = () => {
2424
onPress={handleButtonPress}
2525
animationType={'flipInY'}
2626
indicatorCount={10}
27+
animateHeight={50}
28+
animateWidth={200}
29+
animateRadius={10}
30+
animatedDuration={700}
2731
>
2832
<Text style={styles.buttonText}>Bar SpinnerButton</Text>
2933
</SpinnerButton>

Example/App/DefaultOrBallSpinnerButton.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const DefaultOrBallSpinnerButton = () => {
2828
gradientColorAngle={90}
2929
gradientRadialRadius={10}
3030
gradientButtonHeight={50}
31+
borderStyle={styles.borderStyle}
3132
>
3233
<Text style={styles.buttonText}>Default Or Ball SpinnerButton</Text>
3334
</SpinnerButton>

Example/App/DotSpinnerButton.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const DotSpinnerButton = () => {
2424
size={10}
2525
spinnerType='DotIndicator'
2626
onPress={handleButtonPress}
27-
animationType={'flipInX'}
27+
animationType={'bounceIn'}
2828
gradientType={'Radial'}
2929
gradientColors={['#231557', '#44107A', '#FF1361', '#FFF800']}
3030
gradientColoroffset={['0%', '29%', '67%', '100%']}
@@ -35,6 +35,10 @@ const DotSpinnerButton = () => {
3535
radialRadiusy={"50%"}
3636
radialRadiusRX={"50%"}
3737
radialRadiusRY={"50%"}
38+
animateHeight={50}
39+
animateWidth={220}
40+
animateRadius={10}
41+
animatedDuration={700}
3842
>
3943
<Text style={styles.buttonText}>Dot SpinnerButton</Text>
4044
</SpinnerButton>

Example/App/PacmanSpinnerButton.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const PacmanSpinnerButton = () => {
2828
gradientColorAngle={90}
2929
gradientRadialRadius={10}
3030
gradientButtonHeight={50}
31+
animateHeight={70}
32+
animateWidth={70}
33+
animateRadius={35}
3134
>
3235
<Text style={styles.buttonText}>Pacman SpinnerButton</Text>
3336
</SpinnerButton>

Example/App/styles/AppStyles.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ export default StyleSheet.create({
1717
},
1818
buttonStyle: {
1919
borderRadius: 10,
20-
margin: 20,
20+
margin: 5
2121
},
2222
instructions: {
2323
textAlign: 'center',
2424
color: '#333333',
2525
marginBottom: 5,
2626
},
27+
borderStyle: {
28+
borderWidth: 2,
29+
borderRadius: 10,
30+
borderColor: 'blue',
31+
borderStyle: 'solid'
32+
}
2733
});

README.md

Lines changed: 91 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Don't forget to set the state variable you have given to _isLoading_ prop false
4545
1. **animationType**
4646
* Type of animation for the button and spinner.
4747
* Default type: string
48-
* Default value: _fadeIn_
48+
* Default value: null | undefined
4949
2. **buttonStyle**
5050
* Its a stylesheet object.
5151
* Default button style
@@ -57,27 +57,22 @@ Don't forget to set the state variable you have given to _isLoading_ prop false
5757
backgroundColor: '#25CAC6',
5858
}
5959
```
60-
3. **indicatorCount**
61-
* The count property of react-native-indicators.
62-
* Default type: number
63-
* Default value: _fadeIn_
64-
4. **isLoading**
65-
* The flag to render a Button or a Spinner. _false_ will render button and _true_ will render button.
66-
* Default type: boolean
67-
* Default value: _false_
68-
5. **onPress**
69-
* The function to execute on tap of the button.
70-
* Default type: functin.
71-
* Default value: _nothing is executed_
72-
6. **size**
73-
* The size of the Spinner.
74-
* Default type: number
75-
* Its default value _veries according to the spinnerType_.
76-
7. **spinnerColor**
60+
3. **borderStyle**
61+
* Its a stylesheet object with support all basic border property like width, radius, color and style(solid, dotted and dashed) etc.
62+
* If you want to need to apply border in your button then you should used like
63+
```javascript
64+
buttonBorderStyle: {
65+
borderWidth: 2,
66+
borderRadius: 10,
67+
borderColor: 'blue',
68+
borderStyle: 'solid'
69+
}
70+
```
71+
4. **spinnerColor**
7772
* The color of the Spinner.
7873
* Default type: string
7974
* Its default value is _white_. You can give spinnerColor in all react-native acceptable formats of color.
80-
8. **spinnerType**
75+
5. **spinnerType**
8176
* Type of the spinner.
8277
* Default type: string
8378
* Its default value is _BallIndicator_.
@@ -90,11 +85,81 @@ Don't forget to set the state variable you have given to _isLoading_ prop false
9085
6. PulseIndicator
9186
7. SkypeIndicator
9287
8. UIActivityIndicator
93-
9. WaveIndicator
94-
9. **spinnerOptions**
88+
9. WaveIndicator
89+
6. **isLoading**
90+
* The flag to render a Button or a Spinner. _false_ will render button and _true_ will render spinner.
91+
* Default type: boolean
92+
* Default value: _false_
93+
7. **onPress**
94+
* The function to execute on tap of the button.
95+
* Default type: function.
96+
* Default value: _nothing is executed_
97+
8. **indicatorCount**
98+
* The count property of react-native-indicators.
99+
* Default type: number
100+
* Default value: null | undefined
101+
9. **size**
102+
* The size of the Spinner.
103+
* Default type: number
104+
* Its default value _veries according to the spinnerType_.
105+
10. **spinnerOptions**
95106
* An object of waveMode for WaveIndicator for WaveIndicator.
96107
* Default type: Object
97108
* For more details about these properties, refer [react-native-indicators](https://github.com/n4kz/react-native-indicators)
109+
11. **gradientType**
110+
* Gradients allow you to show more than one color with a smooth transition between the colors (think Instagram logo).
111+
* They come in handy when trying to create multi-color backgrounds or custom buttons. You can have gradients in different varieties, horizontally, vertically, diagonally, etc.
112+
* Currently, we are supporting two types of gradient 1.Linear Gradient & 2.Radial Gradient.
113+
12. **gradientColors**
114+
* This is how we pass the colors we want to be displayed, colors can be passed in a different format, name, rgba, hex etc.
115+
* The colors should be ordered the way we want them to be displayed.
116+
* Eg. colors={[ “purple”, “white” ]} the gradient will move from purple to white.
117+
13. **gradientColoroffset**
118+
* An array of string that define where each color will stop in the gradient.
119+
* These values are also passed as a percentage of the entire gradient from 0%100% and have to map the corresponding colors passed in length and position.
120+
* For colors={[“red”, “yellow”, “green”}] then well have locations={['0%', '50%', '80%']} with first color (red) covering '0%''50%', second (yellow) going from '50%''80%' and yellow '80%''100%'
121+
14. **gradientColorAngle**
122+
* The gradient line's angle of direction. A value of 0deg is equivalent to to top; increasing values rotate clockwise from there.
123+
* The angle range of 0 to 360.
124+
* [More detail to read](https://www.quirksmode.org/css/images/angles.html)
125+
15. **gradientRadialRadius**
126+
* This property used for Radial type gradient in set radius of radial gradient.
127+
16. **gradientButtonHeight**
128+
* The size of the gradient component.
129+
* Default type: number
130+
17. **radialRadiusx**
131+
* The x coordinate of the center of the radial gradient.
132+
18. **radialRadiusy**
133+
* The y coordinate of the center of the radial gradient.
134+
19. **radialRadiusRX**
135+
* The horizontal radius of the radial gradient defining ellipse.
136+
20. **radialRadiusRY**
137+
* The vertical radius of the radial gradient defining ellipse.
138+
21. **animatedDuration**
139+
* Used for animation time, how long you have to execute your animation.
140+
22. **customSpinnerComponent**
141+
* This props will allow you to add your own custom spinner component.
142+
23. **animateWidth**
143+
* This props used to set component width when progress/loading will start..
144+
* If you want to not set this props then identify width and height which is minimum and then used that value.
145+
24. **animateHeight**
146+
* This props used to set component height when progress/loading will start.
147+
* If you want to not set this props then identify width and height which is minimum and then used that value.
148+
25. **animateRadius**
149+
* This props used to set component radius when progress/loading will start.
150+
* If you want to not set this props then create circle shape.
151+
26. **isConnected**
152+
* The flag to identify network connection and based on flag set user iteration. _false_ will render button with disable mode and _true_ will render button with normal mode.
153+
* Default type: boolean
154+
* Default value: _true_
155+
27. **isDisable**
156+
* The flag to identify button enable/disable. _true_ will render button with disable mode and _false_ will render button with normal mode.
157+
* Default type: boolean
158+
* Default value: _false_
159+
28. **disableStyle**
160+
* Its a stylesheet object.
161+
* This style apply when identify button disable or if network connect not available.
162+
* Default value: null | undefined
98163
99164
## Example
100165
A full working example project is here [Example](https://github.com/simformsolutions/react-native-spinner-button/tree/master/Example)
@@ -104,6 +169,11 @@ Don't forget to set the state variable you have given to _isLoading_ prop false
104169
* [react-native-animatable](https://github.com/oblador/react-native-animatable)
105170
* [SSspinnerButton](https://github.com/simformsolutions/SSSpinnerButton)
106171
172+
## Roadmap (What to do in next)
173+
1. Support inbuild different gradient with name.
174+
2. Support result state (InPreogress, InSuccess and InFailure).
175+
3. Neon style apply
176+
4. Button shadow
107177
## License
108178
109179
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import { View } from 'react-native';
43
import styles from './styles/SpinnerButtonStyle';
54
import SpinnerComponent from './SpinnerComponent';
65
import * as Animatable from 'react-native-animatable';
7-
import { DEFAULT_ANIMATION_TYPE, getSpinnerStyle } from './utils';
86

9-
const Spinner = ({
7+
const AnimatableView = ({
108
animationType,
11-
buttonStyle,
9+
children,
10+
customSpinnerComponent,
11+
height,
12+
size,
1213
spinnerColor,
1314
spinnerType,
14-
isLoading,
1515
indicatorCount,
16-
size,
17-
spinnerOptions
16+
spinnerOptions,
17+
isLoading,
18+
animatedDuration
1819
}) => {
19-
if (isLoading) {
20-
const { height, width, customSpinnerStyle } = getSpinnerStyle(spinnerType, buttonStyle, styles.defaultButtonStyle);
21-
return (
22-
<View style={[styles.loaderContainer, { width: width }]}>
23-
<Animatable.View
24-
animation={animationType || DEFAULT_ANIMATION_TYPE}
25-
style={[styles.defaultSpinnerContainerStyle, customSpinnerStyle]}>
20+
const isCustomeSpinner = customSpinnerComponent !== null && customSpinnerComponent !== undefined;
21+
return (
22+
<>
23+
{!isLoading &&
24+
<Animatable.View animation={animationType} duration={animatedDuration}>
25+
{children}
26+
</Animatable.View>
27+
}
28+
{isLoading &&
29+
<Animatable.View animation={animationType} duration={animatedDuration} style={styles.absoluteView}>
30+
{isCustomeSpinner && customSpinnerComponent}
31+
{!isCustomeSpinner &&
2632
<SpinnerComponent
2733
height={height}
2834
size={size}
@@ -31,24 +37,28 @@ const Spinner = ({
3137
indicatorCount={indicatorCount}
3238
spinnerOptions={spinnerOptions}
3339
/>
40+
}
3441
</Animatable.View>
35-
</View>
36-
);
37-
}
42+
}
43+
</>
44+
)
3845
};
3946

40-
Spinner.propTypes = {
47+
AnimatableView.propTypes = {
4148
animationType: PropTypes.string,
42-
buttonStyle: PropTypes.object,
49+
children: PropTypes.any.isRequired,
50+
customSpinnerComponent: PropTypes.node,
51+
height: PropTypes.number,
52+
size: PropTypes.number,
4353
spinnerColor: PropTypes.string,
4454
spinnerType: PropTypes.string,
45-
isLoading: PropTypes.bool,
4655
indicatorCount: PropTypes.number,
47-
size: PropTypes.number,
4856
spinnerOptions: PropTypes.shape({
4957
waveFactor: PropTypes.number,
5058
waveMode: PropTypes.string
51-
})
52-
}
59+
}),
60+
isLoading: PropTypes.bool,
61+
animatedDuration: PropTypes.number
62+
};
5363

54-
export default Spinner;
64+
export default AnimatableView;

components/AnimatedView.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { Animated } from 'react-native';
4+
import styles from './styles/SpinnerButtonStyle';
5+
import SpinnerComponent from './SpinnerComponent';
6+
7+
const AnimatedView = ({
8+
animatedChildHideStyle,
9+
animatedChildShowStyle,
10+
children,
11+
customSpinnerComponent,
12+
height,
13+
size,
14+
spinnerColor,
15+
spinnerType,
16+
indicatorCount,
17+
spinnerOptions
18+
}) => {
19+
const isCustomeSpinner = customSpinnerComponent !== null && customSpinnerComponent !== undefined;
20+
return (
21+
<>
22+
<Animated.View style={animatedChildHideStyle}>
23+
{children}
24+
</Animated.View>
25+
<Animated.View style={[styles.absoluteView, animatedChildShowStyle]}>
26+
{isCustomeSpinner && customSpinnerComponent}
27+
{!isCustomeSpinner &&
28+
<SpinnerComponent
29+
height={height}
30+
size={size}
31+
spinnerColor={spinnerColor}
32+
spinnerType={spinnerType}
33+
indicatorCount={indicatorCount}
34+
spinnerOptions={spinnerOptions}
35+
/>
36+
}
37+
</Animated.View>
38+
</>
39+
)
40+
};
41+
42+
AnimatedView.propTypes = {
43+
animatedChildHideStyle: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
44+
animatedChildShowStyle: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
45+
children: PropTypes.any.isRequired,
46+
customSpinnerComponent: PropTypes.node,
47+
height: PropTypes.number,
48+
size: PropTypes.number,
49+
spinnerColor: PropTypes.string,
50+
spinnerType: PropTypes.string,
51+
indicatorCount: PropTypes.number,
52+
spinnerOptions: PropTypes.shape({
53+
waveFactor: PropTypes.number,
54+
waveMode: PropTypes.string
55+
})
56+
};
57+
58+
export default AnimatedView;

0 commit comments

Comments
 (0)