From 3d4b390a8a9c4a7c52354a0c7bd4bc0a8e12f9f8 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Tue, 11 Jun 2024 20:50:56 +0100 Subject: [PATCH] Only enable keyboard controller when necessary (#4483) * Only enable keyboard controller when necessary * make it screen only * rm keyboard padding * rm keyboardpadding file * revert using keyboard controller in composer * remove styles.outer (unnecessary for revert) * continue to use keyboard padding in the report dialog for dms --------- Co-authored-by: Hailey --- src/App.native.tsx | 2 +- ... => KeyboardControllerPadding.android.tsx} | 2 +- src/components/KeyboardControllerPadding.tsx | 7 + src/components/KeyboardPadding.tsx | 3 - src/components/ReportDialog/SubmitView.tsx | 2 - src/components/dialogs/MutedWords.tsx | 2 - src/components/dms/ReportDialog.tsx | 2 + .../moderation/LabelsOnMeDialog.tsx | 2 - src/screens/Messages/Conversation/index.tsx | 12 + src/view/com/composer/Composer.tsx | 357 +++++++++--------- src/view/com/composer/GifAltText.tsx | 2 - src/view/com/modals/AddAppPasswords.tsx | 2 - src/view/com/modals/Modal.tsx | 2 - 13 files changed, 191 insertions(+), 206 deletions(-) rename src/components/{KeyboardPadding.android.tsx => KeyboardControllerPadding.android.tsx} (88%) create mode 100644 src/components/KeyboardControllerPadding.tsx delete mode 100644 src/components/KeyboardPadding.tsx diff --git a/src/App.native.tsx b/src/App.native.tsx index b359ad91..5b2071e1 100644 --- a/src/App.native.tsx +++ b/src/App.native.tsx @@ -143,7 +143,7 @@ function App() { * that is set up in the InnerApp component above. */ return ( - + diff --git a/src/components/KeyboardPadding.android.tsx b/src/components/KeyboardControllerPadding.android.tsx similarity index 88% rename from src/components/KeyboardPadding.android.tsx rename to src/components/KeyboardControllerPadding.android.tsx index 40dec300..92ef1b0b 100644 --- a/src/components/KeyboardPadding.android.tsx +++ b/src/components/KeyboardControllerPadding.android.tsx @@ -5,7 +5,7 @@ import Animated, { useSharedValue, } from 'react-native-reanimated' -export function KeyboardPadding({maxHeight}: {maxHeight?: number}) { +export function KeyboardControllerPadding({maxHeight}: {maxHeight?: number}) { const keyboardHeight = useSharedValue(0) useKeyboardHandler( diff --git a/src/components/KeyboardControllerPadding.tsx b/src/components/KeyboardControllerPadding.tsx new file mode 100644 index 00000000..f3163d87 --- /dev/null +++ b/src/components/KeyboardControllerPadding.tsx @@ -0,0 +1,7 @@ +export function KeyboardControllerPadding({ + maxHeight: _, +}: { + maxHeight?: number +}) { + return null +} diff --git a/src/components/KeyboardPadding.tsx b/src/components/KeyboardPadding.tsx deleted file mode 100644 index 797d42ba..00000000 --- a/src/components/KeyboardPadding.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export function KeyboardPadding({maxHeight: _}: {maxHeight?: number}) { - return null -} diff --git a/src/components/ReportDialog/SubmitView.tsx b/src/components/ReportDialog/SubmitView.tsx index 74ecf92e..3731617f 100644 --- a/src/components/ReportDialog/SubmitView.tsx +++ b/src/components/ReportDialog/SubmitView.tsx @@ -15,7 +15,6 @@ import * as Dialog from '#/components/Dialog' import * as Toggle from '#/components/forms/Toggle' import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check' import {ChevronLeft_Stroke2_Corner0_Rounded as ChevronLeft} from '#/components/icons/Chevron' -import {KeyboardPadding} from '#/components/KeyboardPadding' import {Loader} from '#/components/Loader' import {Text} from '#/components/Typography' import {ReportDialogProps} from './types' @@ -222,7 +221,6 @@ export function SubmitView({ {submitting && } - ) } diff --git a/src/components/dialogs/MutedWords.tsx b/src/components/dialogs/MutedWords.tsx index dea81941..53426342 100644 --- a/src/components/dialogs/MutedWords.tsx +++ b/src/components/dialogs/MutedWords.tsx @@ -28,7 +28,6 @@ import {Hashtag_Stroke2_Corner0_Rounded as Hashtag} from '#/components/icons/Has import {PageText_Stroke2_Corner0_Rounded as PageText} from '#/components/icons/PageText' import {PlusLarge_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus' import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times' -import {KeyboardPadding} from '#/components/KeyboardPadding' import {Loader} from '#/components/Loader' import * as Prompt from '#/components/Prompt' import {Text} from '#/components/Typography' @@ -257,7 +256,6 @@ function MutedWordsInner() { - ) } diff --git a/src/components/dms/ReportDialog.tsx b/src/components/dms/ReportDialog.tsx index 9c4ed2a0..5493a1c8 100644 --- a/src/components/dms/ReportDialog.tsx +++ b/src/components/dms/ReportDialog.tsx @@ -16,6 +16,7 @@ import {CharProgress} from '#/view/com/composer/char-progress/CharProgress' import * as Toast from '#/view/com/util/Toast' import {atoms as a, useBreakpoints, useTheme} from '#/alf' import * as Dialog from '#/components/Dialog' +import {KeyboardControllerPadding} from '#/components/KeyboardControllerPadding' import {Button, ButtonIcon, ButtonText} from '../Button' import {Divider} from '../Divider' import {ChevronLeft_Stroke2_Corner0_Rounded as Chevron} from '../icons/Chevron' @@ -47,6 +48,7 @@ let ReportDialog = ({ + ) diff --git a/src/components/moderation/LabelsOnMeDialog.tsx b/src/components/moderation/LabelsOnMeDialog.tsx index 7c76269a..d0f0d4ea 100644 --- a/src/components/moderation/LabelsOnMeDialog.tsx +++ b/src/components/moderation/LabelsOnMeDialog.tsx @@ -14,7 +14,6 @@ import * as Toast from '#/view/com/util/Toast' import {atoms as a, useBreakpoints, useTheme} from '#/alf' import {Button, ButtonIcon, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' -import {KeyboardPadding} from '#/components/KeyboardPadding' import {InlineLinkText} from '#/components/Link' import {Text} from '#/components/Typography' import {Divider} from '../Divider' @@ -110,7 +109,6 @@ function LabelsOnMeDialogInner(props: LabelsOnMeDialogProps) { )} - ) } diff --git a/src/screens/Messages/Conversation/index.tsx b/src/screens/Messages/Conversation/index.tsx index d21887de..a99ef8d4 100644 --- a/src/screens/Messages/Conversation/index.tsx +++ b/src/screens/Messages/Conversation/index.tsx @@ -1,5 +1,6 @@ import React, {useCallback} from 'react' import {View} from 'react-native' +import {useKeyboardController} from 'react-native-keyboard-controller' import {AppBskyActorDefs, moderateProfile, ModerationOpts} from '@atproto/api' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' @@ -34,6 +35,17 @@ export function MessagesConversationScreen({route}: Props) { const convoId = route.params.conversation const {setCurrentConvoId} = useCurrentConvoId() + const {setEnabled} = useKeyboardController() + useFocusEffect( + useCallback(() => { + if (isWeb) return + setEnabled(true) + return () => { + setEnabled(false) + } + }, [setEnabled]), + ) + useFocusEffect( useCallback(() => { setCurrentConvoId(convoId) diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index e8ea5189..9bb70401 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -10,16 +10,12 @@ import { ActivityIndicator, BackHandler, Keyboard, + KeyboardAvoidingView, LayoutChangeEvent, StyleSheet, TouchableOpacity, View, } from 'react-native' -import { - KeyboardAvoidingView, - KeyboardStickyView, - useKeyboardController, -} from 'react-native-keyboard-controller' import Animated, { interpolateColor, useAnimatedStyle, @@ -131,17 +127,6 @@ export const ComposePost = observer(function ComposePost({ const {closeAllModals} = useModalControls() const t = useTheme() - // Disable this in the composer to prevent any extra keyboard height being applied. - // See https://github.com/bluesky-social/social-app/pull/4399 - const {setEnabled} = useKeyboardController() - React.useEffect(() => { - if (!isAndroid) return - setEnabled(false) - return () => { - setEnabled(true) - } - }, [setEnabled]) - const [isKeyboardVisible] = useIsKeyboardVisible({iosUseWillEvents: true}) const [isProcessing, setIsProcessing] = useState(false) const [processingState, setProcessingState] = useState('') @@ -431,181 +416,175 @@ export const ComposePost = observer(function ComposePost({ } = useAnimatedBorders() return ( - <> - - - - - - - Cancel - - - - {isProcessing ? ( - <> - {processingState} - - - - - ) : ( - <> - - {canPost ? ( - - - - {replyTo ? ( - Reply - ) : ( - Post - )} - - - - ) : ( - - - Post + + + + + + + Cancel + + + + {isProcessing ? ( + <> + {processingState} + + + + + ) : ( + <> + + {canPost ? ( + + + + {replyTo ? ( + Reply + ) : ( + Post + )} - - )} - + + + ) : ( + + + Post + + + )} + + )} + + + {isAltTextRequiredAndMissing && ( + + + + + + One or more images is missing alt text. + + + )} + {error !== '' && ( + + + + + {error} + + )} + + + {replyTo ? : undefined} + + + + + + + + {gallery.isEmpty && extLink && ( + + { + setExtLink(undefined) + setExtGif(undefined) + }} + /> + + + )} + + {quote ? ( + + + + + {quote.uri !== initQuote?.uri && ( + setQuote(undefined)} /> )} + ) : undefined} + + - {isAltTextRequiredAndMissing && ( - - - - - - One or more images is missing alt text. - - - )} - {error !== '' && ( - - - - - {error} - - )} - - - {replyTo ? : undefined} - - - - - - - - {gallery.isEmpty && extLink && ( - - { - setExtLink(undefined) - setExtGif(undefined) - }} - /> - - - )} - {quote ? ( - - - - - {quote.uri !== initQuote?.uri && ( - setQuote(undefined)} /> - )} - - ) : undefined} - - - - - {replyTo ? null : ( - + - + ) }) diff --git a/src/view/com/composer/GifAltText.tsx b/src/view/com/composer/GifAltText.tsx index cdef1335..b1f10bf2 100644 --- a/src/view/com/composer/GifAltText.tsx +++ b/src/view/com/composer/GifAltText.tsx @@ -20,7 +20,6 @@ import * as Dialog from '#/components/Dialog' import * as TextField from '#/components/forms/TextField' import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check' import {PlusSmall_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus' -import {KeyboardPadding} from '#/components/KeyboardPadding' import {Text} from '#/components/Typography' import {GifEmbed} from '../util/post-embeds/GifEmbed' import {AltTextReminder} from './photos/Gallery' @@ -181,7 +180,6 @@ function AltTextInner({ - ) } diff --git a/src/view/com/modals/AddAppPasswords.tsx b/src/view/com/modals/AddAppPasswords.tsx index d6df1265..92229e7b 100644 --- a/src/view/com/modals/AddAppPasswords.tsx +++ b/src/view/com/modals/AddAppPasswords.tsx @@ -22,7 +22,6 @@ import {Text} from '#/view/com/util/text/Text' import * as Toast from '#/view/com/util/Toast' import {atoms as a} from '#/alf' import * as Toggle from '#/components/forms/Toggle' -import {KeyboardPadding} from '#/components/KeyboardPadding' export const snapPoints = ['90%'] @@ -246,7 +245,6 @@ export function Component({}: {}) { onPress={!appPassword ? createAppPassword : onDone} /> - ) } diff --git a/src/view/com/modals/Modal.tsx b/src/view/com/modals/Modal.tsx index eb966640..ecfe5806 100644 --- a/src/view/com/modals/Modal.tsx +++ b/src/view/com/modals/Modal.tsx @@ -6,7 +6,6 @@ import BottomSheet from '@discord/bottom-sheet/src' import {useModalControls, useModals} from '#/state/modals' import {usePalette} from 'lib/hooks/usePalette' import {FullWindowOverlay} from '#/components/FullWindowOverlay' -import {KeyboardPadding} from '#/components/KeyboardPadding' import {createCustomBackdrop} from '../util/BottomSheetCustomBackdrop' import * as AddAppPassword from './AddAppPasswords' import * as AltImageModal from './AltImage' @@ -147,7 +146,6 @@ export function ModalsContainer() { handleStyle={[styles.handle, pal.view]} onChange={onBottomSheetChange}> {element} - )