Integrate ViewSelector into design system
parent
b47714fb11
commit
efaf8a54b8
|
@ -6,7 +6,7 @@ import {
|
||||||
View,
|
View,
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import {Text} from './text/Text'
|
import {Text} from './text/Text'
|
||||||
import {colors} from '../../lib/styles'
|
import {usePalette} from '../../lib/hooks/usePalette'
|
||||||
|
|
||||||
interface Layout {
|
interface Layout {
|
||||||
x: number
|
x: number
|
||||||
|
@ -24,6 +24,7 @@ export function Selector({
|
||||||
panX: Animated.Value
|
panX: Animated.Value
|
||||||
onSelect?: (index: number) => void
|
onSelect?: (index: number) => void
|
||||||
}) {
|
}) {
|
||||||
|
const pal = usePalette('default')
|
||||||
const [itemLayouts, setItemLayouts] = useState<undefined | Layout[]>(
|
const [itemLayouts, setItemLayouts] = useState<undefined | Layout[]>(
|
||||||
undefined,
|
undefined,
|
||||||
)
|
)
|
||||||
|
@ -43,6 +44,7 @@ export function Selector({
|
||||||
}, [selectedIndex, items, itemLayouts])
|
}, [selectedIndex, items, itemLayouts])
|
||||||
|
|
||||||
const underlineStyle = {
|
const underlineStyle = {
|
||||||
|
backgroundColor: pal.colors.text,
|
||||||
left: panX.interpolate({
|
left: panX.interpolate({
|
||||||
inputRange: [-1, 0, 1],
|
inputRange: [-1, 0, 1],
|
||||||
outputRange: [
|
outputRange: [
|
||||||
|
@ -84,14 +86,19 @@ export function Selector({
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[styles.outer]} onLayout={onLayout}>
|
<View style={[pal.view, styles.outer]} onLayout={onLayout}>
|
||||||
<Animated.View style={[styles.underline, underlineStyle]} />
|
<Animated.View style={[styles.underline, underlineStyle]} />
|
||||||
{items.map((item, i) => {
|
{items.map((item, i) => {
|
||||||
const selected = i === selectedIndex
|
const selected = i === selectedIndex
|
||||||
return (
|
return (
|
||||||
<TouchableWithoutFeedback key={i} onPress={() => onPressItem(i)}>
|
<TouchableWithoutFeedback key={i} onPress={() => onPressItem(i)}>
|
||||||
<View style={styles.item} ref={itemRefs[i]}>
|
<View style={styles.item} ref={itemRefs[i]}>
|
||||||
<Text style={selected ? styles.labelSelected : styles.itemLabel}>
|
<Text
|
||||||
|
style={
|
||||||
|
selected
|
||||||
|
? [styles.labelSelected, pal.text]
|
||||||
|
: [styles.label, pal.textLight]
|
||||||
|
}>
|
||||||
{item}
|
{item}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
|
@ -108,26 +115,20 @@ const styles = StyleSheet.create({
|
||||||
paddingTop: 8,
|
paddingTop: 8,
|
||||||
paddingBottom: 12,
|
paddingBottom: 12,
|
||||||
paddingHorizontal: 14,
|
paddingHorizontal: 14,
|
||||||
backgroundColor: colors.white,
|
|
||||||
},
|
},
|
||||||
item: {
|
item: {
|
||||||
marginRight: 14,
|
marginRight: 14,
|
||||||
paddingHorizontal: 10,
|
paddingHorizontal: 10,
|
||||||
},
|
},
|
||||||
itemLabel: {
|
label: {
|
||||||
fontWeight: '600',
|
fontWeight: '600',
|
||||||
fontSize: 16,
|
|
||||||
color: colors.gray5,
|
|
||||||
},
|
},
|
||||||
labelSelected: {
|
labelSelected: {
|
||||||
fontWeight: '600',
|
fontWeight: '600',
|
||||||
fontSize: 16,
|
|
||||||
color: colors.black,
|
|
||||||
},
|
},
|
||||||
underline: {
|
underline: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
height: 4,
|
height: 4,
|
||||||
backgroundColor: colors.black,
|
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
import React, {useEffect, useState} from 'react'
|
import React, {useEffect, useState} from 'react'
|
||||||
import {
|
import {FlatList, View} from 'react-native'
|
||||||
FlatList,
|
|
||||||
NativeSyntheticEvent,
|
|
||||||
NativeScrollEvent,
|
|
||||||
View,
|
|
||||||
} from 'react-native'
|
|
||||||
import {Selector} from './Selector'
|
import {Selector} from './Selector'
|
||||||
import {HorzSwipe} from './gestures/HorzSwipe'
|
import {HorzSwipe} from './gestures/HorzSwipe'
|
||||||
import {useAnimatedValue} from '../../lib/hooks/useAnimatedValue'
|
import {useAnimatedValue} from '../../lib/hooks/useAnimatedValue'
|
||||||
|
|
Loading…
Reference in New Issue