Skip to content

Commit 060fe5d

Browse files
32penkinartyorsh
authored andcommitted
feat(ui): animation-config property to Icon component add
1 parent c4ac3a8 commit 060fe5d

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed

src/framework/ui/icon/icon.component.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ import {
55
ViewStyle,
66
} from 'react-native';
77
import {
8+
getIconAnimation,
89
IconAnimation,
910
IconAnimationRegistry,
10-
IconAnimations,
1111
} from './iconAnimation';
1212
import {
1313
IconRegistryService,
1414
RegisteredIcon,
1515
} from './service/iconRegistry.service';
16+
import { AnimationConfig } from '../animation';
1617

1718
interface ComponentProps {
1819
name: string;
1920
pack?: string;
2021
animation?: keyof IconAnimationRegistry;
22+
animationConfig?: AnimationConfig;
2123
}
2224

2325
export type IconProps<T = {}> = ComponentProps & T;
@@ -31,11 +33,17 @@ export type IconElement<T> = React.ReactElement<T>;
3133
* @extends React.Component
3234
*
3335
* @method {(callback?: Animated.EndCallback) => void} startAnimation - Toggle animation to start.
36+
*
3437
* @method {() => void} stopAnimation - Toggle animation to stop.
38+
*
3539
* @property {string} name - Name of registered icon.
40+
*
3641
* @property {string} pack - Name of icon pack that is able to provide an icon for specified name.
42+
*
3743
* @property {string} animation - Animation name. Available `zoom`, `pulse` and `shake`. Default is `zoom`.
3844
*
45+
* @property {AnimationConfig} animationConfig - Determines animation config. Extends `Animated.AnimationConfig`.
46+
*
3947
* @overview-example Register Icons
4048
*
4149
* ```
@@ -86,6 +94,28 @@ export type IconElement<T> = React.ReactElement<T>;
8694
* iconRef.current.startAnimation();
8795
* ```
8896
*
97+
* @example Infinite Animation
98+
*
99+
* ```
100+
* import React from 'react';
101+
* import { Icon } from 'react-native-ui-kitten';
102+
*
103+
* const iconRef = React.createRef();
104+
*
105+
* export const StarIcon = (props) => (
106+
* <Icon
107+
* ref={iconRef}
108+
* name='star'
109+
* animation='shake'
110+
* animationConfig={{
111+
cycles: -1,
112+
}}
113+
* />
114+
* );
115+
*
116+
* iconRef.current.startAnimation();
117+
* ```
118+
*
89119
* @example Password Input
90120
*
91121
* ```
@@ -166,7 +196,7 @@ export class Icon<T> extends React.Component<IconProps<T>> {
166196

167197
constructor(props: IconProps<T>) {
168198
super(props);
169-
this.animation = IconAnimations[props.animation];
199+
this.animation = getIconAnimation(props.animation, props.animationConfig);
170200
}
171201

172202
public componentWillUnmount() {

src/framework/ui/icon/iconAnimation.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
PulseAnimation,
55
ShakeAnimation,
66
ZoomAnimation,
7+
AnimationConfig,
78
} from '../animation';
89

910
export type IconAnimation = Animation<any, ViewStyle>;
@@ -14,8 +15,15 @@ export interface IconAnimationRegistry {
1415
shake: IconAnimation;
1516
}
1617

17-
export const IconAnimations: IconAnimationRegistry = {
18-
zoom: new ZoomAnimation(),
19-
pulse: new PulseAnimation(),
20-
shake: new ShakeAnimation(),
21-
};
18+
export function getIconAnimation(animation?: keyof IconAnimationRegistry,
19+
config?: AnimationConfig): IconAnimation {
20+
21+
switch (animation) {
22+
case 'zoom':
23+
return new ZoomAnimation(config);
24+
case 'pulse':
25+
return new PulseAnimation(config);
26+
case 'shake':
27+
return new ShakeAnimation(config);
28+
}
29+
}

src/framework/ui/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export { AnimationConfig } from './animation';
12
export {
23
Avatar,
34
AvatarProps,

src/playground/src/ui/screen/icon/type.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ const shakeIcon: ComponentShowcaseItem = {
3131
},
3232
};
3333

34+
const infiniteExample: ComponentShowcaseItem = {
35+
title: 'Infinite',
36+
props: {
37+
animation: 'shake',
38+
animationConfig: {
39+
cycles: -1,
40+
},
41+
},
42+
};
43+
3444
const defaultSection: ComponentShowcaseSection = {
3545
title: 'Default',
3646
items: [
@@ -47,10 +57,18 @@ const animationSection: ComponentShowcaseSection = {
4757
],
4858
};
4959

60+
const infiniteSection: ComponentShowcaseSection = {
61+
title: 'Infinite Animation',
62+
items: [
63+
infiniteExample,
64+
],
65+
};
66+
5067
export const iconShowcase: ComponentShowcase = {
5168
sections: [
5269
defaultSection,
5370
animationSection,
71+
infiniteSection,
5472
],
5573
};
5674

0 commit comments

Comments
 (0)