halilb / react-native-textinput-effects

Text inputs with custom label and icon animations for iOS and android. Built with react native and inspired by Codrops.
MIT License
2.98k stars 291 forks source link

Hoshi label color to change on Focus? #123

Closed gaurav-psych closed 3 years ago

gaurav-psych commented 3 years ago

I want to change the label color when the input field is focused or user taps and tries to enter text. Is it possible?

halilb commented 3 years ago

Hi @gaurav-psych,

You'd need to pass labelStyle prop to change the label color. And you may listen onFocus onBlur methods to have a focused state.

So something like this should work. I haven't tried it but you'd probably achieve what you want with a few changes:

import React, { useState } from 'react'
import { Hoshi } from 'react-native-textinput-effects';

const [isFocused, setIsFocused] = useState(false)
const labelColor = isFocused ? 'red' : 'yellow'

const hoshiInput = (
  <Hoshi
    labelStyle={{
      color: labelColor,
    }}
    label={'Town'}
    // this is used as active border color
    borderColor={labelColor}
   onBlur={() => setIsFocused(false)}
   onFocus={() => setIsFocused(true)}
  />
);