[Drafts] Some bugs (#9833)

* Fix text input not updating

* Fix autofocus

* make placeholder text fainter

* Await invalidation

* Image only drafts

* tweaks to gif presentation

---------

Co-authored-by: Eric Bailey <git@esb.lol>
This commit is contained in:
Samuel Newman
2026-02-07 17:38:48 +02:00
committed by GitHub
parent 6bfe758d2a
commit 917f099e26
7 changed files with 61 additions and 56 deletions
@@ -1,11 +1,16 @@
import {Pressable, StyleSheet, TouchableOpacity, View} from 'react-native' import {
ActivityIndicator,
StyleSheet,
TouchableOpacity,
View,
} from 'react-native'
import {msg, Trans} from '@lingui/macro' import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {HITSLOP_20} from '#/lib/constants' import {HITSLOP_20} from '#/lib/constants'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import {Button} from '#/components/Button'
import {Fill} from '#/components/Fill' import {Fill} from '#/components/Fill'
import {Loader} from '#/components/Loader'
import * as Prompt from '#/components/Prompt' import * as Prompt from '#/components/Prompt'
import {Text} from '#/components/Typography' import {Text} from '#/components/Typography'
import {PlayButtonIcon} from '#/components/video/PlayButtonIcon' import {PlayButtonIcon} from '#/components/video/PlayButtonIcon'
@@ -26,28 +31,27 @@ export function GifPresentationControls({
return ( return (
<> <>
<Pressable <Button
accessibilityRole="button" label={isPlaying ? _(msg`Pause GIF`) : _(msg`Play GIF`)}
accessibilityHint={_(msg`Plays or pauses the GIF`)} accessibilityHint={_(msg`Plays or pauses the GIF`)}
accessibilityLabel={isPlaying ? _(msg`Pause`) : _(msg`Play`)}
style={[ style={[
a.absolute, a.absolute,
a.align_center, a.align_center,
a.justify_center, a.justify_center,
a.inset_0, a.inset_0,
a.w_full,
a.h_full,
{zIndex: 2}, {zIndex: 2},
]} ]}
onPress={onPress}> onPress={onPress}>
{isLoading ? ( {isLoading ? (
<View style={[a.align_center, a.justify_center]}> <View style={[a.align_center, a.justify_center]}>
<Loader size="xl" /> <ActivityIndicator size="large" color="white" />
</View> </View>
) : !isPlaying ? ( ) : !isPlaying ? (
<PlayButtonIcon /> <PlayButtonIcon />
) : undefined} ) : (
</Pressable> <></>
)}
</Button>
{!isPlaying && ( {!isPlaying && (
<Fill <Fill
style={[ style={[
+32 -24
View File
@@ -6,11 +6,12 @@ import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {ErrorBoundary} from '#/view/com/util/ErrorBoundary' import {ErrorBoundary} from '#/view/com/util/ErrorBoundary'
import {atoms as a} from '#/alf' import {atoms as a, platform} from '#/alf'
import {Button} from '#/components/Button' import {Button} from '#/components/Button'
import {useThrottledValue} from '#/components/hooks/useThrottledValue' import {useThrottledValue} from '#/components/hooks/useThrottledValue'
import {ConstrainedImage} from '#/components/images/AutoSizedImage' import {ConstrainedImage} from '#/components/images/AutoSizedImage'
import {PlayButtonIcon} from '#/components/video/PlayButtonIcon' import {PlayButtonIcon} from '#/components/video/PlayButtonIcon'
import {GifPresentationControls} from './GifPresentationControls'
import {VideoEmbedInnerNative} from './VideoEmbedInner/VideoEmbedInnerNative' import {VideoEmbedInnerNative} from './VideoEmbedInner/VideoEmbedInnerNative'
import * as VideoFallback from './VideoEmbedInner/VideoFallback' import * as VideoFallback from './VideoEmbedInner/VideoFallback'
@@ -101,33 +102,40 @@ function InnerWrapper({embed}: Props) {
{ {
backgroundColor: 'transparent', // If you don't add `backgroundColor` to the styles here, backgroundColor: 'transparent', // If you don't add `backgroundColor` to the styles here,
// the play button won't show up on the first render on android 🥴😮‍💨 // the play button won't show up on the first render on android 🥴😮‍💨
display: showOverlay ? 'flex' : 'none',
}, },
platform({
android: {display: showOverlay ? 'flex' : 'none'},
ios: {zIndex: showOverlay ? 1 : -1},
}),
]} ]}
cachePolicy="memory-disk" // Preferring memory cache helps to avoid flicker when re-displaying on android cachePolicy="memory-disk" // Preferring memory cache helps to avoid flicker when re-displaying on android
> >
{showOverlay && ( {showOverlay &&
<Button (embed.presentation === 'gif' ? (
style={[a.flex_1, a.align_center, a.justify_center]} <GifPresentationControls
onPress={() => { isPlaying={false}
ref.current?.togglePlayback() isLoading={showSpinner}
}} onPress={() => {
label={_(msg`Play video`)}> ref.current?.togglePlayback()
{showSpinner ? ( }}
<View altText={embed.alt}
style={[ />
a.rounded_full, ) : (
a.p_xs, <Button
a.align_center, style={[a.flex_1, a.align_center, a.justify_center]}
a.justify_center, onPress={() => {
]}> ref.current?.togglePlayback()
<ActivityIndicator size="large" color="white" /> }}
</View> label={_(msg`Play video`)}>
) : ( {showSpinner ? (
<PlayButtonIcon /> <View style={[a.align_center, a.justify_center]}>
)} <ActivityIndicator size="large" color="white" />
</Button> </View>
)} ) : (
<PlayButtonIcon />
)}
</Button>
))}
</ImageBackground> </ImageBackground>
</> </>
) )
+2 -2
View File
@@ -1115,7 +1115,7 @@ export const ComposePost = ({
onLayout={onScrollViewLayout}> onLayout={onScrollViewLayout}>
{replyTo ? <ComposerReplyTo replyTo={replyTo} /> : undefined} {replyTo ? <ComposerReplyTo replyTo={replyTo} /> : undefined}
{thread.posts.map((post, index) => ( {thread.posts.map((post, index) => (
<React.Fragment key={post.id}> <React.Fragment key={post.id + (composerState.draftId ?? '')}>
<ComposerPost <ComposerPost
post={post} post={post}
dispatch={composerDispatch} dispatch={composerDispatch}
@@ -1320,7 +1320,7 @@ let ComposerPost = React.memo(function ComposerPost({
style={[a.pt_xs]} style={[a.pt_xs]}
richtext={richtext} richtext={richtext}
placeholder={selectTextInputPlaceholder} placeholder={selectTextInputPlaceholder}
autoFocus autoFocus={isLastPost}
webForceMinHeight={forceMinHeight} webForceMinHeight={forceMinHeight}
// To avoid overlap with the close button: // To avoid overlap with the close button:
hasRightPadding={isPartOfThread} hasRightPadding={isPartOfThread}
+8 -6
View File
@@ -95,12 +95,14 @@ export function DraftItem({
paddingTop: 20 + a.pt_md.paddingTop, paddingTop: 20 + a.pt_md.paddingTop,
}, },
]}> ]}>
<RichText {!!post.text.trim().length && (
style={[a.text_md, a.leading_snug, a.pointer_events_none]} <RichText
value={post.text} style={[a.text_md, a.leading_snug, a.pointer_events_none]}
enableTags value={post.text}
disableMentionFacetValidation enableTags
/> disableMentionFacetValidation
/>
)}
{!mediaExistsOnOtherDevice && <DraftMediaPreview post={post} />} {!mediaExistsOnOtherDevice && <DraftMediaPreview post={post} />}
@@ -184,7 +184,7 @@ export function useSaveDraftMutation() {
} }
} }
queryClient.invalidateQueries({queryKey: DRAFTS_QUERY_KEY}) await queryClient.invalidateQueries({queryKey: DRAFTS_QUERY_KEY})
}, },
onError: error => { onError: error => {
// Check for draft limit error // Check for draft limit error
@@ -224,9 +224,9 @@ export function TextInput({
onPaste={onPaste} onPaste={onPaste}
onSelectionChange={onSelectionChange} onSelectionChange={onSelectionChange}
placeholder={placeholder} placeholder={placeholder}
placeholderTextColor={t.atoms.text_contrast_medium.color} placeholderTextColor={t.atoms.text_contrast_low.color}
keyboardAppearance={theme.colorScheme} keyboardAppearance={theme.colorScheme}
autoFocus={true} autoFocus={props.autoFocus !== undefined ? props.autoFocus : true}
allowFontScaling allowFontScaling
multiline multiline
scrollEnabled={false} scrollEnabled={false}
@@ -52,6 +52,7 @@ export function TextInput({
onPressPublish, onPressPublish,
onNewLink, onNewLink,
onFocus, onFocus,
autoFocus,
}: TextInputProps) { }: TextInputProps) {
const {theme: t, fonts} = useAlf() const {theme: t, fonts} = useAlf()
const autocomplete = useActorAutocompleteFn() const autocomplete = useActorAutocompleteFn()
@@ -244,20 +245,10 @@ export function TextInput({
content: generateJSON(richTextToHTML(richtext), extensions, { content: generateJSON(richTextToHTML(richtext), extensions, {
preserveWhitespace: 'full', preserveWhitespace: 'full',
}), }),
autofocus: 'end', autofocus: autoFocus ? 'end' : null,
editable: true, editable: true,
injectCSS: true, injectCSS: true,
shouldRerenderOnTransaction: false, shouldRerenderOnTransaction: false,
onCreate({editor: editorProp}) {
// HACK
// the 'enter' animation sometimes causes autofocus to fail
// (see Composer.web.tsx in shell)
// so we wait 200ms (the anim is 150ms) and then focus manually
// -prf
setTimeout(() => {
editorProp.chain().focus('end').run()
}, 200)
},
onUpdate({editor: editorProp}) { onUpdate({editor: editorProp}) {
const json = editorProp.getJSON() const json = editorProp.getJSON()
const newText = editorJsonToText(json) const newText = editorJsonToText(json)