refactor: 移除不必要的布局效果,简化任务列表屏幕的代码结构,同时添加下拉刷新功能的支持
This commit is contained in:
parent
5ef88f533b
commit
3576a82b8a
@ -1,14 +1,7 @@
|
|||||||
import React, { useLayoutEffect, useState, useCallback } from 'react';
|
import React, { useState, useCallback } from 'react';
|
||||||
import {
|
import { View, StyleSheet, FlatList } from 'react-native';
|
||||||
View,
|
|
||||||
StyleSheet,
|
|
||||||
FlatList,
|
|
||||||
TouchableOpacity,
|
|
||||||
ActivityIndicator,
|
|
||||||
} from 'react-native';
|
|
||||||
import { useNavigation } from '@react-navigation/native';
|
import { useNavigation } from '@react-navigation/native';
|
||||||
import { StackNavigationProp } from '@react-navigation/stack';
|
import { StackNavigationProp } from '@react-navigation/stack';
|
||||||
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
|
|
||||||
import { useTasks } from '../context/TasksContext';
|
import { useTasks } from '../context/TasksContext';
|
||||||
import TaskCard from '../components/TaskCard';
|
import TaskCard from '../components/TaskCard';
|
||||||
|
|
||||||
@ -38,20 +31,6 @@ export default function TaskListScreen() {
|
|||||||
}
|
}
|
||||||
}, [refreshTasks]);
|
}, [refreshTasks]);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
|
||||||
navigation.setOptions({
|
|
||||||
headerRight: () => (
|
|
||||||
<TouchableOpacity onPress={handleRefresh} style={{ marginRight: 15 }}>
|
|
||||||
{isRefreshing ? (
|
|
||||||
<ActivityIndicator size="small" color="#ffffff" />
|
|
||||||
) : (
|
|
||||||
<MaterialIcons name="refresh" size={24} color="#ffffff" />
|
|
||||||
)}
|
|
||||||
</TouchableOpacity>
|
|
||||||
),
|
|
||||||
});
|
|
||||||
}, [navigation, isRefreshing, handleRefresh]);
|
|
||||||
|
|
||||||
const handlePressTask = (id: string) => {
|
const handlePressTask = (id: string) => {
|
||||||
navigation.navigate('TaskEdit', { taskId: id });
|
navigation.navigate('TaskEdit', { taskId: id });
|
||||||
};
|
};
|
||||||
@ -67,6 +46,8 @@ export default function TaskListScreen() {
|
|||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
keyExtractor={item => item.id}
|
keyExtractor={item => item.id}
|
||||||
ItemSeparatorComponent={() => <View style={styles.separator} />}
|
ItemSeparatorComponent={() => <View style={styles.separator} />}
|
||||||
|
refreshing={isRefreshing}
|
||||||
|
onRefresh={handleRefresh}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user