Skip to content

Commit

Permalink
Tidy up with constants and start test writing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonyardley committed Jun 15, 2018
1 parent 162fbe8 commit 02c688f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/constants/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,6 @@ export default {
stageImage: "community"
}
]
}
},
resetAllFilters: "Reset all filters"
};
22 changes: 13 additions & 9 deletions src/screens/EventsScreen/ResetAllFiltersButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from "react";
import { Animated, StyleSheet, Easing } from "react-native";
import type { ViewLayoutEvent } from "react-native/Libraries/Components/View/ViewPropTypes";
import FilterHeaderButton from "./FilterHeaderButton";
import text from "../../constants/text";

type Props = {
visible: boolean,
Expand All @@ -16,6 +17,9 @@ type State = {
const DEFAULT_HEIGHT = 120;
const DEFAULT_FADE_VALUE = 1;
const DEFAULT_TOP_OFFSET_VALUE = 1;
const FADE_ANIMATION_TIME = 200;
const TOP_OFFSET_ANIMATION_TIME = 400;
const TOP_OSSET_ANIMATION_DELAY = 50;

class ResetAllFiltersButton extends React.Component<Props, State> {
constructor(props: Props) {
Expand All @@ -30,28 +34,28 @@ class ResetAllFiltersButton extends React.Component<Props, State> {
this.height = height;
};

fadeOut(): void {
fadeOut = (): void => {
this.props.onPress();
this.setState({ isAnimating: true });

Animated.parallel([
Animated.timing(this.fadeValue, {
toValue: 0,
duration: 200
duration: FADE_ANIMATION_TIME
}),
Animated.timing(this.topOffset, {
toValue: -this.height,
duration: 400,
duration: TOP_OFFSET_ANIMATION_TIME,
easing: Easing.out(Easing.quad),
delay: 50
delay: TOP_OSSET_ANIMATION_DELAY
})
]).start(this.animationFinished);
}
};

reset(): void {
reset = (): void => {
this.topOffset = new Animated.Value(DEFAULT_TOP_OFFSET_VALUE);
this.fadeValue = new Animated.Value(DEFAULT_FADE_VALUE);
}
};

animationFinished = (): void => {
this.setState({ isAnimating: false });
Expand All @@ -75,8 +79,8 @@ class ResetAllFiltersButton extends React.Component<Props, State> {
>
<FilterHeaderButton
active={false}
text="Reset all filters"
label="Reset all filters"
text={text.resetAllFilters}
label={text.resetAllFilters}
style={styles.clearAll}
onPress={() => this.fadeOut()}
/>
Expand Down
9 changes: 9 additions & 0 deletions src/screens/EventsScreen/ResetAllFiltersButton.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @flow
import React from "react";
import { shallow } from "enzyme";
import ResetAllFiltersButton from "./ResetAllFiltersButton";

it("renders correctly", () => {
const output = shallow(<ResetAllFiltersButton visible onPress={() => {}} />);
expect(output).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly 1`] = `
<AnimatedComponent
onLayout={[Function]}
style={
Array [
Object {
"flexDirection": "row",
"justifyContent": "flex-end",
},
Object {
"marginTop": 1,
"opacity": 1,
},
]
}
>
<FilterHeaderButton
active={false}
badgeValue={null}
label="Reset all filters"
onPress={[Function]}
style={
Object {
"minHeight": 0,
"paddingTop": 16,
}
}
text="Reset all filters"
/>
</AnimatedComponent>
`;

0 comments on commit 02c688f

Please sign in to comment.