Skip to content

Commit

Permalink
state
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok committed Oct 5, 2024
1 parent 13d195a commit 8285f08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/view/com/composer/GifAltText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function AltTextInner({
onChangeText={text => {
setAltText(text)
}}
value={altText}
defaultValue={altText}
multiline
numberOfLines={3}
autoFocus
Expand Down
17 changes: 9 additions & 8 deletions src/view/com/composer/photos/ImageAltTextDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,43 @@ export const ImageAltTextDialog = ({
onChange,
Portal,
}: Props): React.ReactNode => {
const altTextRef = React.useRef<string>(image.alt)
const [altText, setAltText] = React.useState(image.alt)

return (
<Dialog.Outer
control={control}
onClose={() => {
onChange({
...image,
alt: enforceLen(altTextRef.current, MAX_ALT_TEXT, true),
alt: enforceLen(altText, MAX_ALT_TEXT, true),
})
}}
Portal={Portal}>
<Dialog.Handle />
<ImageAltTextInner
control={control}
image={image}
altTextRef={altTextRef}
altText={altText}
setAltText={setAltText}
/>
</Dialog.Outer>
)
}

const ImageAltTextInner = ({
altTextRef,
altText,
setAltText,
control,
image,
}: {
altTextRef: React.MutableRefObject<string>
altText: string
setAltText: (text: string) => void
control: DialogControlProps
image: Props['image']
}): React.ReactNode => {
const {_, i18n} = useLingui()
const t = useTheme()
const windim = useWindowDimensions()
const [altText, setAltText] = React.useState(image.alt)

const imageStyle = React.useMemo<ImageStyle>(() => {
const maxWidth = isWeb ? 450 : windim.width
Expand Down Expand Up @@ -119,10 +121,9 @@ const ImageAltTextInner = ({
<Dialog.Input
label={_(msg`Alt text`)}
onChangeText={text => {
altTextRef.current = text
setAltText(text)
}}
value={altText}
defaultValue={altText}
multiline
numberOfLines={3}
autoFocus
Expand Down

0 comments on commit 8285f08

Please sign in to comment.