Proper fix!

This commit is contained in:
Samuel Newman
2024-06-06 15:29:15 +03:00
parent becebcd026
commit 4df79dfc8c
2 changed files with 13 additions and 29 deletions
+5 -28
View File
@@ -107,7 +107,9 @@ export const ComposePost = observer(function ComposePost({
text: initText, text: initText,
imageUris: initImageUris, imageUris: initImageUris,
cancelRef, cancelRef,
visible,
}: Props & { }: Props & {
visible?: boolean
cancelRef?: React.RefObject<CancelRef> cancelRef?: React.RefObject<CancelRef>
}) { }) {
const {currentAccount} = useSession() const {currentAccount} = useSession()
@@ -155,33 +157,6 @@ export const ComposePost = observer(function ComposePost({
const [labels, setLabels] = useState<string[]>([]) const [labels, setLabels] = useState<string[]>([])
const [threadgate, setThreadgate] = useState<ThreadgateSetting[]>([]) const [threadgate, setThreadgate] = useState<ThreadgateSetting[]>([])
useEffect(() => {
if (!isAndroid) return
// optimistic first try to focus keyboard
const timeout = setTimeout(() => {
textInput.current?.focus()
}, 50)
// however, sometimes that fires too soon, and the keyboard doesn't show
// so we try a few more times
let numTries = 5
const interval = setInterval(() => {
if (Keyboard.isVisible() || numTries-- <= 0) {
clearInterval(interval)
} else {
// focusing doesn't open keyboard if it's already focused
textInput.current?.blur()
textInput.current?.focus()
}
}, 250)
return () => {
clearTimeout(timeout)
clearInterval(interval)
}
}, [])
const gallery = useMemo( const gallery = useMemo(
() => new GalleryModel(initImageUris), () => new GalleryModel(initImageUris),
[initImageUris], [initImageUris],
@@ -543,7 +518,9 @@ export const ComposePost = observer(function ComposePost({
ref={textInput} ref={textInput}
richtext={richtext} richtext={richtext}
placeholder={selectTextInputPlaceholder} placeholder={selectTextInputPlaceholder}
autoFocus={!isAndroid} // fixes autofocus on android
key={isAndroid ? (visible ? 'visible' : 'hidden') : 'static'}
autoFocus
setRichText={setRichText} setRichText={setRichText}
onPhotoPasted={onPhotoPasted} onPhotoPasted={onPhotoPasted}
onPressPublish={onPressPublish} onPressPublish={onPressPublish}
+8 -1
View File
@@ -1,4 +1,4 @@
import React, {useLayoutEffect} from 'react' import React, {useLayoutEffect, useState} from 'react'
import {Modal, View} from 'react-native' import {Modal, View} from 'react-native'
import {GestureHandlerRootView} from 'react-native-gesture-handler' import {GestureHandlerRootView} from 'react-native-gesture-handler'
import {RootSiblingParent} from 'react-native-root-siblings' import {RootSiblingParent} from 'react-native-root-siblings'
@@ -24,9 +24,14 @@ export const Composer = observer(function ComposerImpl({}: {
const t = useTheme() const t = useTheme()
const state = useComposerState() const state = useComposerState()
const ref = useComposerCancelRef() const ref = useComposerCancelRef()
const [shown, setShown] = useState(false)
const open = !!state const open = !!state
if (!open && shown) {
setShown(false)
}
return ( return (
<Modal <Modal
aria-modal aria-modal
@@ -34,10 +39,12 @@ export const Composer = observer(function ComposerImpl({}: {
visible={open} visible={open}
presentationStyle="formSheet" presentationStyle="formSheet"
animationType="slide" animationType="slide"
onShow={() => setShown(true)}
onRequestClose={() => ref.current?.onPressCancel()}> onRequestClose={() => ref.current?.onPressCancel()}>
<View style={[t.atoms.bg, a.flex_1]}> <View style={[t.atoms.bg, a.flex_1]}>
<Providers open={open}> <Providers open={open}>
<ComposePost <ComposePost
visible={shown}
cancelRef={ref} cancelRef={ref}
replyTo={state?.replyTo} replyTo={state?.replyTo}
onPost={state?.onPost} onPost={state?.onPost}