Use <Modal> for Composer (#3588)

* use <Modal> to display composer

* trigger `onPressCancel` on modal cancel

* remove android top padding

* use light statusbar on ios

* use KeyboardStickyView from r-n-keyboard-controller

* make extra bottom padding ios-only

* make cancelRef optional

* scope legacy modals

* don't change bg color on ios

* use fullScreen instead of formSheet

* adjust padding on keyboardaccessory to account for new buttons

* Revert "use KeyboardStickyView from r-n-keyboard-controller"

This reverts commit 426c812904f427bdd08107cffc32e4be1d9b83bc.

* fix insets

* tweaks and merge

* revert 89f51c72

* nit

* import keyboard provider

---------

Co-authored-by: Hailey <me@haileyok.com>
Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
This commit is contained in:
Samuel Newman 2024-05-30 07:44:20 +03:00 committed by GitHub
parent fba4a9ca02
commit c4abaa1abc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 101 additions and 98 deletions

View file

@ -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: {