Skip to content

Commit

Permalink
feat(Logcat): 添加FAB按钮以滚动日志列表到末尾
Browse files Browse the repository at this point in the history
  • Loading branch information
thoulee21 committed Jan 8, 2025
1 parent f7cbf0f commit f011572
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/pages/logcat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, {
useEffect,
useLayoutEffect,
useMemo,
useRef,
useState
} from 'react';
import {
Expand All @@ -24,6 +25,7 @@ import {
Button,
Caption,
Dialog,
FAB,
IconButton,
Portal,
Text,
Expand All @@ -35,6 +37,7 @@ import { logFilePath, rootLog } from '../utils/logger';

export const Logcat = () => {
const navigation = useNavigation();
const logsRef = useRef<Animated.FlatList>(null);
const appTheme = useTheme();

const [isLoaded, setIsLoaded] = useState(false);
Expand Down Expand Up @@ -150,8 +153,8 @@ export const Logcat = () => {
return (
<>
<Animated.FlatList
ref={logsRef}
data={logLines}
inverted
style={styles.root}
contentContainerStyle={styles.content}
renderItem={renderLogLine}
Expand All @@ -170,6 +173,18 @@ export const Logcat = () => {
persistentScrollbar
/>

<Portal>
<FAB
icon="arrow-down"
style={styles.fab}
onPress={() => {
if (logsRef.current) {
logsRef.current.scrollToEnd();
}
}}
/>
</Portal>

<Portal>
<Dialog
visible={dialogVisible}
Expand Down Expand Up @@ -218,5 +233,11 @@ const styles = StyleSheet.create({
},
row: {
flexDirection: 'row',
},
fab: {
position: 'absolute',
margin: 16,
right: 0,
bottom: 0
}
});

0 comments on commit f011572

Please sign in to comment.