From 154491bc3a618332d8f2255a291cd3222ee239d1 Mon Sep 17 00:00:00 2001 From: Linus109 Date: Tue, 25 Nov 2025 20:52:53 +0100 Subject: [PATCH] chat (wip) --- app/Chat.tsx | 350 ++++++++++++++++++++++++++++++++++++++++++++++++ app/Themes.tsx | 18 +++ app/_layout.tsx | 2 +- app/index.tsx | 4 +- 4 files changed, 371 insertions(+), 3 deletions(-) create mode 100644 app/Chat.tsx create mode 100644 app/Themes.tsx diff --git a/app/Chat.tsx b/app/Chat.tsx new file mode 100644 index 0000000..376a285 --- /dev/null +++ b/app/Chat.tsx @@ -0,0 +1,350 @@ +import { View, Text, FlatList, TextInput } from "react-native"; +import currentTheme from "./Themes"; +import { useState } from "react"; + +// TODO: better shadows for everything + +type BubbleSide = "left" | "right"; +type ChatMessageProps = { + side: BubbleSide; + width: number; + height: number; +}; + +type messageData = { + id: string; + side: BubbleSide; + width: number; + height: number; +}; + +// NOTE: only for testing +const getRandomInt = (min: number, max: number) => { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min + 1)) + min; +}; + +const randomWidth = () => getRandomInt(100, 400); +const randomHeight = () => getRandomInt(50, 100); + +const messages: messageData[] = [ + // {{{ + { + id: "1", + side: "left", + width: randomWidth(), + height: randomHeight(), + }, + { + id: "2", + side: "right", + width: randomWidth(), + height: randomHeight(), + }, + { + id: "3", + side: "left", + width: randomWidth(), + height: randomHeight(), + }, + { + id: "4", + side: "right", + width: randomWidth(), + height: randomHeight(), + }, + { + id: "5", + side: "left", + width: randomWidth(), + height: randomHeight(), + }, + { + id: "6", + side: "right", + width: randomWidth(), + height: randomHeight(), + }, + { + id: "7", + side: "left", + width: randomWidth(), + height: randomHeight(), + }, + { + id: "8", + side: "right", + width: randomWidth(), + height: randomHeight(), + }, + { + id: "9", + side: "left", + width: randomWidth(), + height: randomHeight(), + }, + { + id: "10", + side: "right", + width: randomWidth(), + height: randomHeight(), + }, + // { + // id: "11", + // side: "left", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "12", + // side: "right", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "13", + // side: "left", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "14", + // side: "right", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "15", + // side: "left", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "16", + // side: "right", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "17", + // side: "left", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "18", + // side: "right", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "19", + // side: "left", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "20", + // side: "right", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "21", + // side: "left", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "22", + // side: "right", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "23", + // side: "left", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "24", + // side: "right", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "25", + // side: "left", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "26", + // side: "right", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "27", + // side: "left", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "28", + // side: "right", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "29", + // side: "left", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "30", + // side: "right", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "31", + // side: "left", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "32", + // side: "right", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "33", + // side: "left", + // width: randomWidth(), + // height: randomHeight(), + // }, + // { + // id: "34", + // side: "right", + // width: randomWidth(), + // height: randomHeight(), + // }, + //, width: randomWidth, height: getRandomInt(50, 500) }}} +]; + +const Chat = () => { + return ( + + + + ( + + )} + keyExtractor={(item) => item.id} + // extraData={selectedId} might need this later for re-rendering + /> + + + ); +}; + +const ChatHeader = () => { + return ( + + + CalChat + + ); +}; + +const ChatInput = () => { + const [text, onChangeText] = useState("Nachricht"); + + return ( + + + + + ); +}; + +const ChatMessage = (props: ChatMessageProps) => { + const borderColor = + props.side === "left" ? currentTheme.chatBot : currentTheme.primeFg; + const selfSide = + props.side === "left" + ? "self-start ml-2 rounded-bl-sm" + : "self-end mr-2 rounded-br-sm"; + + return ( + + Lorem Ipsum Dolor sit amet + + ); +}; + +export default Chat; diff --git a/app/Themes.tsx b/app/Themes.tsx new file mode 100644 index 0000000..501fb4f --- /dev/null +++ b/app/Themes.tsx @@ -0,0 +1,18 @@ +type Theme = { + chatBot: string, + primeFg: string, + primeBg: string, + messageBorderBg: string, + placeholderBg: string, +} + +const defaultLight: Theme = { + chatBot: "#DE6C20", + primeFg: "#3B3329", + primeBg: "#FFEEDE", + messageBorderBg: "#FFFFFF", + placeholderBg: "#D9D9D9" +} + +let currentTheme: Theme = defaultLight; +export default currentTheme; diff --git a/app/_layout.tsx b/app/_layout.tsx index f4da9a1..ee0e86e 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -2,5 +2,5 @@ import { Stack } from "expo-router"; import "../global.css"; export default function RootLayout() { - return ; + return ; } diff --git a/app/index.tsx b/app/index.tsx index b11933d..67a3cf9 100644 --- a/app/index.tsx +++ b/app/index.tsx @@ -1,8 +1,8 @@ import React from "react"; -import ManyHelloes from "./Hello_World"; +import Chat from "./Chat"; export default function Index() { return ( - + ); }