Browse Source

feat(YooForum): support getting more topics in the bottom of topic list

dev 0.0.2a
kdxcxs 4 years ago
parent
commit
d61e064b9b
  1. 14
      src/component/YooForum.js
  2. 35
      src/ui/YooForumUI.js

14
src/component/YooForum.js

@ -15,6 +15,7 @@ export default class YooForum extends Component {
hint: '准备中', hint: '准备中',
topics: [], topics: [],
fetchedListPage: 0, fetchedListPage: 0,
gettingTopicList: false,
}; };
this.initForum = this.initForum.bind(this); this.initForum = this.initForum.bind(this);
this.getTopicList = this.getTopicList.bind(this); this.getTopicList = this.getTopicList.bind(this);
@ -102,7 +103,8 @@ export default class YooForum extends Component {
getTopicList() { getTopicList() {
const page = this.state.fetchedListPage + 1; const page = this.state.fetchedListPage + 1;
this.setState({hint: '获取数据中'}); page === 1 && this.setState({hint: '获取数据中'});
this.setState({gettingTopicList: true});
gbkFetch( gbkFetch(
'GET', 'GET',
`http://eol.ctbu.edu.cn/meol/common/faq/forum.jsp?viewtype=thread&forumid=102211&cateId=0&s_gotopage=${page}`, `http://eol.ctbu.edu.cn/meol/common/faq/forum.jsp?viewtype=thread&forumid=102211&cateId=0&s_gotopage=${page}`,
@ -132,11 +134,19 @@ export default class YooForum extends Component {
topics: [...this.state.topics, ...newTopics], topics: [...this.state.topics, ...newTopics],
hint: '', hint: '',
fetchedListPage: page, fetchedListPage: page,
gettingTopicList: false,
}); });
}); });
} }
render() { render() {
return <YooForumUI topics={this.state.topics} hint={this.state.hint} />; return (
<YooForumUI
topics={this.state.topics}
hint={this.state.hint}
getTopicList={this.getTopicList}
gettingTopicList={this.state.gettingTopicList}
/>
);
} }
} }

35
src/ui/YooForumUI.js

@ -8,6 +8,7 @@ import {
Image, Image,
Animated, Animated,
Dimensions, Dimensions,
Pressable,
} from 'react-native'; } from 'react-native';
import YooForumTopic from '../component/YooForumTopic'; import YooForumTopic from '../component/YooForumTopic';
import YooReply from './YooReply'; import YooReply from './YooReply';
@ -43,6 +44,10 @@ const styles = StyleSheet.create({
indicator: { indicator: {
marginTop: 64, marginTop: 64,
}, },
showMoreText: {
fontSize: 18,
margin: 8,
},
}); });
function ForumTopic(props) { function ForumTopic(props) {
@ -56,6 +61,20 @@ function ForumTopic(props) {
)); ));
} }
function ShowMore(props) {
return (
<Pressable
style={{width: screenWidth, alignItems: 'center'}}
onPress={() => props.getTopicList()}>
{props.gettingTopicList ? (
<Text style={styles.showMoreText}>加载中</Text>
) : (
<Text style={styles.showMoreText}>加载更多</Text>
)}
</Pressable>
);
}
export default class YooForumUI extends Component { export default class YooForumUI extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -145,11 +164,17 @@ export default class YooForumUI extends Component {
this.setState({currentPosition: event.nativeEvent.contentOffset.y}) this.setState({currentPosition: event.nativeEvent.contentOffset.y})
}> }>
{this.props.hint === '' ? ( {this.props.hint === '' ? (
<ForumTopic <View>
topics={this.props.topics} <ForumTopic
showDetail={this.showDetail} topics={this.props.topics}
hideDetail={this.hideDetail} showDetail={this.showDetail}
/> hideDetail={this.hideDetail}
/>
<ShowMore
getTopicList={this.props.getTopicList}
gettingTopicList={this.props.gettingTopicList}
/>
</View>
) : ( ) : (
<View style={styles.hintContainer}> <View style={styles.hintContainer}>
<Image <Image

Loading…
Cancel
Save