# All files / src/user-event/event-builder text-input.ts

100% Statements 8/8
100% Branches 0/0
100% Functions 7/7
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    86
    87

    4x

    32x

    32x

    1x

    13x

    32x

    2x

    2x

     import { ContentSize } from '../utils/content-size';
    import { TextRange } from '../utils/text-range';

    export const TextInputEventBuilder = {
      /**
       * Experimental values:
       * - iOS: `{"eventCount": 4, "target": 75, "text": "Test"}`
       * - Android: `{"eventCount": 6, "target": 53, "text": "Tes"}`
       */
      change: (text: string) => {
        return {
          nativeEvent: { text, target: 0, eventCount: 0 },
        };
      },

      /**
       * Experimental values:
       * - iOS: `{"eventCount": 3, "key": "a", "target": 75}`
       * - Android: `{"key": "a"}`
       */
      keyPress: (key: string) => {
        return {
          nativeEvent: { key },
        };
      },

      /**
       * Experimental values:
       * - iOS: `{"eventCount": 4, "target": 75, "text": "Test"}`
       * - Android: `{"target": 53, "text": "Test"}`
       */
      submitEditing: (text: string) => {
        return {
          nativeEvent: { text, target: 0 },
        };
      },

      /**
       * Experimental values:
       * - iOS: `{"eventCount": 4, "target": 75, "text": "Test"}`
       * - Android: `{"target": 53, "text": "Test"}`
       */
      endEditing: (text: string) => {
        return {
          nativeEvent: { text, target: 0 },
        };
      },

      /**
       * Experimental values:
       * - iOS: `{"selection": {"end": 4, "start": 4}, "target": 75}`
       * - Android: `{"selection": {"end": 4, "start": 4}}`
       */
      selectionChange: ({ start, end }: TextRange) => {
        return {
          nativeEvent: { selection: { start, end } },
        };
      },

      /**
       * Experimental values:
       * - iOS: `{"eventCount": 2, "previousText": "Te", "range": {"end": 2, "start": 2}, "target": 75, "text": "s"}`
       * - Android: `{"previousText": "Te", "range": {"end": 2, "start": 0}, "target": 53, "text": "Tes"}`
       */
      textInput: (text: string, previousText: string) => {
        return {
          nativeEvent: {
            text,
            previousText,
            range: { start: text.length, end: text.length },
            target: 0,
          },
        };
      },

      /**
       * Experimental values:
       * - iOS: `{"contentSize": {"height": 21.666666666666668, "width": 11.666666666666666}, "target": 75}`
       * - Android: `{"contentSize": {"height": 61.45454406738281, "width": 352.7272644042969}, "target": 53}`
       */
      contentSizeChange: ({ width, height }: ContentSize) => {
        return {
          nativeEvent: { contentSize: { width, height }, target: 0 },
        };
      },
    };