Show image count badge on in-feed carousel (#10719)
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import {StyleSheet, View} from 'react-native'
|
import {StyleSheet, View} from 'react-native'
|
||||||
|
import {BlurView} from 'expo-blur'
|
||||||
import {atoms as a} from '#/alf'
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
count: number
|
count: number
|
||||||
@@ -14,26 +13,38 @@ const GAP = 5
|
|||||||
export function PagerDots({count, activeIndex}: Props) {
|
export function PagerDots({count, activeIndex}: Props) {
|
||||||
if (count <= 1) return null
|
if (count <= 1) return null
|
||||||
return (
|
return (
|
||||||
<View style={[a.flex_row, a.align_center, a.justify_center, styles.row]}>
|
<View style={styles.root}>
|
||||||
{Array.from({length: count}).map((_, i) => {
|
<BlurView intensity={20} tint="dark" style={styles.inner}>
|
||||||
const isActive = i === activeIndex
|
{Array.from({length: count}).map((_, i) => {
|
||||||
return (
|
const isActive = i === activeIndex
|
||||||
<View
|
return (
|
||||||
key={i}
|
<View
|
||||||
style={[
|
key={i}
|
||||||
isActive ? styles.active : styles.inactive,
|
style={[
|
||||||
isActive ? styles.activeDot : styles.inactiveDot,
|
isActive ? styles.active : styles.inactive,
|
||||||
]}
|
isActive ? styles.activeDot : styles.inactiveDot,
|
||||||
/>
|
]}
|
||||||
)
|
/>
|
||||||
})}
|
)
|
||||||
|
})}
|
||||||
|
</BlurView>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
row: {
|
root: {
|
||||||
|
borderRadius: 999,
|
||||||
|
overflow: 'hidden',
|
||||||
|
},
|
||||||
|
inner: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
gap: GAP,
|
gap: GAP,
|
||||||
|
paddingHorizontal: 10,
|
||||||
|
paddingVertical: 6,
|
||||||
|
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
||||||
},
|
},
|
||||||
activeDot: {
|
activeDot: {
|
||||||
width: ACTIVE,
|
width: ACTIVE,
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import {StyleSheet, View} from 'react-native'
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
count: number
|
||||||
|
activeIndex: number
|
||||||
|
}
|
||||||
|
|
||||||
|
const ACTIVE = 6
|
||||||
|
const INACTIVE = 4
|
||||||
|
const GAP = 5
|
||||||
|
|
||||||
|
export function PagerDots({count, activeIndex}: Props) {
|
||||||
|
if (count <= 1) return null
|
||||||
|
return (
|
||||||
|
<View style={styles.root}>
|
||||||
|
{Array.from({length: count}).map((_, i) => {
|
||||||
|
const isActive = i === activeIndex
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
key={i}
|
||||||
|
style={[
|
||||||
|
isActive ? styles.active : styles.inactive,
|
||||||
|
isActive ? styles.activeDot : styles.inactiveDot,
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
root: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: GAP,
|
||||||
|
paddingHorizontal: 10,
|
||||||
|
paddingVertical: 6,
|
||||||
|
borderRadius: 999,
|
||||||
|
backgroundColor: 'rgba(0, 0, 0, 0.75)',
|
||||||
|
// @ts-expect-error web-only
|
||||||
|
backdropFilter: 'blur(8px)',
|
||||||
|
WebkitBackdropFilter: 'blur(8px)',
|
||||||
|
},
|
||||||
|
activeDot: {
|
||||||
|
width: ACTIVE,
|
||||||
|
height: ACTIVE,
|
||||||
|
borderRadius: ACTIVE / 2,
|
||||||
|
},
|
||||||
|
inactiveDot: {
|
||||||
|
width: INACTIVE,
|
||||||
|
height: INACTIVE,
|
||||||
|
borderRadius: INACTIVE / 2,
|
||||||
|
},
|
||||||
|
active: {
|
||||||
|
backgroundColor: '#fff',
|
||||||
|
},
|
||||||
|
inactive: {
|
||||||
|
backgroundColor: 'rgba(255, 255, 255, 0.4)',
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -491,6 +491,35 @@ function GalleryImage({
|
|||||||
useAppleWebpCodec
|
useAppleWebpCodec
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{!hideBadges && imageCount > 1 ? (
|
||||||
|
<View
|
||||||
|
accessible={false}
|
||||||
|
pointerEvents="none"
|
||||||
|
style={[
|
||||||
|
a.absolute,
|
||||||
|
a.justify_center,
|
||||||
|
a.rounded_sm,
|
||||||
|
a.p_xs,
|
||||||
|
t.atoms.bg_contrast_25,
|
||||||
|
{
|
||||||
|
top: a.p_xs.padding,
|
||||||
|
right: a.p_xs.padding,
|
||||||
|
opacity: 0.8,
|
||||||
|
},
|
||||||
|
largeAltBadge && {
|
||||||
|
padding: 6,
|
||||||
|
},
|
||||||
|
]}>
|
||||||
|
<Text
|
||||||
|
style={[
|
||||||
|
a.font_bold,
|
||||||
|
largeAltBadge ? a.text_xs : {fontSize: 8},
|
||||||
|
]}>
|
||||||
|
{index + 1}/{imageCount}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
{(hasAlt || isCropped) && !hideBadges ? (
|
{(hasAlt || isCropped) && !hideBadges ? (
|
||||||
<View
|
<View
|
||||||
accessible={false}
|
accessible={false}
|
||||||
|
|||||||
Reference in New Issue
Block a user