Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions app/(app)/server/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Animated, {
import { useKeyboardHandler } from "react-native-keyboard-controller";
import { useBottomTabBarHeight } from "@react-navigation/bottom-tabs";
import { useTranslation } from "react-i18next";
import { FlashList } from "@shopify/flash-list";
import { LegendList } from "@legendapp/list";
import MaterialCommunityIcons from "@expo/vector-icons/MaterialCommunityIcons";
import ConsoleText from "@/components/server/console/ConsoleText";
import TextInput from "@/components/ui/TextInput";
Expand Down Expand Up @@ -77,7 +77,7 @@ export default function ConsoleScreen() {
);
const { server } = useServer();
const [lines, setLines] = useState<string[]>([]);
const { listRef, isAtBottom, listMounted, handleScroll, handleContentSizeChange, goToBottom } = useAutoScroll<string>({ data: lines, inverted: true });
const { listRef, isAtBottom, listMounted, handleScroll, handleContentSizeChange, goToBottom } = useAutoScroll<string>({ data: lines, inverted: false });
const chevronVisible = useSharedValue(0);
const [initialScroll, setInitialScroll] = useState(true);
const [hasGotItems, setHasGotItems] = useState(false);
Expand Down Expand Up @@ -155,7 +155,7 @@ export default function ConsoleScreen() {
newLines.pop();
}

setLines((lines) => [...newLines.reverse(), ...lines]);
setLines((lines) => [...lines, ...newLines]);
setHasGotItems(true);
};

