Skip to content

Commit 1b9118e

Browse files
committed
hooks重写搜索页面
1 parent 19f3a85 commit 1b9118e

File tree

5 files changed

+84
-58
lines changed

5 files changed

+84
-58
lines changed

declare.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
declare module '*.png';
22
declare module 'react-native-refresh-list-view';
3+
declare module 'react-native-animated-header';
34
declare module 'react-native-share';
45
declare module 'react-native-masonry-list';
56
declare module 'dva-model-extend' {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"moment": "^2.29.1",
2929
"react": "16.13.1",
3030
"react-native": "0.63.3",
31+
"react-native-animated-header": "^1.0.7",
3132
"react-native-config": "^1.4.1",
3233
"react-native-fast-image": "^8.3.4",
3334
"react-native-gesture-handler": "^1.9.0",

ts/page/discover/CategoryDetailPage.tsx

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import React, {useEffect} from 'react';
22
import {shallowEqual, useDispatch, useSelector} from 'react-redux';
33
import RefreshListView, {RefreshState} from 'react-native-refresh-list-view';
4+
import AnimatedHeader from 'react-native-animated-header';
45
import {RootState} from '@/model/dva/Models';
56
import {ListRenderItemInfo, StyleSheet, View} from 'react-native';
67
import {RouteProp} from '@react-navigation/native';
78
import {RootNavigation, RootStackParamList} from '@/navigator/Router';
89
import {Item} from '@/model/Daily';
910
import ImageTextItem from '@/components/ImageTextItem';
11+
import FastImage from 'react-native-fast-image';
12+
import {ScreenWidth} from '@/utils/Utils';
1013

1114
const CLEAR_TYPE = 'categoryDetail/setState';
1215
const REFRESH_TYPE = 'categoryDetail/onRefresh';
@@ -60,15 +63,6 @@ function CategoryDetailPage(props: IProps) {
6063
};
6164
}, [dispatch]);
6265

