Skip to content

Commit 4a8d19d

Browse files
dVaytulgreenfrvr
andauthored
feat: add linear and circular progress bars (#1567)
Co-authored-by: Artsiom Grintsevich <greenfrvr@gmail.com>
1 parent df96d0d commit 4a8d19d

15 files changed

+1015
-4
lines changed

docs/src/structure.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,28 @@ export const structure = [
711711
description: 'Spinner displays a loading state of a page or a section.',
712712
keywords: 'ui kitten, ui kitten menu, kitten extra, ui kitten spinner ',
713713
},
714+
{
715+
type: 'tabs',
716+
name: 'ProgressBar',
717+
icon: 'progress-bar.svg',
718+
source: [
719+
'ProgressBar',
720+
],
721+
title: 'ProgressBar',
722+
description: 'Displays the length of a process.',
723+
keywords: 'ui kitten, ui kitten menu, kitten extra, ui kitten progress bar ',
724+
},
725+
{
726+
type: 'tabs',
727+
name: 'CircularProgressBar',
728+
icon: 'circular-progress-bar.svg',
729+
source: [
730+
'CircularProgressBar',
731+
],
732+
title: 'CircularProgressBar',
733+
description: 'Displays the length of a process.',
734+
keywords: 'ui kitten, ui kitten menu, kitten extra, ui kitten circular progress bar ',
735+
},
714736
{
715737
type: 'tabs',
716738
name: 'Calendar',

src/components/theme/modal/modal.spec.tsx

Whitespace-only changes.

src/components/ui/card/card.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export class Card extends React.Component<CardProps> {
152152
component={header}
153153
/>
154154
{header && <Divider />}
155-
<View style={[ styles.content, evaStyle.body ]}>
155+
<View style={[styles.content, evaStyle.body]}>
156156
{children}
157157
</View>
158158
{footer && <Divider />}
@@ -174,5 +174,5 @@ const styles = StyleSheet.create({
174174
},
175175
content: {
176176
flexShrink: 1,
177-
}
177+
},
178178
});
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* @license
3+
* Copyright Akveo. All Rights Reserved.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*/
6+
7+
import {
8+
Animated,
9+
Easing,
10+
Platform,
11+
} from 'react-native';
12+
import {
13+
Animation,
14+
AnimationConfig,
15+
} from '../animation/animation';
16+
17+
const DEFAULT_CONFIG: CircularProgressBarAnimationConfig = {
18+
duration: 500,
19+
easing: Easing.linear,
20+
cycles: 1,
21+
useNativeDriver: Platform.OS !== 'web',
22+
};
23+
24+
interface AnimationStyle {
25+
rotateFirstHalf: Animated.AnimatedInterpolation<string>;
26+
rotateSecondHalf: Animated.AnimatedInterpolation<string>;
27+
}
28+
29+
type TimingAnimationConfig = Omit<Animated.TimingAnimationConfig, 'toValue'>;
30+
31+
export type CircularProgressBarAnimationConfig = AnimationConfig & TimingAnimationConfig;
32+
33+
export class CircularProgressBarAnimation extends Animation<CircularProgressBarAnimationConfig, AnimationStyle> {
34+
35+
private toValue: number;
36+
private readonly animationValue: Animated.Value;
37+
38+
constructor(config?: Partial<CircularProgressBarAnimationConfig>) {
39+
super({ ...DEFAULT_CONFIG, ...config });
40+
this.animationValue = new Animated.Value(0);
41+
}
42+
43+
protected get animation(): Animated.CompositeAnimation {
44+
return Animated.timing(
45+
this.animationValue,
46+
{
47+
...this.config,
48+
toValue: this.toValue,
49+
},
50+
);
51+
}
52+
53+
public startDeterminate(toValue: number, callback?: Animated.EndCallback): void {
54+
this.toValue = toValue;
55+
super.start(callback);
56+
}
57+
58+
public stop(): void {
59+
super.stop();
60+
}
61+
62+
public toProps(): AnimationStyle {
63+
return {
64+
rotateFirstHalf: this.createRotateFirstHalfInterpolation(),
65+
rotateSecondHalf: this.createRotateSecondHalfInterpolation(),
66+
};
67+
}
68+
69+
private createRotateFirstHalfInterpolation = (): Animated.AnimatedInterpolation<string> => {
70+
return this.animationValue.interpolate({
71+
inputRange: [0, 0.5],
72+
outputRange: ['180deg', '360deg'],
73+
extrapolate: 'clamp',
74+
});
75+
};
76+
77+
private createRotateSecondHalfInterpolation = (): Animated.AnimatedInterpolation<string> => {
78+
return this.animationValue.interpolate({
79+
inputRange: [0.5, 1],
80+
outputRange: ['180deg', '360deg'],
81+
extrapolate: 'clamp',
82+
});
83+
};
84+
85+
}

0 commit comments

Comments
 (0)