Browse Source

refactor: pass specific variables instead of `this` to YooForumUI, toggle `detailShowing` state as a callback of animation

pull/1/head
kdxcxs 4 years ago
parent
commit
14bf63f35b
  1. 15
      src/ui/YooForumTopicUI.js
  2. 14
      src/ui/YooForumUI.js

15
src/ui/YooForumTopicUI.js

@ -36,15 +36,22 @@ export default class YooForumTopicUI extends Component {
}; };
this.topicHeaderRef = createRef(); this.topicHeaderRef = createRef();
this.onPress = this.onPress.bind(this); this.onPress = this.onPress.bind(this);
this.onAnimationFinished = this.onAnimationFinished.bind(this);
}
onAnimationFinished() {
this.setState({detailShowing: !this.state.detailShowing});
} }
onPress() { onPress() {
if (!this.state.detailShowing) { if (!this.state.detailShowing) {
this.setState({detailShowing: true}); this.props.showDetail(
this.props.showDetail(this); this.state.translate,
this.state.layoutY,
this.onAnimationFinished,
);
} else { } else {
this.setState({detailShowing: false}); this.props.hideDetail(this.state.translate, this.onAnimationFinished);
this.props.hideDetail(this);
} }
} }

14
src/ui/YooForumUI.js

@ -49,13 +49,13 @@ export default class YooForumUI extends Component {
this.hideDetail = this.hideDetail.bind(this); this.hideDetail = this.hideDetail.bind(this);
} }
showDetail(topicRef) { showDetail(translate, layoutY, onAnimationFinished) {
this.setState({scrollEnabled: false}); this.setState({scrollEnabled: false});
Animated.parallel([ Animated.parallel([
Animated.timing(topicRef.state.translate, { Animated.timing(translate, {
toValue: { toValue: {
x: screenWidth, x: screenWidth,
y: this.state.currentPosition - topicRef.state.layoutY + 8, y: this.state.currentPosition - layoutY + 8,
}, },
duration: 250, duration: 250,
useNativeDriver: true, useNativeDriver: true,
@ -65,13 +65,13 @@ export default class YooForumUI extends Component {
duration: 250, duration: 250,
useNativeDriver: true, useNativeDriver: true,
}), }),
]).start(); ]).start(onAnimationFinished);
} }
hideDetail(topicRef) { hideDetail(translate, onAnimationFinished) {
this.setState({scrollEnabled: true}); this.setState({scrollEnabled: true});
Animated.parallel([ Animated.parallel([
Animated.timing(topicRef.state.translate, { Animated.timing(translate, {
toValue: { toValue: {
x: 0, x: 0,
y: 0, y: 0,
@ -84,7 +84,7 @@ export default class YooForumUI extends Component {
duration: 250, duration: 250,
useNativeDriver: true, useNativeDriver: true,
}), }),
]).start(); ]).start(onAnimationFinished);
} }
render() { render() {

Loading…
Cancel
Save