63-
const onHeaderRefresh = () => {
64-
dispatch({
65-
type: REFRESH_TYPE,
66-
payload: {
67-
id: props.route.params.item.id,
68-
},
69-
});
70-
};
71-
7266
const onFooterRefresh = () => {
7367
if (nextPageUrl == null) {
7468
return;
@@ -90,24 +84,46 @@ function CategoryDetailPage(props: IProps) {
9084
};
9185

9286
return (
93-
<View style={styles.container}>
87+
<AnimatedHeader
88+
style={styles.container}
89+
title="Happy coding"
90+
backStyle={{marginLeft: 10}}
91+
backTextStyle={{fontSize: 14, color: '#000'}}
92+
titleStyle={{fontSize: 22, left: 20, bottom: 20, color: '#000'}}
93+
headerMaxHeight={200}
94+
imageSource={() => (
95+
<FastImage
96+
style={styles.headImage}
97+
source={{
98+
uri:
99+
'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201804%2F28%2F20180428114906_ulvqd.jpg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633255088&t=5de32951b8196587f44772fc590a6456',
100+
}}
101+
/>
102+
)}
103+
toolbarColor="#FFF"
104+
disabled={false}>
94105
<RefreshListView
95106
data={dataList}
96107
renderItem={renderItem}
97108
keyExtractor={keyExtractor}
98109
refreshState={refreshState}
99-
onHeaderRefresh={onHeaderRefresh}
100110
onFooterRefresh={onFooterRefresh}
101111
showsVerticalScrollIndicator={false}
102112
/>
103-
</View>
113+
</AnimatedHeader>
104114
);
105115
}
106116

107117
const styles = StyleSheet.create({
108118
container: {
119+
flex: 1,
109120
backgroundColor: '#fff',
110121
},
122+
headImage: {
123+
width: ScreenWidth,
124+
height: 200,
125+
borderRadius: 4,
126+
},
111127
});
112128

113129
export default CategoryDetailPage;

ts/page/search/SearchPage.tsx

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,17 @@ function SearchPage() {
5454
const keyword = useRef('');
5555

5656
const dispatch = useDispatch();
57-
const {
58-
showLoading,
59-
showKeyWorkContainer,
60-
keyWordList,
61-
dataList,
62-
refreshState,
63-
nextPageUrl,
64-
total,
65-
} = useSelector(mapStateToProps, shallowEqual);
57+
58+
const {showLoading} = useSelector(mapStateToProps, shallowEqual);
59+
60+
const {showKeyWorkContainer} = useSelector(mapStateToProps, shallowEqual);
61+
62+
const {keyWordList} = useSelector(mapStateToProps, shallowEqual);
63+
64+
const {dataList, refreshState, nextPageUrl, total} = useSelector(
65+
mapStateToProps,
66+
shallowEqual,
67+
);
6668

6769
useEffect(() => {
6870
dispatch({
@@ -141,42 +143,6 @@ function SearchPage() {
141143
return <SearchVideoComponent item={item} />;
142144
};
143145

144-
const ContentContainer = () => {
145-
if (showLoading) {
146-
return (
147-
<Spinner
148-
visible={showLoading}
149-
textContent={'Loading...'}
150-
textStyle={styles.spinnerTextStyle}
151-
/>
152-
);
153-
}
154-
if (dataList == null || dataList.length === 0) {
155-
return <KeyWordContainerOrEmpty />;
156-
}
157-
return (
158-
<View style={styles.searchVideoContainer}>
159-
<Text style={styles.searchKey}>
160-
— 「{keyword.current}」搜索结果共{total}个 —
161-
</Text>
162-
<RefreshListView
163-
data={dataList}
164-
keyExtractor={keyExtractor}
165-
renderItem={renderItem}
166-
refreshState={refreshState}
167-
onHeaderRefresh={onHeaderRefresh}
168-
onFooterRefresh={onFooterRefresh}
169-
showsVerticalScrollIndicator={false}
170-
getItemLayout={(_data: Item, index: number) => ({
171-
length: FeedHeight,
172-
offset: FeedHeight * index,
173-
index,
174-
})}
175-
/>
176-
</View>
177-
);
178-
};
179-
180146
const KeyWordContainerOrEmpty = () => {
181147
if (showKeyWorkContainer) {
182148
return (
@@ -247,7 +213,44 @@ function SearchPage() {
247213
</View>
248214
<SearchView />
249215
</View>
250-
<ContentContainer />
216+
{showLoading && (
217+
<>
218+
<Spinner
219+
visible={showLoading}
220+
textContent={'Loading...'}
221+
textStyle={styles.spinnerTextStyle}
222+
/>
223+
</>
224+
)}
225+
{dataList == null ||
226+
(dataList.length === 0 && (
227+
<>
228+
<KeyWordContainerOrEmpty />
229+
</>
230+
))}
231+
{total > 0 && (
232+
<>
233+
<View style={styles.searchVideoContainer}>
234+
<Text style={styles.searchKey}>
235+
— 「{keyword.current}」搜索结果共{total}个 —
236+
</Text>
237+
<RefreshListView
238+
data={dataList}
239+
keyExtractor={keyExtractor}
240+
renderItem={renderItem}
241+
refreshState={refreshState}
242+
onHeaderRefresh={onHeaderRefresh}
243+
onFooterRefresh={onFooterRefresh}
244+
showsVerticalScrollIndicator={false}
245+
getItemLayout={(_data: Item, index: number) => ({
246+
length: FeedHeight,
247+
offset: FeedHeight * index,
248+
index,
249+
})}
250+
/>
251+
</View>
252+
</>
253+
)}
251254
</SafeAreaView>
252255
);
253256
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6090,6 +6090,11 @@ react-is@^16.12.0, react-is@^16.13.0, react-is@^16.13.1, react-is@^16.7.0, react
60906090
resolved "https://registry.npm.taobao.org/react-is/download/react-is-16.13.1.tgz?cache=0&sync_timestamp=1608330338071&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Freact-is%2Fdownload%2Freact-is-16.13.1.tgz"
60916091
integrity sha1-eJcppNw23imZ3BVt1sHZwYzqVqQ=
60926092

6093+
react-native-animated-header@^1.0.7:
6094+
version "1.0.7"
6095+
resolved "https://registry.nlark.com/react-native-animated-header/download/react-native-animated-header-1.0.7.tgz#df9793e60b86e9106b31dcb1a3f2ef4ac37c0db9"
6096+
integrity sha1-35eT5guG6RBrMdyxo/LvSsN8Dbk=
6097+
60936098
react-native-config@^1.4.1:
60946099
version "1.4.1"
60956100
resolved "https://registry.npm.taobao.org/react-native-config/download/react-native-config-1.4.1.tgz"

0 commit comments

Comments
 (0)