Skip to content

Commit

Permalink
feat(ui): animation-config property to Icon component add
Browse files Browse the repository at this point in the history
  • Loading branch information
32penkin authored and artyorsh committed Sep 24, 2019
1 parent c4ac3a8 commit 060fe5d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 7 deletions.
34 changes: 32 additions & 2 deletions src/framework/ui/icon/icon.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ import {
ViewStyle,
} from 'react-native';
import {
getIconAnimation,
IconAnimation,
IconAnimationRegistry,
IconAnimations,
} from './iconAnimation';
import {
IconRegistryService,
RegisteredIcon,
} from './service/iconRegistry.service';
import { AnimationConfig } from '../animation';

interface ComponentProps {
name: string;
pack?: string;
animation?: keyof IconAnimationRegistry;
animationConfig?: AnimationConfig;
}

export type IconProps<T = {}> = ComponentProps & T;
Expand All @@ -31,11 +33,17 @@ export type IconElement<T> = React.ReactElement<T>;
* @extends React.Component
*
* @method {(callback?: Animated.EndCallback) => void} startAnimation - Toggle animation to start.
*
* @method {() => void} stopAnimation - Toggle animation to stop.
*
* @property {string} name - Name of registered icon.
*
* @property {string} pack - Name of icon pack that is able to provide an icon for specified name.
*
* @property {string} animation - Animation name. Available `zoom`, `pulse` and `shake`. Default is `zoom`.
*
* @property {AnimationConfig} animationConfig - Determines animation config. Extends `Animated.AnimationConfig`.
*
* @overview-example Register Icons
*
* ```
Expand Down Expand Up @@ -86,6 +94,28 @@ export type IconElement<T> = React.ReactElement<T>;
* iconRef.current.startAnimation();
* ```
*
* @example Infinite Animation
*
* ```
* import React from 'react';
* import { Icon } from 'react-native-ui-kitten';
*
* const iconRef = React.createRef();
*
* export const StarIcon = (props) => (
* <Icon
* ref={iconRef}
* name='star'
* animation='shake'
* animationConfig={{
cycles: -1,
}}
* />
* );
*
* iconRef.current.startAnimation();
* ```
*
* @example Password Input
*
* ```
Expand Down Expand Up @@ -166,7 +196,7 @@ export class Icon<T> extends React.Component<IconProps<T>> {

constructor(props: IconProps<T>) {
super(props);
this.animation = IconAnimations[props.animation];
this.animation = getIconAnimation(props.animation, props.animationConfig);
}

public componentWillUnmount() {
Expand Down
18 changes: 13 additions & 5 deletions src/framework/ui/icon/iconAnimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
PulseAnimation,
ShakeAnimation,
ZoomAnimation,
AnimationConfig,
} from '../animation';

export type IconAnimation = Animation<any, ViewStyle>;
Expand All @@ -14,8 +15,15 @@ export interface IconAnimationRegistry {
shake: IconAnimation;
}

export const IconAnimations: IconAnimationRegistry = {
zoom: new ZoomAnimation(),
pulse: new PulseAnimation(),
shake: new ShakeAnimation(),
};
export function getIconAnimation(animation?: keyof IconAnimationRegistry,
config?: AnimationConfig): IconAnimation {

switch (animation) {
case 'zoom':
return new ZoomAnimation(config);
case 'pulse':
return new PulseAnimation(config);
case 'shake':
return new ShakeAnimation(config);
}
}
1 change: 1 addition & 0 deletions src/framework/ui/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { AnimationConfig } from './animation';
export {
Avatar,
AvatarProps,
Expand Down
18 changes: 18 additions & 0 deletions src/playground/src/ui/screen/icon/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ const shakeIcon: ComponentShowcaseItem = {
},
};

const infiniteExample: ComponentShowcaseItem = {
title: 'Infinite',
props: {
animation: 'shake',
animationConfig: {
cycles: -1,
},
},
};

const defaultSection: ComponentShowcaseSection = {
title: 'Default',
items: [
Expand All @@ -47,10 +57,18 @@ const animationSection: ComponentShowcaseSection = {
],
};

const infiniteSection: ComponentShowcaseSection = {
title: 'Infinite Animation',
items: [
infiniteExample,
],
};

export const iconShowcase: ComponentShowcase = {
sections: [
defaultSection,
animationSection,
infiniteSection,
],
};

Expand Down

0 comments on commit 060fe5d

Please sign in to comment.