Expand All @@ -172,16 +172,20 @@ export default function ConsoleScreen() {
<View style={style.container}>
{server?.hasScope("server.console") && (
<>
<FlashList
<LegendList
ref={listRef}
onScroll={handleScroll}
onContentSizeChange={handleContentSizeChange}
data={lines}
keyExtractor={(_, index) => index.toString()}
renderItem={({ item }) => <ConsoleText text={item} />}
estimatedItemSize={30}
inverted={true}
recycleItems={true}
alignItemsAtEnd={true}
maintainScrollAtEnd={true}
maintainScrollAtEndThreshold={0.1}
showsVerticalScrollIndicator={false}
waitForInitialLayout={true}
/>

<TouchableOpacity style={style.clearConsole} onPress={clearConsole}>
Expand Down
7 changes: 6 additions & 1 deletion bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@formatjs/intl-locale": "^4.2.11",
"@gorhom/bottom-sheet": "^5.1.5",
"@hookform/resolvers": "^5.0.1",
"@legendapp/list": "^1.0.14",
"@react-native-async-storage/async-storage": "2.1.2",
"@react-native-community/slider": "4.5.6",
"@react-native-menu/menu": "^1.2.3",
Expand Down Expand Up @@ -528,6 +529,8 @@

"@jsamr/react-native-li": ["@jsamr/react-native-li@2.3.1", "", { "peerDependencies": { "@jsamr/counter-style": "^1.0.0 || ^2.0.0", "react": "*", "react-native": "*" } }, "sha512-Qbo4NEj48SQ4k8FZJHFE2fgZDKTWaUGmVxcIQh3msg5JezLdTMMHuRRDYctfdHI6L0FZGObmEv3haWbIvmol8w=="],

"@legendapp/list": ["@legendapp/list@1.0.14", "", { "dependencies": { "use-sync-external-store": "^1.5.0" }, "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-/3OWGGFgZWZK8ZvM4bdL18HhkxFEkpC0wEK8hvlLI8IeVxk0z/anKXb5hraijiMwfpDEyD4nDzQQDqtlJ1UVLQ=="],

"@napi-rs/wasm-runtime": ["@napi-rs/wasm-runtime@0.2.9", "", { "dependencies": { "@emnapi/core": "^1.4.0", "@emnapi/runtime": "^1.4.0", "@tybys/wasm-util": "^0.9.0" } }, "sha512-OKRBiajrrxB9ATokgEQoG87Z25c67pCpYcCwmXYX8PBftC9pBfN18gnm/fh1wurSLEKIAt+QRFLFCQISrb66Jg=="],

"@nicolo-ribaudo/chokidar-2": ["@nicolo-ribaudo/chokidar-2@2.1.8-no-fsevents.3", "", {}, "sha512-s88O1aVtXftvp5bCPB7WnmXc5IwOZZ7YPuwNPt+GtOOXpPvad1LfbmjYv+qII7zP6RU2QGnqve27dnLycEnyEQ=="],
Expand Down Expand Up @@ -2358,7 +2361,7 @@

"use-sidecar": ["use-sidecar@1.1.2", "", { "dependencies": { "detect-node-es": "^1.1.0", "tslib": "^2.0.0" }, "peerDependencies": { "@types/react": "^16.9.0 || ^17.0.0 || ^18.0.0", "react": "^16.8.0 || ^17.0.0 || ^18.0.0" }, "optionalPeers": ["@types/react"] }, "sha512-epTbsLuzZ7lPClpz2TyryBfztm7m+28DlEv2ZCQ3MDr5ssiwyOwGH/e5F9CkfWjJ1t4clvI58yF822/GUkjjhw=="],

"use-sync-external-store": ["use-sync-external-store@1.4.0", "", { "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-9WXSPC5fMv61vaupRkCKCxsPxBocVnwakBEkMIHHpkTTg6icbJtg6jzgtLDm4bl3cSHAca52rYWih0k4K3PfHw=="],
"use-sync-external-store": ["use-sync-external-store@1.5.0", "", { "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-Rb46I4cGGVBmjamjphe8L/UnvJD+uPPtTkNvX5mZgqdbavhI4EbgIWJiIHXJ8bc/i9EQGPRh4DwEURJ552Do0A=="],

"utils-merge": ["utils-merge@1.0.1", "", {}, "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA=="],

Expand Down Expand Up @@ -2898,6 +2901,8 @@

"@react-navigation/core/use-latest-callback": ["use-latest-callback@0.2.1", "", { "peerDependencies": { "react": ">=16.8" } }, "sha512-QWlq8Is8BGWBf883QOEQP5HWYX/kMI+JTbJ5rdtvJLmXTIh9XoHIO3PQcmQl8BU44VKxow1kbQUHa6mQSMALDQ=="],

"@react-navigation/core/use-sync-external-store": ["use-sync-external-store@1.4.0", "", { "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-9WXSPC5fMv61vaupRkCKCxsPxBocVnwakBEkMIHHpkTTg6icbJtg6jzgtLDm4bl3cSHAca52rYWih0k4K3PfHw=="],

"@react-navigation/native/nanoid": ["nanoid@3.3.8", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w=="],

"@react-navigation/native/use-latest-callback": ["use-latest-callback@0.2.1", "", { "peerDependencies": { "react": ">=16.8" } }, "sha512-QWlq8Is8BGWBf883QOEQP5HWYX/kMI+JTbJ5rdtvJLmXTIh9XoHIO3PQcmQl8BU44VKxow1kbQUHa6mQSMALDQ=="],
Expand Down
16 changes: 4 additions & 12 deletions hooks/useAutoScroll.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { useRef, useState, useEffect } from "react";
import { NativeScrollEvent, NativeSyntheticEvent } from "react-native";
import { FlashList } from "@shopify/flash-list";
import { LegendListRef } from "@legendapp/list";

type AutoScrollHookProps<T> = {
data: T[];
inverted?: boolean;
};

export default function useAutoScroll<T>({ data, inverted }: AutoScrollHookProps<T>) {
const listRef = useRef<FlashList<T>>(null);
const listRef = useRef<LegendListRef>(null);
const [isAtBottom, setIsAtBottom] = useState(true);
const [listMounted, setListMounted] = useState(false);

Expand All @@ -18,15 +17,8 @@ export default function useAutoScroll<T>({ data, inverted }: AutoScrollHookProps
}
}, [data, listMounted, isAtBottom]);

const handleScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
const { layoutMeasurement, contentOffset, contentSize } = event.nativeEvent;
const paddingToBottom = 20;

if (inverted) {
setIsAtBottom(contentOffset.y <= paddingToBottom);
} else {
setIsAtBottom(layoutMeasurement.height + contentOffset.y >= contentSize.height - paddingToBottom);
}
const handleScroll = () => {
setIsAtBottom(listRef.current?.getState().isAtEnd || false);
};

const handleContentSizeChange = () => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@formatjs/intl-locale": "^4.2.11",
"@gorhom/bottom-sheet": "^5.1.5",
"@hookform/resolvers": "^5.0.1",
"@legendapp/list": "^1.0.14",
"@react-native-async-storage/async-storage": "2.1.2",
"@react-native-community/slider": "4.5.6",
"@react-native-menu/menu": "^1.2.3",
Expand Down
Loading