about summary refs log tree commit diff
path: root/src/view/com/util/images/ImageHorzList.tsx
blob: 88494bba3909defe061132974288538c38d32bcd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React from 'react'
import {
  StyleProp,
  StyleSheet,
  TouchableWithoutFeedback,
  View,
  ViewStyle,
} from 'react-native'
import {Image} from 'expo-image'
import {AppBskyEmbedImages} from '@atproto/api'

interface Props {
  images: AppBskyEmbedImages.ViewImage[]
  onPress?: (index: number) => void
  style?: StyleProp<ViewStyle>
}

export function ImageHorzList({images, onPress, style}: Props) {
  const numImages = images.length
  return (
    <View style={[styles.flexRow, style]}>
      {images.map(({thumb, alt}, i) => (
        <TouchableWithoutFeedback
          key={i}
          onPress={() => onPress?.(i)}
          accessible={true}
          accessibilityLabel={`Open image ${i} of ${numImages}`}
          accessibilityHint="Opens image in viewer"
          accessibilityActions={[{name: 'press', label: 'Press'}]}
          onAccessibilityAction={action => {
            switch (action.nativeEvent.actionName) {
              case 'press':
                onPress?.(0)
                break
              default:
                break
            }
          }}>
          <Image
            source={{uri: thumb}}
            style={styles.image}
            accessible={true}
            accessibilityIgnoresInvertColors
            accessibilityHint={alt}
            accessibilityLabel=""
          />
        </TouchableWithoutFeedback>
      ))}
    </View>
  )
}

const styles = StyleSheet.create({
  flexRow: {flexDirection: 'row'},
  image: {
    width: 100,
    height: 100,
    borderRadius: 4,
    marginRight: 5,
  },
})