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(),
|
||||
},
|
||||
]);
|
||||
const [sortNewestFirst, setSortNewestFirst] = useState(false);
|
||||
|
||||
// Voice call state (local connecting state only)
|
||||
const [isConnectingVoice, setIsConnectingVoice] = useState(false);
|
||||
@ -765,7 +766,17 @@ export default function ChatScreen() {
|
||||
</View>
|
||||
</View>
|
||||
<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={() => {
|
||||
Alert.alert(
|
||||
'Clear Chat',
|
||||
@ -857,12 +868,16 @@ export default function ChatScreen() {
|
||||
>
|
||||
<FlatList
|
||||
ref={flatListRef}
|
||||
data={messages}
|
||||
data={sortNewestFirst ? [...messages].reverse() : messages}
|
||||
keyExtractor={(item) => item.id}
|
||||
renderItem={renderMessage}
|
||||
contentContainerStyle={styles.messagesList}
|
||||
showsVerticalScrollIndicator={false}
|
||||
onContentSizeChange={() => flatListRef.current?.scrollToEnd({ animated: true })}
|
||||
onContentSizeChange={() => {
|
||||
if (!sortNewestFirst) {
|
||||
flatListRef.current?.scrollToEnd({ animated: true });
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Input */}
|
||||
@ -999,8 +1014,9 @@ const styles = StyleSheet.create({
|
||||
fontSize: FontSizes.sm,
|
||||
color: AppColors.success,
|
||||
},
|
||||
eraseButton: {
|
||||
headerButton: {
|
||||
padding: Spacing.xs,
|
||||
marginLeft: Spacing.sm,
|
||||
},
|
||||
chatContainer: {
|
||||
flex: 1,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user