1

I get this error even I change: inputIndex === i ? 255: 0 to inputIndex === i ? "#ffffff" : "#aaa2d7".

the purpose, is when the first tab is active the title color should be white "#ffffff" and others tabs should be "#aaa2d7"

    const inputRange = props.navigationState.routes.map((x, i) => i);
    return (
      <View style={{backgroundColor: "#5243af",flexDirection: 'row', height: Metrics.HEIGHT * 0.1, elevation: 0}}> 
        { props.navigationState.routes.map((route, i) => {
          const color = Animated.color(
            Animated.round(
              Animated.interpolate(props.position, {
                inputRange,
                outputRange: inputRange.map(inputIndex =>
                  inputIndex === i ? "#ffffff" : "#aaa2d7"
                ),
              })
            ),
            0,
            0
          );
          return (
            <TouchableOpacity
              style={{flex: 1, alignItems: 'center', borderLeftColor: "#9a91d2", borderLeftWidth: 1/* , borderBottomWidth: 3, borderBottomColor "red" */}}
              key={i}
              onPress={() => {
                //this.changeTabs(route.key)
                this.setState({ index: i })
              }}>
              {this._getTabBarIcon(route.key)}
              <Animated.Text style={{ color, fontSize: Fonts.moderateScale(15), marginBottom: 10 }}>{route.title.toLocaleUpperCase()}</Animated.Text>
            </TouchableOpacity>
          );
        })}
      </View>
    );
  }

thank you

hanae
  • 91
  • 4
  • 18
  • 1
    You may need the `outputRange` values in the format of `Animated.color(r, g, b)` instead of `"#RRGGBB"` – Zaytri Nov 25 '19 at 20:20
  • @zaytrix thank you for the help, I have changed outputRange as you said: ```outputRange: inputRange.map(inputIndex => inputIndex === i ? Animated.color(255, 255, 255) : Animated.color(170,170,173) )```, at the moment no error but still the active tab red and others black, I want to active color tab white and others on rgb(170, 170, 173) – hanae Nov 26 '19 at 08:55

1 Answers1

0

You can try something like this.

const scrollY = new Animated.Value(0);

const bgColor = Animated.interpolate(scrollY, {
                inputRange: [0, HEADER_HEIGHT], 
                outputRange: [Animated.color(56, 180, 113, 0),                        Animated.color(56, 180, 113, 1)]
                })
Tim Garcia
  • 21
  • 2