Skip to content

Commit

Permalink
Merge pull request #7 from samagragupta/master
Browse files Browse the repository at this point in the history
Adding style to base animation and json animation
  • Loading branch information
swapnil1104 authored Feb 5, 2023
2 parents 0517556 + 34ab149 commit 27b26aa
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
10 changes: 6 additions & 4 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ private _onPressToReset = (_: GestureResponderEvent) => {
```
### AnimationWrapperView props
| Prop name | Prop Type | Description |
| --- | --- | --- |
| Prop name | Prop Type | Description |
| --- | --- |--------------------------------------------------------------------------------------------------------------------------------------------------------|
| animationConfig | BaseAnimation | Object which will contain all optional and non-optional parameters needed to render the animation, including AnimationType, AnimationTriggerType, etc. |
| onAnimationFinish | () => void | (optional) Callback function, if provided will be invoked once animation is finished. |
| onAnimationStart | () => void | (optional) Callback function, if provided will be invoked when the animation is triggered. |
| onAnimationFinish | () => void | (optional) Callback function, if provided will be invoked once animation is finished. |
| onAnimationStart | () => void | (optional) Callback function, if provided will be invoked when the animation is triggered. |
| animationWrapperStyles | StyleProp<ViewStyle> | (optional) Styling, if provided will be applied to the JSON animation element. |
| baseAnimationStyles | StyleProp<ViewStyle> | (optional) Styling, if provided will be applied to the root element. |
## Types of supported Animations
Expand Down
3 changes: 3 additions & 0 deletions src/core/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { RippleAnimationProps } from "./components/wrapper/RippleAnimationWrappe
import { ScaleAnimationProps } from "./components/wrapper/ScaleAnimationWrapper";
import { WiggleAnimationProps } from "./components/wrapper/WiggleAnimationWrapper";
import BaseAnimationConfig from "./data/BaseAnimationConfig";
import { StyleProp, ViewStyle } from "react-native";

/**
* Append the React.ComponentClass<T extends AnimationProps> for each class extending from BaseAnimationWrapper
Expand All @@ -23,6 +24,8 @@ type AnimationWrapperProps = {
animationConfig: BaseAnimationConfig;
onAnimationFinish?: (animationConfig?: BaseAnimationConfig) => void;
onAnimationStart?: (animationConfig?: BaseAnimationConfig) => void;
animationWrapperStyles?: StyleProp<ViewStyle>;
baseAnimationStyles?: StyleProp<ViewStyle>;
}

type SlideAnimationProps = AnimationWrapperProps;
Expand Down
6 changes: 4 additions & 2 deletions src/core/components/AnimationWrapperView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ export default class AnimationWrapperView extends React.Component<AnimationWrapp

public render(): React.ReactNode | undefined {
this._assertChildType();
const { animationConfig, children, onAnimationFinish, onAnimationStart } = this.props;
const { animationConfig, children, onAnimationFinish, onAnimationStart, animationWrapperStyles, baseAnimationStyles } = this.props;
if (this._animationComponentClass && children) {
return (
<this._animationComponentClass
ref={this._setRef}
animationConfig={animationConfig as any}
onAnimationFinish={onAnimationFinish}
onAnimationStart={onAnimationStart}>
onAnimationStart={onAnimationStart}
animationWrapperStyles={animationWrapperStyles}
baseAnimationStyles={baseAnimationStyles}>
{children}
</this._animationComponentClass>
);
Expand Down
4 changes: 2 additions & 2 deletions src/core/components/wrapper/BaseAnimationWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ export abstract class BaseAnimationWrapper<P extends AnimationWrapperProps> exte
const content = this.props.children;
if (this.props.animationConfig?.triggerType === AnimationTriggerType.ON_CLICK) {
return (
<TouchableWithoutFeedback onPress={this._onPress}>
<TouchableWithoutFeedback onPress={this._onPress} style={this.props?.baseAnimationStyles}>
{this.renderAnimation(content)}
</TouchableWithoutFeedback>
);
} else {
return (
<View>
<View style={this.props?.baseAnimationStyles}>
{this.renderAnimation(content)}
</View>
)
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/wrapper/JsonAnimationWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class JsonAnimationWrapper extends BaseAnimationWrapper<JsonAnimationProp
const transformArray = this._getTransformArray();
const animations: ViewStyle[] = this._getViewStyleAnimationArray();
return (
<Animated.View style={[{ transform: transformArray }, animations]}>
<Animated.View style={[{ transform: transformArray }, animations, this.props?.animationWrapperStyles]}>
{content}
</Animated.View>
);
Expand Down

0 comments on commit 27b26aa

Please sign in to comment.