0

Code below working as expected, all I need when click other button, it should animate the change of background color(active item is light-blue).

Default background color of buttons is gray(shade04), when its clicked I need it to fade backgroundColor to lightblue(color.bluePurple) with animation

component:

export const TabController = (props: TabControllerProps) => {
  const { index, activeTab, setActiveTab, containerStyle } = props

  return (
    <>
      <View style={TABS}>
        <View style={{ ...CONTAINER, ...containerStyle }}>
          <TouchableOpacity
            onPress={() => {
              setActiveTab(0)
            }}
            style={{
              backgroundColor: activeTab === 0 ? color.bluePurple : color.shade04,
              ...TAB_BTN,
            }}
          >
            <View
              style={{
                flex: 1,
                flexDirection: 'row',
                justifyContent: 'center',
                alignItems: 'center',
              }}
            >
              <Text tx={'Topics'} preset="body1Emphasized" />
            </View>
          </TouchableOpacity>
          <TouchableOpacity
            onPress={() => {
              setActiveTab(1)
            }}
            style={{
              backgroundColor: activeTab === 1 ? color.bluePurple : color.shade04,
              ...TAB_BTN,
            }}
          >
            <View
              style={{
                flex: 1,
                flexDirection: 'row',
                justifyContent: 'center',
                alignItems: 'center',
              }}
            >
              <Text
                style={activeTab === 1 ? ACTIVE : NORMAL}
                tx={'Quiz'}
                preset="body1Emphasized"
              />
            </View>
          </TouchableOpacity>
        </View>
      </View>
    </>
  )
}

I seached any tried to leverage Animated.View but still got trouble..

TrypicalDev
  • 101
  • 8

0 Answers0