@@ -12,9 +12,9 @@ import Animated, {
|
|||||||
useSharedValue,
|
useSharedValue,
|
||||||
} from 'react-native-reanimated'
|
} from 'react-native-reanimated'
|
||||||
|
|
||||||
import {usePalette} from '#/lib/hooks/usePalette'
|
import {PressableWithHover} from '#/view/com/util/PressableWithHover'
|
||||||
import {PressableWithHover} from '../util/PressableWithHover'
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
import {Text} from '../util/text/Text'
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
export interface TabBarProps {
|
export interface TabBarProps {
|
||||||
testID?: string
|
testID?: string
|
||||||
@@ -41,7 +41,7 @@ export function TabBar({
|
|||||||
dragProgress,
|
dragProgress,
|
||||||
dragState,
|
dragState,
|
||||||
}: TabBarProps) {
|
}: TabBarProps) {
|
||||||
const pal = usePalette('default')
|
const t = useTheme()
|
||||||
const scrollElRef = useAnimatedRef<ScrollView>()
|
const scrollElRef = useAnimatedRef<ScrollView>()
|
||||||
const syncScrollState = useSharedValue<'synced' | 'unsynced' | 'needs-sync'>(
|
const syncScrollState = useSharedValue<'synced' | 'unsynced' | 'needs-sync'>(
|
||||||
'synced',
|
'synced',
|
||||||
@@ -264,7 +264,7 @@ export function TabBar({
|
|||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
testID={testID}
|
testID={testID}
|
||||||
style={[pal.view, styles.outer]}
|
style={[t.atoms.bg, a.flex_row]}
|
||||||
accessibilityRole="tablist">
|
accessibilityRole="tablist">
|
||||||
<ScrollView
|
<ScrollView
|
||||||
testID={`${testID}-selector`}
|
testID={`${testID}-selector`}
|
||||||
@@ -309,14 +309,14 @@ export function TabBar({
|
|||||||
left: 0,
|
left: 0,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
borderBottomWidth: 3,
|
borderBottomWidth: 2,
|
||||||
borderColor: pal.link.color,
|
borderColor: t.palette.primary_500,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
<View style={[pal.border, styles.outerBottomBorder]} />
|
<View style={[t.atoms.border_contrast_low, styles.outerBottomBorder]} />
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -336,7 +336,7 @@ function TabBarItem({
|
|||||||
onPressItem: (index: number) => void
|
onPressItem: (index: number) => void
|
||||||
onItemLayout: (index: number, layout: {x: number; width: number}) => void
|
onItemLayout: (index: number, layout: {x: number; width: number}) => void
|
||||||
}) {
|
}) {
|
||||||
const pal = usePalette('default')
|
const t = useTheme()
|
||||||
const style = useAnimatedStyle(() => {
|
const style = useAnimatedStyle(() => {
|
||||||
if (!_WORKLET) {
|
if (!_WORKLET) {
|
||||||
return {opacity: 0.7}
|
return {opacity: 0.7}
|
||||||
@@ -363,15 +363,14 @@ function TabBarItem({
|
|||||||
<PressableWithHover
|
<PressableWithHover
|
||||||
testID={`${testID}-selector-${index}`}
|
testID={`${testID}-selector-${index}`}
|
||||||
style={styles.item}
|
style={styles.item}
|
||||||
hoverStyle={pal.viewLight}
|
hoverStyle={t.atoms.bg_contrast_25}
|
||||||
onPress={() => onPressItem(index)}
|
onPress={() => onPressItem(index)}
|
||||||
accessibilityRole="tab">
|
accessibilityRole="tab">
|
||||||
<Animated.View style={[style, styles.itemInner]}>
|
<Animated.View style={[style, styles.itemInner]}>
|
||||||
<Text
|
<Text
|
||||||
emoji
|
emoji
|
||||||
type="lg-bold"
|
|
||||||
testID={testID ? `${testID}-${item}` : undefined}
|
testID={testID ? `${testID}-${item}` : undefined}
|
||||||
style={[pal.text, {lineHeight: 20}]}>
|
style={[t.atoms.text, a.text_md, a.font_bold, {lineHeight: 20}]}>
|
||||||
{item}
|
{item}
|
||||||
</Text>
|
</Text>
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
@@ -381,9 +380,6 @@ function TabBarItem({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
outer: {
|
|
||||||
flexDirection: 'row',
|
|
||||||
},
|
|
||||||
contentContainer: {
|
contentContainer: {
|
||||||
backgroundColor: 'transparent',
|
backgroundColor: 'transparent',
|
||||||
paddingHorizontal: CONTENT_PADDING,
|
paddingHorizontal: CONTENT_PADDING,
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import {useCallback, useEffect, useMemo, useRef} from 'react'
|
import {useCallback, useEffect, useRef} from 'react'
|
||||||
import {ScrollView, StyleSheet, View} from 'react-native'
|
import {ScrollView, StyleSheet, View} from 'react-native'
|
||||||
|
|
||||||
import {usePalette} from '#/lib/hooks/usePalette'
|
import {atoms as a, useBreakpoints, useTheme} from '#/alf'
|
||||||
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
|
import {Text} from '#/components/Typography'
|
||||||
import {PressableWithHover} from '../util/PressableWithHover'
|
import {PressableWithHover} from '../util/PressableWithHover'
|
||||||
import {Text} from '../util/text/Text'
|
|
||||||
import {DraggableScrollView} from './DraggableScrollView'
|
import {DraggableScrollView} from './DraggableScrollView'
|
||||||
|
|
||||||
export interface TabBarProps {
|
export interface TabBarProps {
|
||||||
@@ -12,6 +11,8 @@ export interface TabBarProps {
|
|||||||
selectedPage: number
|
selectedPage: number
|
||||||
items: string[]
|
items: string[]
|
||||||
indicatorColor?: string
|
indicatorColor?: string
|
||||||
|
backgroundColor?: string
|
||||||
|
|
||||||
onSelect?: (index: number) => void
|
onSelect?: (index: number) => void
|
||||||
onPressSelected?: (index: number) => void
|
onPressSelected?: (index: number) => void
|
||||||
}
|
}
|
||||||
@@ -28,15 +29,14 @@ export function TabBar({
|
|||||||
onSelect,
|
onSelect,
|
||||||
onPressSelected,
|
onPressSelected,
|
||||||
}: TabBarProps) {
|
}: TabBarProps) {
|
||||||
const pal = usePalette('default')
|
const t = useTheme()
|
||||||
const scrollElRef = useRef<ScrollView>(null)
|
const scrollElRef = useRef<ScrollView>(null)
|
||||||
const itemRefs = useRef<Array<Element>>([])
|
const itemRefs = useRef<Array<Element>>([])
|
||||||
const indicatorStyle = useMemo(
|
const indicatorStyle = {
|
||||||
() => ({borderBottomColor: indicatorColor || pal.colors.link}),
|
borderBottomColor: indicatorColor || t.palette.primary_500,
|
||||||
[indicatorColor, pal],
|
}
|
||||||
)
|
const {gtMobile} = useBreakpoints()
|
||||||
const {isDesktop, isTablet} = useWebMediaQueries()
|
const styles = gtMobile ? desktopStyles : mobileStyles
|
||||||
const styles = isDesktop || isTablet ? desktopStyles : mobileStyles
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// On the web, the primary interaction is tapping.
|
// On the web, the primary interaction is tapping.
|
||||||
@@ -96,7 +96,7 @@ export function TabBar({
|
|||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
testID={testID}
|
testID={testID}
|
||||||
style={[pal.view, styles.outer]}
|
style={[t.atoms.bg, styles.outer]}
|
||||||
accessibilityRole="tablist">
|
accessibilityRole="tablist">
|
||||||
<DraggableScrollView
|
<DraggableScrollView
|
||||||
testID={`${testID}-selector`}
|
testID={`${testID}-selector`}
|
||||||
@@ -112,16 +112,17 @@ export function TabBar({
|
|||||||
key={`${item}-${i}`}
|
key={`${item}-${i}`}
|
||||||
ref={node => (itemRefs.current[i] = node as any)}
|
ref={node => (itemRefs.current[i] = node as any)}
|
||||||
style={styles.item}
|
style={styles.item}
|
||||||
hoverStyle={pal.viewLight}
|
hoverStyle={t.atoms.bg_contrast_25}
|
||||||
onPress={() => onPressItem(i)}
|
onPress={() => onPressItem(i)}
|
||||||
accessibilityRole="tab">
|
accessibilityRole="tab">
|
||||||
<View style={[styles.itemInner, selected && indicatorStyle]}>
|
<View style={[styles.itemInner, selected && indicatorStyle]}>
|
||||||
<Text
|
<Text
|
||||||
emoji
|
emoji
|
||||||
type={isDesktop || isTablet ? 'xl-bold' : 'lg-bold'}
|
|
||||||
testID={testID ? `${testID}-${item}` : undefined}
|
testID={testID ? `${testID}-${item}` : undefined}
|
||||||
style={[
|
style={[
|
||||||
selected ? pal.text : pal.textLight,
|
selected ? t.atoms.text : t.atoms.text_contrast_medium,
|
||||||
|
a.text_md,
|
||||||
|
a.font_bold,
|
||||||
{lineHeight: 20},
|
{lineHeight: 20},
|
||||||
]}>
|
]}>
|
||||||
{item}
|
{item}
|
||||||
@@ -131,7 +132,7 @@ export function TabBar({
|
|||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
</DraggableScrollView>
|
</DraggableScrollView>
|
||||||
<View style={[pal.border, styles.outerBottomBorder]} />
|
<View style={[t.atoms.border_contrast_low, styles.outerBottomBorder]} />
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -179,7 +180,7 @@ const mobileStyles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
itemInner: {
|
itemInner: {
|
||||||
paddingBottom: 10,
|
paddingBottom: 10,
|
||||||
borderBottomWidth: 3,
|
borderBottomWidth: 2,
|
||||||
borderBottomColor: 'transparent',
|
borderBottomColor: 'transparent',
|
||||||
},
|
},
|
||||||
outerBottomBorder: {
|
outerBottomBorder: {
|
||||||
|
|||||||
Reference in New Issue
Block a user