import React, { useEffect, useRef, useState } from "react"; import { StyleSheet, View, TouchableOpacity, ScrollView, Text, } from "react-native"; import RNFS from "react-native-fs"; const DebugLogs = () => { const [files, setFiles] = useState([]); const [file, setFile] = useState(null); const [logs, setLogs] = useState(null); const fileViewRef = useRef(null); useEffect(() => { RNFS.readdir(RNFS.DocumentDirectoryPath + "/logs").then((result) => { if (result) { setFiles(result); } }); }, []); useEffect(() => { if (file) { RNFS.readFile(RNFS.DocumentDirectoryPath + "/logs/" + file, "utf8").then( (result) => { setLogs(result); } ); } }, [file]); return ( fileViewRef.current && fileViewRef.current.scrollToEnd({ animated: true }) } > {files.map((item: string, index: number) => { return ( { setFile(item); }} > - {item} ); })} fileViewRef.current && fileViewRef.current.scrollToEnd({ animated: true }) } > {logs ? {logs} : SELECT LOG FILE...} ); }; const styles = StyleSheet.create({ container: { flex: 1, paddingTop: 10, justifyContent: "center", alignItems: "center", }, title: { marginTop: 10, marginBottom: 10, maxWidth: "50%", }, }); export { DebugLogs };