# All files / form FormInput.js

55.56% Statements 5/9
100% Branches 4/4
33.33% Functions 1/3
55.56% Lines 5/9

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85

    1x

    4x
    4x

    1x

    1x

     import PropTypes from 'prop-types';
    import React, { Component } from 'react';
    import {
      TextInput,
      StyleSheet,
      View,
      Platform,
      Dimensions,
      Text as NativeText,
    } from 'react-native';
    import colors from '../config/colors';
    import normalize from '../helpers/normalizeText';

    const { width } = Dimensions.get('window');

    class FormInput extends Component {
      focus() {
        const ref = this.props.textInputRef;
        this.refs[ref].focus();
      }
      blur() {
        const ref = this.props.textInputRef;
        this.refs[ref].blur();
      }
      render() {
        const {
          containerStyle,
          inputStyle,
          textInputRef,
          containerRef,
          ...attributes
        } = this.props;
        return (
          <View
            ref={containerRef}
            style={[styles.container, containerStyle && containerStyle]}
          >
            <TextInput
              ref={textInputRef}
              style={[styles.input, inputStyle && inputStyle]}
              {...attributes}
            />
          </View>
        );
      }
    }

    FormInput.propTypes = {
      containerStyle: View.propTypes.style,
      inputStyle: NativeText.propTypes.style,
      textInputRef: PropTypes.string,
      containerRef: PropTypes.string,
    };

    const styles = StyleSheet.create({
      container: {
        marginLeft: 15,
        marginRight: 15,
        ...Platform.select({
          ios: {
            borderBottomColor: colors.grey4,
            borderBottomWidth: 1,
            marginLeft: 20,
            marginRight: 20,
          },
        }),
      },
      input: {
        ...Platform.select({
          android: {
            minHeight: 46,
            width: width - 30,
          },
          ios: {
            minHeight: 36,
            width: width,
          },
        }),
        color: colors.grey3,
        fontSize: normalize(14),
      },
    });

    export default FormInput;