Browse Source

refactor: pass `this` to YooForumUI when YooForumTopicUI is clicked

As feature is growing fast, it needs to pass to many args, so i decide to pass this instead.
dev
kdxcxs 4 years ago
parent
commit
09c29e1ba5
  1. 10
      src/ui/YooForumTopicUI.js
  2. 35
      src/ui/YooForumUI.js

10
src/ui/YooForumTopicUI.js

@ -46,15 +46,9 @@ export default class YooForumTopicUI extends Component {
onPress() { onPress() {
if (!this.state.detailShowing) { if (!this.state.detailShowing) {
this.props.showDetail( this.props.showDetail(this);
this.state.translate,
this.state.layoutY,
this.onAnimationFinished,
this.props.replies,
this.state.layoutHeight,
);
} else { } else {
this.props.hideDetail(this.state.translate, this.onAnimationFinished); this.props.hideDetail();
} }
} }

35
src/ui/YooForumUI.js

@ -88,22 +88,29 @@ export default class YooForumUI extends Component {
this.replyRef = createRef(); this.replyRef = createRef();
this.showDetail = this.showDetail.bind(this); this.showDetail = this.showDetail.bind(this);
this.hideDetail = this.hideDetail.bind(this); this.hideDetail = this.hideDetail.bind(this);
this.currentForumTopicUI = null;
} }
showDetail(translate, layoutY, onAnimationFinished, replies, layoutHeight) { showDetail(ForumTopicUI) {
this.currentForumTopicUI = ForumTopicUI;
this.replyRef.current.scrollTo({x: 0, y: 0, animated: false}); this.replyRef.current.scrollTo({x: 0, y: 0, animated: false});
this.setState({ this.setState({
scrollEnabled: false, scrollEnabled: false,
currentReplies: replies, currentReplies: this.currentForumTopicUI.props.replies,
}); });
this.state.replyTranslateY.setValue( this.state.replyTranslateY.setValue(
this.state.currentPosition + layoutHeight + screenHeight, this.state.currentPosition +
this.currentForumTopicUI.state.layoutHeight +
screenHeight,
); );
Animated.parallel([ Animated.parallel([
Animated.timing(translate, { Animated.timing(this.currentForumTopicUI.state.translate, {
toValue: { toValue: {
x: screenWidth, x: screenWidth,
y: this.state.currentPosition - layoutY + 8, y:
this.state.currentPosition -
this.currentForumTopicUI.state.layoutY +
8,
}, },
duration: 250, duration: 250,
useNativeDriver: true, useNativeDriver: true,
@ -114,18 +121,21 @@ export default class YooForumUI extends Component {
useNativeDriver: true, useNativeDriver: true,
}), }),
Animated.timing(this.state.replyTranslateY, { Animated.timing(this.state.replyTranslateY, {
toValue: this.state.currentPosition + layoutHeight + 8, toValue:
this.state.currentPosition +
this.currentForumTopicUI.state.layoutHeight +
8,
duration: 250, duration: 250,
delay: 250, delay: 250,
useNativeDriver: true, useNativeDriver: true,
}), }),
]).start(onAnimationFinished); ]).start(this.currentForumTopicUI.onAnimationFinished);
} }
hideDetail(translate, onAnimationFinished) { hideDetail() {
this.setState({scrollEnabled: true}); this.setState({scrollEnabled: true});
Animated.parallel([ Animated.parallel([
Animated.timing(translate, { Animated.timing(this.currentForumTopicUI.state.translate, {
toValue: { toValue: {
x: 0, x: 0,
y: 0, y: 0,
@ -143,7 +153,12 @@ export default class YooForumUI extends Component {
duration: 250, duration: 250,
useNativeDriver: true, useNativeDriver: true,
}), }),
]).start(onAnimationFinished); ]).start(
function () {
this.currentForumTopicUI.onAnimationFinished();
this.currentForumTopicUI = null;
}.bind(this),
);
} }
render() { render() {

Loading…
Cancel
Save