Icon Props

The icon prop group contains all properties related to the left and right icons that can be displayed within the input field. These icons can be used for visual cues or interactive elements like clear buttons or password toggles.

Note: React Native Forminput uses FontAwesome icons by default. Make sure you have installed and set up react-native-vector-icons in your project.

Properties

PropTypeDefaultDescription
leftIconstringundefinedName of the left icon (Icon used: react-native-vector-icons/FontAwesome by default)
leftIconColorstring#666666Color of the left icon
leftIconStyleStyleProp<TextStyle>undefinedStyle object for the left icon
leftIconContainerStyleViewStyleundefinedStyle object for the left icon container
renderLeftIconReactNodeundefinedFunction to render a custom left icon
leftIconSourceIconSourceType'font-awesome'Source of the left icon (e.g., FontAwesome, MaterialIcons, etc.)
leftIconSizenumber20Size of the left icon
leftIconOnPress() => voidundefinedFunction to call when the left icon is pressed
rightIconstringundefinedName of the right icon (Icon used: react-native-vector-icons/FontAwesome by default)
rightIconColorstring#666666Color of the right icon
rightIconStyleStyleProp<TextStyle>undefinedStyle object for the right icon
rightIconContainerStyleViewStyleundefinedStyle object for the right icon container
renderRightIconReactNodeundefinedFunction to render a custom right icon
rightIconSourceIconSourceType'font-awesome'Source of the right icon (e.g., FontAwesome, MaterialIcons, etc.)
rightIconSizenumber20Size of the right icon
rightIconOnPress() => voidundefinedFunction to call when the right icon is pressed
renderRightIconReactNodeundefinedFunction to render a custom right icon

Example

tsx
import { FormInput } from '@react-native-utils/forminput';
import { useState } from 'react';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';

const IconPropsExample = () => {
  const [email, setEmail] = useState('');
  const [isPasswordVisible, setIsPasswordVisible] = useState(false);
  const [password, setPassword] = useState('');
  
  const togglePasswordVisibility = () => setIsPasswordVisible(!isPasswordVisible);

  return (
    <>
      {/* Email input with clear button */}
      <FormInput
        text={{
          labelText: "Email Address",
          placeholderText: "Enter your email",
          value: email,
        }}
        icon={{
          leftIcon: "envelope",
          rightIcon: email ? "times-circle" : undefined,
          leftIconColor: "#3B82F6",
          rightIconColor: "#9CA3AF",
          rightIconOnPress: () => setEmail(''),
          leftIconSize: 20,
          rightIconSize: 22,
          leftIconSource: "font-awesome",
          rightIconSource: "font-awesome",
          leftIconContainerStyle: {
            paddingRight: 8
          }
        }}
        core={{
          onTextChange: setEmail,
          inputType: "email-address",
        }}
      />
      
      {/* Password input with toggle visibility */}
      <FormInput
        text={{
          labelText: "Password",
          placeholderText: "Enter your password",
          value: password,
        }}
        icon={{
          leftIcon: "lock",
          rightIcon: isPasswordVisible ? "eye-slash" : "eye",
          leftIconColor: "#3B82F6",
          rightIconOnPress: togglePasswordVisibility,
          // Example of a custom icon rendering
          renderLeftIcon: <Icon name="lock-outline" size={24} color="#3B82F6" />
        }}
        core={{
          onTextChange: setPassword,
          hiddenText: !isPasswordVisible,
        }}
      />
    </>
  );
};

Notes

  • Icons can be made interactive by providing an onPress handler
  • Use the renderLeftIcon and renderRightIcon props to provide your own icon components
  • Common use cases include:
    • Clear buttons (to reset input value)
    • Password visibility toggles
    • Search icons
    • Currency or unit indicators
  • Icons are properly positioned within the input and respond to the input's focus state