feat: Add sort button to toggle message order in chat
Add a sort button in the chat header that toggles between oldest-first (default) and newest-first message ordering. The arrow icon indicates the current sort direction. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
5724e7ab76
commit
664759dee9
@ -408,6 +408,7 @@ export default function ChatScreen() {
|
|||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
const [sortNewestFirst, setSortNewestFirst] = useState(false);
|
||||||
|
|
||||||
// Voice call state (local connecting state only)
|
// Voice call state (local connecting state only)
|
||||||
const [isConnectingVoice, setIsConnectingVoice] = useState(false);
|
const [isConnectingVoice, setIsConnectingVoice] = useState(false);
|
||||||
@ -765,7 +766,17 @@ export default function ChatScreen() {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
style={styles.eraseButton}
|
style={styles.headerButton}
|
||||||
|
onPress={() => setSortNewestFirst(prev => !prev)}
|
||||||
|
>
|
||||||
|
<Ionicons
|
||||||
|
name={sortNewestFirst ? 'arrow-up' : 'arrow-down'}
|
||||||
|
size={22}
|
||||||
|
color={AppColors.textSecondary}
|
||||||
|
/>
|
||||||
|
</TouchableOpacity>
|
||||||
|
<TouchableOpacity
|
||||||
|
style={styles.headerButton}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
Alert.alert(
|
Alert.alert(
|
||||||
'Clear Chat',
|
'Clear Chat',
|
||||||
@ -857,12 +868,16 @@ export default function ChatScreen() {
|
|||||||
>
|
>
|
||||||
<FlatList
|
<FlatList
|
||||||
ref={flatListRef}
|
ref={flatListRef}
|
||||||
data={messages}
|
data={sortNewestFirst ? [...messages].reverse() : messages}
|
||||||
keyExtractor={(item) => item.id}
|
keyExtractor={(item) => item.id}
|
||||||
renderItem={renderMessage}
|
renderItem={renderMessage}
|
||||||
contentContainerStyle={styles.messagesList}
|
contentContainerStyle={styles.messagesList}
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
onContentSizeChange={() => flatListRef.current?.scrollToEnd({ animated: true })}
|
onContentSizeChange={() => {
|
||||||
|
if (!sortNewestFirst) {
|
||||||
|
flatListRef.current?.scrollToEnd({ animated: true });
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Input */}
|
{/* Input */}
|
||||||
@ -999,8 +1014,9 @@ const styles = StyleSheet.create({
|
|||||||
fontSize: FontSizes.sm,
|
fontSize: FontSizes.sm,
|
||||||
color: AppColors.success,
|
color: AppColors.success,
|
||||||
},
|
},
|
||||||
eraseButton: {
|
headerButton: {
|
||||||
padding: Spacing.xs,
|
padding: Spacing.xs,
|
||||||
|
marginLeft: Spacing.sm,
|
||||||
},
|
},
|
||||||
chatContainer: {
|
chatContainer: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user