diff options
Diffstat (limited to 'src/view/com/composer/Composer.tsx')
-rw-r--r-- | src/view/com/composer/Composer.tsx | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 12e57c411..5746454c2 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -1,7 +1,13 @@ -import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react' +import React, { + useCallback, + useEffect, + useImperativeHandle, + useMemo, + useRef, + useState, +} from 'react' import { ActivityIndicator, - BackHandler, Keyboard, ScrollView, StyleSheet, @@ -79,6 +85,10 @@ import {TextInput, TextInputRef} from './text-input/TextInput' import {ThreadgateBtn} from './threadgate/ThreadgateBtn' import {useExternalLinkFetch} from './useExternalLinkFetch' +type CancelRef = { + onPressCancel: () => void +} + type Props = ComposerOpts export const ComposePost = observer(function ComposePost({ replyTo, @@ -88,7 +98,10 @@ export const ComposePost = observer(function ComposePost({ openPicker, text: initText, imageUris: initImageUris, -}: Props) { + cancelRef, +}: Props & { + cancelRef?: React.RefObject<CancelRef> +}) { const {currentAccount} = useSession() const agent = useAgent() const {data: currentProfile} = useProfileQuery({did: currentAccount!.did}) @@ -145,7 +158,7 @@ export const ComposePost = observer(function ComposePost({ () => ({ paddingBottom: isAndroid || (isIOS && !isKeyboardVisible) ? insets.bottom : 0, - paddingTop: isAndroid ? insets.top : isMobile ? 15 : 0, + paddingTop: isMobile && isWeb ? 15 : insets.top, }), [insets, isKeyboardVisible, isMobile], ) @@ -167,23 +180,8 @@ export const ComposePost = observer(function ComposePost({ discardPromptControl, onClose, ]) - // android back button - useEffect(() => { - if (!isAndroid) { - return - } - const backHandler = BackHandler.addEventListener( - 'hardwareBackPress', - () => { - onPressCancel() - return true - }, - ) - return () => { - backHandler.remove() - } - }, [onPressCancel]) + useImperativeHandle(cancelRef, () => ({onPressCancel})) // listen to escape key on desktop web const onEscape = useCallback( @@ -583,19 +581,18 @@ export const ComposePost = observer(function ComposePost({ ) }) +export function useComposerCancelRef() { + return useRef<CancelRef>(null) +} + const styles = StyleSheet.create({ - outer: { - flexDirection: 'column', - flex: 1, - height: '100%', - }, topbar: { flexDirection: 'row', alignItems: 'center', - paddingTop: 6, + marginTop: -14, paddingBottom: 4, paddingHorizontal: 20, - height: 55, + height: 50, gap: 4, }, topbarDesktop: { |