### Install react-native-confirmation-code-field Source: https://github.com/retyui/react-native-confirmation-code-field/blob/master/README.md This snippet shows how to install the react-native-confirmation-code-field library using Yarn. ```sh yarn add react-native-confirmation-code-field ``` -------------------------------- ### Installation Compatibility Source: https://github.com/retyui/react-native-confirmation-code-field/blob/master/README.md Information on which version of `react-native-confirmation-code-field` to install based on your React Native version. For React Native 0.63.x and below, use version 6. For newer versions, install the latest release. ```bash yarn add react-native-confirmation-code-field@6 // For react-native@0.63.x and below yarn add react-native-confirmation-code-field // For latest version ``` -------------------------------- ### Underline Example Fix Source: https://github.com/retyui/react-native-confirmation-code-field/blob/master/examples/DemoCodeField/src/UnderlineExample/README.md This snippet shows the correct way to render a cell for the confirmation code field with an underline style. It addresses a React Native bug related to border styles on iOS by wrapping the Text component in a View and moving the onLayout handler to the View. ```javascript // BAD 👎 renderCell={({index, symbol, isFocused}) => ( {...} )} // GOOD ✔️ renderCell={({index, symbol, isFocused}) => ( {...} )} ``` -------------------------------- ### Basic Confirmation Code Input (React Native) Source: https://github.com/retyui/react-native-confirmation-code-field/blob/master/README.md This snippet demonstrates a fundamental implementation of a confirmation code input field using the react-native-confirmation-code-field library. It utilizes hooks like `useBlurOnFulfill` and `useClearByFocusCell` for managing focus and clearing input. The example includes basic styling for the input cells and handles different auto-complete behaviors for Android and other platforms. ```tsx import React, {useState} from 'react'; import {SafeAreaView, Text, StyleSheet, Platform} from 'react-native'; import type {TextInputProps} from 'react-native'; import { CodeField, Cursor, useBlurOnFulfill, useClearByFocusCell, } from 'react-native-confirmation-code-field'; const styles = StyleSheet.create({ root: {flex: 1, padding: 20}, title: {textAlign: 'center', fontSize: 30}, codeFieldRoot: {marginTop: 20}, cell: { width: 40, height: 40, lineHeight: 38, fontSize: 24, borderWidth: 2, borderColor: '#00000030', textAlign: 'center', color: '#000', // text color }, focusCell: { borderColor: '#000', }, }); const CELL_COUNT = 6; const autoComplete = Platform.select({ android: 'sms-otp', default: 'one-time-code', }); function App() { const [value, setValue] = useState(''); const ref = useBlurOnFulfill({value, cellCount: CELL_COUNT}); const [props, getCellOnLayoutHandler] = useClearByFocusCell({ value, setValue, }); return ( Verification ( {symbol || (isFocused && )} )} /> ); }; export default App; ``` -------------------------------- ### JSX Structure for Confirmation Code Field Source: https://github.com/retyui/react-native-confirmation-code-field/blob/master/README.md This JSX structure illustrates the component's internal layout, featuring a root view containing individual Cell components and an invisible TextInput for input handling. This setup is designed to manage code input and display. ```jsx // Root view (rectangle with a red border on 3d visualization below) // Each Cell element is result of a `renderCell` function (gray boxes) 1 2 3 | // Invisible Text Input with absolute position (gray rectangle with text '123') ``` -------------------------------- ### useClearByFocusCell Hook for React Native Source: https://github.com/retyui/react-native-confirmation-code-field/blob/master/API.md This hook adds functionality to clear input values based on the focused cell in a confirmation code field. It returns props to spread onto the CodeField component and a helper to get onLayout handlers for each cell. It also includes a workaround for React Native's border style issues on iOS. ```javascript import { CodeField, useClearByFocusCell, } from 'react-native-confirmation-code-field'; const App = () => { const [codeFieldProps, getCellOnLayout] = useClearByFocusCell({ value, setValue, }); return ( ( {symbol} )} /> ); }; ``` -------------------------------- ### CodeField Component API Source: https://github.com/retyui/react-native-confirmation-code-field/blob/master/API.md The base CodeField component renders a root component with cells and an invisible text input. It inherits TextInput props and allows customization of root and input components, styles, and props. ```APIDOC CodeField: cellCount?: number - Number of characters in input (optional, default: 4) renderCell: (options: {symbol: string, index: number, isFocused: boolean}) => ReactElement - Required function for Cell rendering, will be invoke with next options: - symbol: string - index: number - isFocused: boolean RootComponent?: ComponentType - If you want change root component for example using animations RootComponent={Animated.View} (optional, default View) InputComponent?: ComponentType - If you want to provide a custom TextInput component that can receive the same props (optional, default TextInput) rootStyle?: StyleProp - Styles for root component (optional) RootProps?: Object - Any props that will applied for root component textInputStyle?: StyleProp - Styles for invisible , can be used for testing or debug (optional) ``` -------------------------------- ### useBlurOnFulfill Hook Source: https://github.com/retyui/react-native-confirmation-code-field/blob/master/API.md The useBlurOnFulfill hook automatically blurs the input when the user has entered the required number of characters. It takes the current input value and the total cell count, returning a ref to the TextInput. ```APIDOC useBlurOnFulfill({value?: string, cellCount: number}): Ref ``` -------------------------------- ### Cursor Component Usage Source: https://github.com/retyui/react-native-confirmation-code-field/blob/master/API.md The Cursor component is a helper for simulating cursor blinking animation within Cell components. It accepts optional delay and cursor symbol props. ```javascript import { Cursor } from 'react-native-confirmation-code-field'; ; ``` -------------------------------- ### useBlurOnFulfill Hook for React Native Source: https://github.com/retyui/react-native-confirmation-code-field/blob/master/API.md This hook automatically blurs the TextInput component when the entered value reaches the specified cell count. It returns a ref that should be passed to the CodeField component. It integrates well with the useClearByFocusCell hook. ```javascript import { CodeField, useBlurOnFulfill, } from 'react-native-confirmation-code-field'; const App = () => { const CELL_COUNT = 4; const ref = useBlurOnFulfill({value, cellCount: CELL_COUNT}); return ( ); }; ``` -------------------------------- ### useClearByFocusCell Hook Source: https://github.com/retyui/react-native-confirmation-code-field/blob/master/API.md The useClearByFocusCell hook is designed to clear the input field when it gains focus. It requires the current input value and a function to set the value. ```APIDOC useClearByFocusCell({value?: string, setValue: (text: string) => void}) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.