Comments, improve a11y

This commit is contained in:
Eric Bailey
2024-09-03 21:18:47 -05:00
parent d8bd4ec5c4
commit 8675fd48ac
2 changed files with 27 additions and 10 deletions
+17 -7
View File
@@ -1,5 +1,5 @@
import React from 'react' import React from 'react'
import {Pressable, View} from 'react-native' import {DimensionValue, Pressable, View} from 'react-native'
import {Image} from 'expo-image' import {Image} from 'expo-image'
import {AppBskyEmbedImages} from '@atproto/api' import {AppBskyEmbedImages} from '@atproto/api'
import {msg} from '@lingui/macro' import {msg} from '@lingui/macro'
@@ -46,17 +46,25 @@ export function SquareFramedImage({
children: React.ReactNode children: React.ReactNode
}) { }) {
const t = useTheme() const t = useTheme()
const outerAspectRatio = React.useMemo(() => { /**
return Math.min(1 / aspectRatio, 1) * Computed as a % value to apply as `paddingTop`
*/
const outerAspectRatio = React.useMemo<DimensionValue>(() => {
// capped to square or shorter
const ratio = Math.min(1 / aspectRatio, 1)
return `${ratio * 100}%`
}, [aspectRatio]) }, [aspectRatio])
/**
* Computed as a CSS `aspectRatio` value
*/
const innerAspectRatio = React.useMemo(() => { const innerAspectRatio = React.useMemo(() => {
// max of 3:4 ratio
return Math.max(aspectRatio, 0.75) return Math.max(aspectRatio, 0.75)
}, [aspectRatio]) }, [aspectRatio])
return ( return (
<View style={[a.w_full]}> <View style={[a.w_full]}>
<View <View style={[a.overflow_hidden, {paddingTop: outerAspectRatio}]}>
style={[a.overflow_hidden, {paddingTop: `${outerAspectRatio * 100}%`}]}>
<View style={[a.absolute, a.inset_0, a.flex_row]}> <View style={[a.absolute, a.inset_0, a.flex_row]}>
<View <View
style={[ style={[
@@ -113,8 +121,9 @@ export function AutoSizedImage({
onPress={onPress} onPress={onPress}
onLongPress={onLongPress} onLongPress={onLongPress}
onPressIn={onPressIn} onPressIn={onPressIn}
// alt here is what screen readers actually use
accessibilityLabel={image.alt} accessibilityLabel={image.alt}
accessibilityHint={_(msg`Tap to view fully`)} accessibilityHint={_(msg`Tap to view full image`)}
style={[ style={[
a.w_full, a.w_full,
a.rounded_sm, a.rounded_sm,
@@ -133,8 +142,9 @@ export function AutoSizedImage({
onPress={onPress} onPress={onPress}
onLongPress={onLongPress} onLongPress={onLongPress}
onPressIn={onPressIn} onPressIn={onPressIn}
// alt here is what screen readers actually use
accessibilityLabel={image.alt} accessibilityLabel={image.alt}
accessibilityHint={_(msg`Tap to view fully`)} accessibilityHint={_(msg`Tap to view full image`)}
style={[a.h_full]}> style={[a.h_full]}>
{contents} {contents}
{children} {children}
+10 -3
View File
@@ -7,7 +7,7 @@ import {useLingui} from '@lingui/react'
import {isWeb} from '#/platform/detection' import {isWeb} from '#/platform/detection'
import {useLargeAltBadgeEnabled} from '#/state/preferences/large-alt-badge' import {useLargeAltBadgeEnabled} from '#/state/preferences/large-alt-badge'
import {atoms as a} from '#/alf' import {atoms as a, useTheme} from '#/alf'
type EventFunction = (index: number) => void type EventFunction = (index: number) => void
@@ -28,6 +28,7 @@ export const GalleryItem: FC<GalleryItemProps> = ({
onPressIn, onPressIn,
onLongPress, onLongPress,
}) => { }) => {
const t = useTheme()
const {_} = useLingui() const {_} = useLingui()
const largeAltBadge = useLargeAltBadgeEnabled() const largeAltBadge = useLargeAltBadgeEnabled()
const image = images[index] const image = images[index]
@@ -37,13 +38,19 @@ export const GalleryItem: FC<GalleryItemProps> = ({
onPress={onPress ? () => onPress(index) : undefined} onPress={onPress ? () => onPress(index) : undefined}
onPressIn={onPressIn ? () => onPressIn(index) : undefined} onPressIn={onPressIn ? () => onPressIn(index) : undefined}
onLongPress={onLongPress ? () => onLongPress(index) : undefined} onLongPress={onLongPress ? () => onLongPress(index) : undefined}
style={a.flex_1} style={[
a.flex_1,
a.rounded_xs,
a.overflow_hidden,
t.atoms.bg_contrast_25,
imageStyle,
]}
accessibilityRole="button" accessibilityRole="button"
accessibilityLabel={image.alt || _(msg`Image`)} accessibilityLabel={image.alt || _(msg`Image`)}
accessibilityHint=""> accessibilityHint="">
<Image <Image
source={{uri: image.thumb}} source={{uri: image.thumb}}
style={[a.flex_1, a.rounded_xs, imageStyle]} style={[a.flex_1]}
accessible={true} accessible={true}
accessibilityLabel={image.alt} accessibilityLabel={image.alt}
accessibilityHint="" accessibilityHint=""