Proper fix!
This commit is contained in:
@@ -107,7 +107,9 @@ export const ComposePost = observer(function ComposePost({
|
||||
text: initText,
|
||||
imageUris: initImageUris,
|
||||
cancelRef,
|
||||
visible,
|
||||
}: Props & {
|
||||
visible?: boolean
|
||||
cancelRef?: React.RefObject<CancelRef>
|
||||
}) {
|
||||
const {currentAccount} = useSession()
|
||||
@@ -155,33 +157,6 @@ export const ComposePost = observer(function ComposePost({
|
||||
const [labels, setLabels] = useState<string[]>([])
|
||||
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(
|
||||
() => new GalleryModel(initImageUris),
|
||||
[initImageUris],
|
||||
@@ -543,7 +518,9 @@ export const ComposePost = observer(function ComposePost({
|
||||
ref={textInput}
|
||||
richtext={richtext}
|
||||
placeholder={selectTextInputPlaceholder}
|
||||
autoFocus={!isAndroid}
|
||||
// fixes autofocus on android
|
||||
key={isAndroid ? (visible ? 'visible' : 'hidden') : 'static'}
|
||||
autoFocus
|
||||
setRichText={setRichText}
|
||||
onPhotoPasted={onPhotoPasted}
|
||||
onPressPublish={onPressPublish}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, {useLayoutEffect} from 'react'
|
||||
import React, {useLayoutEffect, useState} from 'react'
|
||||
import {Modal, View} from 'react-native'
|
||||
import {GestureHandlerRootView} from 'react-native-gesture-handler'
|
||||
import {RootSiblingParent} from 'react-native-root-siblings'
|
||||
@@ -24,9 +24,14 @@ export const Composer = observer(function ComposerImpl({}: {
|
||||
const t = useTheme()
|
||||
const state = useComposerState()
|
||||
const ref = useComposerCancelRef()
|
||||
const [shown, setShown] = useState(false)
|
||||
|
||||
const open = !!state
|
||||
|
||||
if (!open && shown) {
|
||||
setShown(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
aria-modal
|
||||
@@ -34,10 +39,12 @@ export const Composer = observer(function ComposerImpl({}: {
|
||||
visible={open}
|
||||
presentationStyle="formSheet"
|
||||
animationType="slide"
|
||||
onShow={() => setShown(true)}
|
||||
onRequestClose={() => ref.current?.onPressCancel()}>
|
||||
<View style={[t.atoms.bg, a.flex_1]}>
|
||||
<Providers open={open}>
|
||||
<ComposePost
|
||||
visible={shown}
|
||||
cancelRef={ref}
|
||||
replyTo={state?.replyTo}
|
||||
onPost={state?.onPost}
|
||||
|
||||
Reference in New Issue
Block a user