From a93c69fa7737af814159c5398bbc27695241b425 Mon Sep 17 00:00:00 2001 From: Hailey Date: Sat, 18 May 2024 21:42:28 -0700 Subject: [PATCH] fully implement keyboard controller --- src/App.native.tsx | 116 +++--- .../Messages/Conversation/MessagesList.tsx | 20 +- src/view/com/composer/Composer.tsx | 331 +++++++++--------- 3 files changed, 231 insertions(+), 236 deletions(-) diff --git a/src/App.native.tsx b/src/App.native.tsx index 94c5d7ba56..7c60d1624b 100644 --- a/src/App.native.tsx +++ b/src/App.native.tsx @@ -88,43 +88,41 @@ function InnerApp() { return ( - - - - - - - - - - {/* LabelDefsProvider MUST come before ModerationOptsProvider */} - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + {/* LabelDefsProvider MUST come before ModerationOptsProvider */} + + + + + + + + + + + + + + + + + + + + + + + + ) } @@ -145,27 +143,29 @@ function App() { * that is set up in the InnerApp component above. */ return ( - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + ) } diff --git a/src/screens/Messages/Conversation/MessagesList.tsx b/src/screens/Messages/Conversation/MessagesList.tsx index 13d333cd1a..922721664a 100644 --- a/src/screens/Messages/Conversation/MessagesList.tsx +++ b/src/screens/Messages/Conversation/MessagesList.tsx @@ -2,13 +2,11 @@ import React, {useCallback, useRef} from 'react' import {FlatList, View} from 'react-native' import { KeyboardStickyView, - useKeyboardContext, useKeyboardHandler, } from 'react-native-keyboard-controller' import { runOnJS, scrollTo, - useAnimatedKeyboard, useAnimatedRef, useAnimatedStyle, useSharedValue, @@ -16,7 +14,6 @@ import { import {ReanimatedScrollEvent} from 'react-native-reanimated/lib/typescript/reanimated2/hook/commonTypes' import {useSafeAreaInsets} from 'react-native-safe-area-context' import {AppBskyRichtextFacet, RichText} from '@atproto/api' -import {useFocusEffect} from '@react-navigation/native' import {shortenLinks} from '#/lib/strings/rich-text-manip' import {isIOS, isNative} from '#/platform/detection' @@ -79,17 +76,6 @@ export function MessagesList({ blocked?: boolean footer?: React.ReactNode }) { - const kbContext = useKeyboardContext() - useFocusEffect( - useCallback(() => { - kbContext.setEnabled(true) - - return () => { - kbContext.setEnabled(false) - } - }, [kbContext]), - ) - const convoState = useConvoActive() const {getAgent} = useAgent() @@ -219,7 +205,7 @@ export function MessagesList({ const nativeBottomBarHeight = isIOS ? 42 : 60 const bottomOffset = isWeb ? 0 : bottomInset + nativeBottomBarHeight - const kb = useAnimatedKeyboard() + const keyboardHeight = useSharedValue(0) const keyboardIsOpening = useSharedValue(false) useKeyboardHandler({ @@ -229,6 +215,8 @@ export function MessagesList({ }, onMove: e => { 'worklet' + keyboardHeight.value = e.height + if (e.height > bottomOffset) { console.log('move') scrollTo(flatListRef, 0, 1e7, false) @@ -242,7 +230,7 @@ export function MessagesList({ const animatedListStyle = useAnimatedStyle(() => ({ marginBottom: - kb.height.value > bottomOffset ? kb.height.value : bottomOffset, + keyboardHeight.value > bottomOffset ? keyboardHeight.value : bottomOffset, })) // -- Message sending diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 61c339024b..d85fca299a 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -3,13 +3,15 @@ import { ActivityIndicator, BackHandler, Keyboard, - KeyboardAvoidingView, - Platform, ScrollView, StyleSheet, TouchableOpacity, View, } from 'react-native' +import { + KeyboardAvoidingView, + KeyboardStickyView, +} from 'react-native-keyboard-controller' import {useSafeAreaInsets} from 'react-native-safe-area-context' import {LinearGradient} from 'expo-linear-gradient' import {RichText} from '@atproto/api' @@ -373,172 +375,178 @@ export const ComposePost = observer(function ComposePost({ ) return ( - - - - - - Cancel - - - - {isProcessing ? ( - <> - {processingState} - - - - - ) : ( - <> - - {replyTo ? null : ( - + + + + + + Cancel + + + + {isProcessing ? ( + <> + {processingState} + + + + + ) : ( + <> + - )} - {canPost ? ( - - - - {replyTo ? ( - Reply - ) : ( - Post - )} + {replyTo ? null : ( + + )} + {canPost ? ( + + + + {replyTo ? ( + Reply + ) : ( + Post + )} + + + + ) : ( + + + Post - - - ) : ( - - - Post - - - )} - - )} - - {isAltTextRequiredAndMissing && ( - - - - - - One or more images is missing alt text. - + + )} + + )} - )} - {error !== '' && ( - - - + {isAltTextRequiredAndMissing && ( + + + + + + One or more images is missing alt text. + - {error} - - )} - - {replyTo ? : undefined} - - - - - + )} + {error !== '' && ( + + + + + {error} + + )} + + {replyTo ? : undefined} - - {gallery.isEmpty && extLink && ( - - { - setExtLink(undefined) - setExtGif(undefined) - }} + + - - )} - {quote ? ( - - - + + + {gallery.isEmpty && extLink && ( + + { + setExtLink(undefined) + setExtGif(undefined) + }} + /> + - {quote.uri !== initQuote?.uri && ( - setQuote(undefined)} /> - )} - - ) : undefined} - - + )} + {quote ? ( + + + + + {quote.uri !== initQuote?.uri && ( + setQuote(undefined)} /> + )} + + ) : undefined} + + + + + @@ -565,8 +573,7 @@ export const ComposePost = observer(function ComposePost({ - - + - + ) })