Skip to content

[StackAgregator] added onCollapseChanged / onCollapseWillChanged / disablePresses #942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 68 additions & 33 deletions src/components/stackAggregator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,23 @@ export default class StackAggregator extends PureBaseComponent {
/**
* A callback for item press
*/
onItemPress: PropTypes.func
onItemPress: PropTypes.func,
/**
* A callback for collapse state will change (value is future collapsed state)
*/
onCollapseWillChange: PropTypes.func,
/**
* A callback for collapse state change (value is collapsed state)
*/
onCollapseChanged: PropTypes.func,
/**
* A setting that disables pressability on cards
*/
disablePresses: PropTypes.boolean
}

static defaultProps = {
disablePresses: false,
collapsed: true,
itemBorderRadius: 0
}
Expand Down Expand Up @@ -101,55 +114,77 @@ export default class StackAggregator extends PureBaseComponent {
return 1;
}

animate = () => {
this.animateValues();
this.animateCards();
animate = async () => {
return Promise.all([this.animateValues(), this.animateCards()]);
}

animateValues() {
const {collapsed} = this.state;
const newValue = collapsed ? buttonStartValue : 1;

Animated.parallel([
Animated.timing(this.animatedOpacity, {
duration: DURATION,
toValue: Number(newValue),
useNativeDriver: true
}),
Animated.timing(this.animatedScale, {
toValue: Number(newValue),
easing: this.easeOut,
duration: DURATION,
useNativeDriver: true
}),
Animated.timing(this.animatedContentOpacity, {
toValue: Number(collapsed ? 0 : 1),
easing: this.easeOut,
duration: DURATION,
useNativeDriver: true
})
]).start();
return new Promise((resolve) => {
Animated.parallel([
Animated.timing(this.animatedOpacity, {
duration: DURATION,
toValue: Number(newValue),
useNativeDriver: true
}),
Animated.timing(this.animatedScale, {
toValue: Number(newValue),
easing: this.easeOut,
duration: DURATION,
useNativeDriver: true
}),
Animated.timing(this.animatedContentOpacity, {
toValue: Number(collapsed ? 0 : 1),
easing: this.easeOut,
duration: DURATION,
useNativeDriver: true
})
]).start(resolve);
});
}

animateCards() {
const promises = [];
for (let index = 0; index < this.itemsCount; index++) {
const newScale = this.getItemScale(index);

Animated.timing(this.animatedScaleArray[index], {
toValue: Number(newScale),
easing: this.easeOut,
duration: DURATION,
useNativeDriver: true
}).start();
promises.push(
new Promise((resolve) => {
Animated.timing(this.animatedScaleArray[index], {
toValue: Number(newScale),
easing: this.easeOut,
duration: DURATION,
useNativeDriver: true
}).start(resolve);
})
);
}
return Promise.all(promises);
}

close = () => {
this.setState({collapsed: true}, () => this.animate());
this.setState({collapsed: true}, async () => {
_.invoke(this.props, 'onCollapseWillChange', true);
if (this.props.onCollapseChanged) {
await this.animate();
this.props.onCollapseChanged(true);
} else {
this.animate();
}
});
}

open = () => {
this.setState({collapsed: false}, () => this.animate());
this.setState({collapsed: false}, async () => {
_.invoke(this.props, 'onCollapseWillChange', false);
if (this.props.onCollapseChanged) {
await this.animate();
this.props.onCollapseChanged(false);
} else {
this.animate();
}
});
}

getTop(index) {
Expand Down Expand Up @@ -219,7 +254,7 @@ export default class StackAggregator extends PureBaseComponent {
>
<Card
style={[contentContainerStyle, this.styles.card]}
onPress={() => this.onItemPress(index)}
onPress={this.props.disablePresses ? false : () => this.onItemPress(index)}
borderRadius={itemBorderRadius}
elevation={5}
>
Expand Down
5 changes: 1 addition & 4 deletions src/components/tagsInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,7 @@ export default class TagsInput extends BaseComponent {

if (tag.invalid) {
return (
<View
key={index}
style={[styles.inValidTag, tagStyle, shouldMarkTag && styles.inValidMarkedTag]}
>
<View key={index} style={[styles.inValidTag, tagStyle, shouldMarkTag && styles.inValidMarkedTag]}>
{this.renderLabel(tag, shouldMarkTag)}
</View>
);
Expand Down
3 changes: 3 additions & 0 deletions typings/components/StackAggregator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import {ButtonProps} from './Button';

export interface StackAggregatorProps {
collapsed?: boolean;
disablePresses?: boolean;
containerStyle?: StyleProp<ViewStyle>;
contentContainerStyle?: StyleProp<ViewStyle>;
itemBorderRadius?: number;
buttonProps?: ButtonProps;
onItemPress?: (index: number) => void;
onCollapseWillChange?: (future: boolean) => void;
onCollapseChanged?: (collapsed: boolean) => void;
}

export class StackAggregator extends PureBaseComponent<StackAggregatorProps> {}