Live video on the AT Protocol

Merge pull request #529 from streamplace/natb/scroll-down-kb-dismiss

chat: scroll up to dismiss keyboard

authored by natalie and committed by GitHub 6a896251 303866b3

+23 -7
+4 -6
js/app/components/mobile/chat.tsx
··· 10 10 } from "@streamplace/components"; 11 11 import { useKeyboard } from "hooks/useKeyboard"; 12 12 import { useEffect } from "react"; 13 - import { Keyboard, Pressable, TouchableWithoutFeedback } from "react-native"; 13 + import { Pressable } from "react-native"; 14 14 import Animated, { 15 15 useAnimatedStyle, 16 16 useSharedValue, ··· 111 111 { width: "100%", maxWidth: "100%" }, 112 112 ]} 113 113 > 114 - <TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}> 115 - <View style={[flex.values[1]]}> 116 - <Chat canModerate={canModerate} /> 117 - </View> 118 - </TouchableWithoutFeedback> 114 + <View style={[flex.values[1]]}> 115 + <Chat canModerate={canModerate} /> 116 + </View> 119 117 <View style={[layout.flex.column, gap.all[2], px[4]]}> 120 118 {handle ? ( 121 119 <ChatBox
+19 -1
js/components/src/components/chat/chat.tsx
··· 1 1 import { Ellipsis, Reply } from "lucide-react-native"; 2 2 import { ComponentProps, memo, useEffect, useRef, useState } from "react"; 3 - import { Platform, Pressable } from "react-native"; 3 + import { Keyboard, Platform, Pressable } from "react-native"; 4 4 import { FlatList } from "react-native-gesture-handler"; 5 5 import Swipeable, { 6 6 SwipeableMethods, ··· 256 256 canModerate?: boolean; 257 257 }) { 258 258 const chat = useChat(); 259 + const [isScrolledUp, setIsScrolledUp] = useState(false); 260 + 261 + const handleScroll = (event: any) => { 262 + const { contentOffset } = event.nativeEvent; 263 + 264 + const scrolledUp = contentOffset.y > 20; // threshold 265 + 266 + if (scrolledUp !== isScrolledUp) { 267 + setIsScrolledUp(scrolledUp); 268 + 269 + // Dismiss keyboard when scrolled up 270 + if (scrolledUp && Platform.OS !== "web") { 271 + Keyboard.dismiss(); 272 + } 273 + } 274 + }; 259 275 260 276 if (!chat) 261 277 return ( ··· 286 302 maxToRenderPerBatch={10} 287 303 initialNumToRender={10} 288 304 updateCellsBatchingPeriod={50} 305 + onScroll={handleScroll} 306 + scrollEventThrottle={16} 289 307 /> 290 308 <ModView /> 291 309 </View>