react-native-fpay 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/lib/module/FountainPayProvider.js +108 -18
  2. package/lib/module/FountainPayProvider.js.map +1 -1
  3. package/lib/module/core/api/client.js +13 -1
  4. package/lib/module/core/api/client.js.map +1 -1
  5. package/lib/module/core/api/index.js +66 -24
  6. package/lib/module/core/api/index.js.map +1 -1
  7. package/lib/module/engine/BLEReceiverService.js.map +1 -1
  8. package/lib/module/engine/BLESenderService.js.map +1 -1
  9. package/lib/module/engine/FPEngine.js +164 -43
  10. package/lib/module/engine/FPEngine.js.map +1 -1
  11. package/lib/module/engine/NearbyUsersService.js +1 -1
  12. package/lib/module/engine/NearbyUsersService.js.map +1 -1
  13. package/lib/module/index.js +1 -0
  14. package/lib/module/index.js.map +1 -1
  15. package/lib/module/store/FPStore.js +155 -0
  16. package/lib/module/store/FPStore.js.map +1 -0
  17. package/lib/module/ui/components/AnimatedDots.js +3 -3
  18. package/lib/module/ui/components/AnimatedDots.js.map +1 -1
  19. package/lib/module/ui/components/ConfirmScreen.js +137 -123
  20. package/lib/module/ui/components/ConfirmScreen.js.map +1 -1
  21. package/lib/module/ui/components/FPButton.js.map +1 -1
  22. package/lib/module/ui/components/LoadingAnimation/InLoading.js +3 -3
  23. package/lib/module/ui/components/LoadingAnimation/InLoading.js.map +1 -1
  24. package/lib/module/ui/components/LoadingAnimation/index.js +3 -3
  25. package/lib/module/ui/components/LoadingAnimation/index.js.map +1 -1
  26. package/lib/module/ui/components/OtpInput/OTPInputView.js +11 -11
  27. package/lib/module/ui/components/OtpInput/OTPInputView.js.map +1 -1
  28. package/lib/module/ui/components/OtpInput/Styles.js +1 -1
  29. package/lib/module/ui/components/OtpInput/helpers/codeToArray.js +1 -1
  30. package/lib/module/ui/components/OtpInput/helpers/device.js.map +1 -1
  31. package/lib/module/ui/components/OtpInput/helpers/styles.js.map +1 -1
  32. package/lib/module/ui/components/OtpInput/index.js +3 -1
  33. package/lib/module/ui/components/OtpInput/index.js.map +1 -1
  34. package/lib/module/ui/components/PulseAnimation.js +2 -2
  35. package/lib/module/ui/components/PulseAnimation.js.map +1 -1
  36. package/lib/module/ui/modals/FPPaymentRequestModal.js +8 -7
  37. package/lib/module/ui/modals/FPPaymentRequestModal.js.map +1 -1
  38. package/lib/module/ui/modals/FPShell.js +2 -0
  39. package/lib/module/ui/modals/FPShell.js.map +1 -1
  40. package/lib/module/ui/screens/ReceiveScreen.js +8 -9
  41. package/lib/module/ui/screens/ReceiveScreen.js.map +1 -1
  42. package/lib/module/ui/screens/SendScreen.js +43 -94
  43. package/lib/module/ui/screens/SendScreen.js.map +1 -1
  44. package/lib/module/ui/screens/styles.js +15 -3
  45. package/lib/module/ui/screens/styles.js.map +1 -1
  46. package/lib/module/ui/screens/sub/receivePayment/Nfc/index.js +4 -4
  47. package/lib/module/ui/screens/sub/receivePayment/Nfc/index.js.map +1 -1
  48. package/lib/module/ui/screens/sub/receivePayment/Qr/index.js +5 -5
  49. package/lib/module/ui/screens/sub/receivePayment/Qr/index.js.map +1 -1
  50. package/lib/module/ui/screens/sub/receivePayment/Transfer/index.js +10 -11
  51. package/lib/module/ui/screens/sub/receivePayment/Transfer/index.js.map +1 -1
  52. package/lib/module/ui/screens/sub/sendPayment/BluetoothSubScreen.js +31 -8
  53. package/lib/module/ui/screens/sub/sendPayment/BluetoothSubScreen.js.map +1 -1
  54. package/lib/module/ui/screens/sub/sendPayment/NFCSubScreen.js +12 -8
  55. package/lib/module/ui/screens/sub/sendPayment/NFCSubScreen.js.map +1 -1
  56. package/lib/module/ui/screens/sub/sendPayment/NQRSubScreen.js +17 -5
  57. package/lib/module/ui/screens/sub/sendPayment/NQRSubScreen.js.map +1 -1
  58. package/lib/module/ui/screens/sub/sendPayment/ProximitySubScreen.js +67 -35
  59. package/lib/module/ui/screens/sub/sendPayment/ProximitySubScreen.js.map +1 -1
  60. package/lib/module/ui/screens/sub/sendPayment/TransferSubScreen.js +110 -34
  61. package/lib/module/ui/screens/sub/sendPayment/TransferSubScreen.js.map +1 -1
  62. package/lib/module/ui/theme/index.js.map +1 -1
  63. package/lib/typescript/src/FountainPayProvider.d.ts +1 -1
  64. package/lib/typescript/src/FountainPayProvider.d.ts.map +1 -1
  65. package/lib/typescript/src/core/api/client.d.ts.map +1 -1
  66. package/lib/typescript/src/core/api/index.d.ts +42 -26
  67. package/lib/typescript/src/core/api/index.d.ts.map +1 -1
  68. package/lib/typescript/src/core/types/index.d.ts +53 -28
  69. package/lib/typescript/src/core/types/index.d.ts.map +1 -1
  70. package/lib/typescript/src/engine/BLEReceiverService.d.ts +2 -0
  71. package/lib/typescript/src/engine/BLEReceiverService.d.ts.map +1 -1
  72. package/lib/typescript/src/engine/BLESenderService.d.ts.map +1 -1
  73. package/lib/typescript/src/engine/FPEngine.d.ts +5 -3
  74. package/lib/typescript/src/engine/FPEngine.d.ts.map +1 -1
  75. package/lib/typescript/src/engine/useIsForeground.d.ts.map +1 -1
  76. package/lib/typescript/src/index.d.ts +2 -1
  77. package/lib/typescript/src/index.d.ts.map +1 -1
  78. package/lib/typescript/src/store/FPStore.d.ts +60 -0
  79. package/lib/typescript/src/store/FPStore.d.ts.map +1 -0
  80. package/lib/typescript/src/ui/components/AnimatedDots.d.ts.map +1 -1
  81. package/lib/typescript/src/ui/components/ConfirmScreen.d.ts +5 -5
  82. package/lib/typescript/src/ui/components/ConfirmScreen.d.ts.map +1 -1
  83. package/lib/typescript/src/ui/components/FPButton.d.ts +1 -1
  84. package/lib/typescript/src/ui/components/FPButton.d.ts.map +1 -1
  85. package/lib/typescript/src/ui/components/LoadingAnimation/InLoading.d.ts.map +1 -1
  86. package/lib/typescript/src/ui/components/LoadingAnimation/index.d.ts.map +1 -1
  87. package/lib/typescript/src/ui/components/OtpInput/OTPInputView.d.ts.map +1 -1
  88. package/lib/typescript/src/ui/components/OtpInput/helpers/codeToArray.d.ts.map +1 -1
  89. package/lib/typescript/src/ui/components/OtpInput/helpers/device.d.ts.map +1 -1
  90. package/lib/typescript/src/ui/components/OtpInput/helpers/styles.d.ts.map +1 -1
  91. package/lib/typescript/src/ui/components/OtpInput/helpers/types.d.ts +1 -2
  92. package/lib/typescript/src/ui/components/OtpInput/helpers/types.d.ts.map +1 -1
  93. package/lib/typescript/src/ui/components/OtpInput/index.d.ts +3 -1
  94. package/lib/typescript/src/ui/components/OtpInput/index.d.ts.map +1 -1
  95. package/lib/typescript/src/ui/components/PulseAnimation.d.ts.map +1 -1
  96. package/lib/typescript/src/ui/modals/FPPaymentRequestModal.d.ts.map +1 -1
  97. package/lib/typescript/src/ui/modals/FPShell.d.ts.map +1 -1
  98. package/lib/typescript/src/ui/screens/ReceiveScreen.d.ts +1 -1
  99. package/lib/typescript/src/ui/screens/ReceiveScreen.d.ts.map +1 -1
  100. package/lib/typescript/src/ui/screens/SendScreen.d.ts +1 -1
  101. package/lib/typescript/src/ui/screens/SendScreen.d.ts.map +1 -1
  102. package/lib/typescript/src/ui/screens/styles.d.ts +197 -0
  103. package/lib/typescript/src/ui/screens/styles.d.ts.map +1 -1
  104. package/lib/typescript/src/ui/screens/sub/receivePayment/Nfc/index.d.ts.map +1 -1
  105. package/lib/typescript/src/ui/screens/sub/receivePayment/Qr/index.d.ts.map +1 -1
  106. package/lib/typescript/src/ui/screens/sub/receivePayment/Transfer/index.d.ts.map +1 -1
  107. package/lib/typescript/src/ui/screens/sub/sendPayment/BluetoothSubScreen.d.ts.map +1 -1
  108. package/lib/typescript/src/ui/screens/sub/sendPayment/NFCSubScreen.d.ts +1 -1
  109. package/lib/typescript/src/ui/screens/sub/sendPayment/NFCSubScreen.d.ts.map +1 -1
  110. package/lib/typescript/src/ui/screens/sub/sendPayment/NQRSubScreen.d.ts +1 -1
  111. package/lib/typescript/src/ui/screens/sub/sendPayment/NQRSubScreen.d.ts.map +1 -1
  112. package/lib/typescript/src/ui/screens/sub/sendPayment/ProximitySubScreen.d.ts +1 -1
  113. package/lib/typescript/src/ui/screens/sub/sendPayment/ProximitySubScreen.d.ts.map +1 -1
  114. package/lib/typescript/src/ui/screens/sub/sendPayment/TransferSubScreen.d.ts +1 -1
  115. package/lib/typescript/src/ui/screens/sub/sendPayment/TransferSubScreen.d.ts.map +1 -1
  116. package/lib/typescript/src/ui/theme/index.d.ts.map +1 -1
  117. package/package.json +4 -4
  118. package/src/FountainPayProvider.tsx +163 -24
  119. package/src/core/api/client.ts +26 -4
  120. package/src/core/api/index.ts +170 -49
  121. package/src/core/types/index.ts +81 -48
  122. package/src/engine/BLEReceiverService.ts +86 -28
  123. package/src/engine/BLESenderService.ts +133 -69
  124. package/src/engine/FPEngine.ts +316 -97
  125. package/src/engine/NearbyUsersService.ts +6 -6
  126. package/src/engine/useIsForeground.ts +12 -12
  127. package/src/index.ts +10 -4
  128. package/src/store/FPStore.ts +216 -0
  129. package/src/ui/components/AnimatedDots.tsx +4 -5
  130. package/src/ui/components/ConfirmScreen.tsx +182 -169
  131. package/src/ui/components/FPButton.tsx +50 -9
  132. package/src/ui/components/LoadingAnimation/InLoading.tsx +23 -27
  133. package/src/ui/components/LoadingAnimation/index.tsx +3 -7
  134. package/src/ui/components/OtpInput/OTPInputView.tsx +254 -205
  135. package/src/ui/components/OtpInput/Styles.ts +1 -1
  136. package/src/ui/components/OtpInput/helpers/codeToArray.ts +2 -2
  137. package/src/ui/components/OtpInput/helpers/device.ts +4 -3
  138. package/src/ui/components/OtpInput/helpers/styles.ts +13 -14
  139. package/src/ui/components/OtpInput/helpers/types.ts +83 -79
  140. package/src/ui/components/OtpInput/index.tsx +18 -15
  141. package/src/ui/components/PulseAnimation.tsx +3 -5
  142. package/src/ui/modals/FPPaymentRequestModal.tsx +111 -28
  143. package/src/ui/modals/FPShell.tsx +60 -34
  144. package/src/ui/screens/ReceiveScreen.tsx +245 -84
  145. package/src/ui/screens/SendScreen.tsx +419 -167
  146. package/src/ui/screens/styles.ts +17 -5
  147. package/src/ui/screens/sub/receivePayment/Nfc/index.tsx +17 -25
  148. package/src/ui/screens/sub/receivePayment/Qr/index.tsx +21 -20
  149. package/src/ui/screens/sub/receivePayment/Transfer/index.tsx +34 -28
  150. package/src/ui/screens/sub/sendPayment/BluetoothSubScreen.tsx +135 -67
  151. package/src/ui/screens/sub/sendPayment/NFCSubScreen.tsx +188 -112
  152. package/src/ui/screens/sub/sendPayment/NQRSubScreen.tsx +102 -69
  153. package/src/ui/screens/sub/sendPayment/ProximitySubScreen.tsx +225 -99
  154. package/src/ui/screens/sub/sendPayment/TransferSubScreen.tsx +209 -89
  155. package/src/ui/theme/index.ts +14 -2
@@ -1,243 +1,292 @@
1
1
  import type { InputProps, OTPInputViewState } from './helpers/types';
2
- import React, { Component } from 'react'
3
- import { View, TextInput, TouchableWithoutFeedback, Keyboard, Platform, I18nManager, type EmitterSubscription, } from 'react-native'
2
+ import React, { Component } from 'react';
3
+ import {
4
+ View,
5
+ TextInput,
6
+ TouchableWithoutFeedback,
7
+ Keyboard,
8
+ Platform,
9
+ I18nManager,
10
+ type EmitterSubscription,
11
+ } from 'react-native';
4
12
  import Clipboard from '@react-native-community/clipboard';
5
- import styles from './helpers/styles'
6
- import { isAutoFillSupported } from './helpers/device'
7
- import { codeToArray } from './helpers/codeToArray'
8
-
13
+ import styles from './helpers/styles';
14
+ import { isAutoFillSupported } from './helpers/device';
15
+ import { codeToArray } from './helpers/codeToArray';
9
16
 
10
17
  type TextInputRef = React.ElementRef<typeof TextInput>;
11
18
 
12
- export default class OTPInputView extends Component<InputProps, OTPInputViewState> {
19
+ export default class OTPInputView extends Component<
20
+ InputProps,
21
+ OTPInputViewState
22
+ > {
23
+ private fields: Array<TextInputRef | null> = [];
13
24
 
14
- private fields: Array<TextInputRef | null> = [];
25
+ private keyboardDidHideListener?: EmitterSubscription;
26
+ private timer?: NodeJS.Timeout;
27
+ private hasCheckedClipBoard?: boolean;
28
+ private clipBoardCode?: string;
15
29
 
16
- private keyboardDidHideListener?: EmitterSubscription;
17
- private timer?: NodeJS.Timeout;
18
- private hasCheckedClipBoard?: boolean;
19
- private clipBoardCode?: string;
30
+ constructor(props: InputProps) {
31
+ super(props);
32
+ const { code } = props;
33
+ this.state = {
34
+ digits: codeToArray(code),
35
+ selectedIndex: props.autoFocusOnLoad ? 0 : -1,
36
+ };
37
+ }
20
38
 
21
- constructor(props: InputProps) {
22
- super(props)
23
- const { code } = props
24
- this.state = {
25
- digits: codeToArray(code),
26
- selectedIndex: props.autoFocusOnLoad ? 0 : -1,
27
- }
39
+ UNSAFE_componentWillReceiveProps(nextProps: InputProps) {
40
+ const { code } = this.props;
41
+ if (nextProps.code !== code) {
42
+ this.setState({ digits: codeToArray(nextProps.code) });
28
43
  }
44
+ }
29
45
 
30
- UNSAFE_componentWillReceiveProps(nextProps: InputProps) {
31
- const { code } = this.props
32
- if (nextProps.code !== code) {
33
- this.setState({ digits: codeToArray(nextProps.code) })
34
- }
35
- }
46
+ componentDidMount() {
47
+ this.copyCodeFromClipBoardOnAndroid();
48
+ this.bringUpKeyBoardIfNeeded();
49
+ this.keyboardDidHideListener = Keyboard.addListener(
50
+ 'keyboardDidHide',
51
+ this.handleKeyboardDidHide
52
+ );
53
+ }
36
54
 
37
- componentDidMount() {
38
- this.copyCodeFromClipBoardOnAndroid()
39
- this.bringUpKeyBoardIfNeeded()
40
- this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this.handleKeyboardDidHide)
41
- }
42
-
43
- componentWillUnmount() {
44
- if (this.timer) {
45
- clearInterval(this.timer)
46
- }
47
- this.keyboardDidHideListener?.remove()
55
+ componentWillUnmount() {
56
+ if (this.timer) {
57
+ clearInterval(this.timer);
48
58
  }
59
+ this.keyboardDidHideListener?.remove();
60
+ }
49
61
 
50
- private copyCodeFromClipBoardOnAndroid = () => {
51
- if (Platform.OS === "android") {
52
- this.checkPinCodeFromClipBoard()
53
- this.timer = setInterval(this.checkPinCodeFromClipBoard, 400)
54
- }
62
+ private copyCodeFromClipBoardOnAndroid = () => {
63
+ if (Platform.OS === 'android') {
64
+ this.checkPinCodeFromClipBoard();
65
+ this.timer = setInterval(this.checkPinCodeFromClipBoard, 400);
55
66
  }
67
+ };
56
68
 
57
- bringUpKeyBoardIfNeeded = () => {
58
- const { autoFocusOnLoad, pinCount } = this.props
59
- const digits = this.getDigits()
60
- const focusIndex = digits.length ? digits.length - 1 : 0
61
- if (focusIndex < pinCount && autoFocusOnLoad) {
62
- this.focusField(focusIndex)
63
- }
69
+ bringUpKeyBoardIfNeeded = () => {
70
+ const { autoFocusOnLoad, pinCount } = this.props;
71
+ const digits = this.getDigits();
72
+ const focusIndex = digits.length ? digits.length - 1 : 0;
73
+ if (focusIndex < pinCount && autoFocusOnLoad) {
74
+ this.focusField(focusIndex);
64
75
  }
76
+ };
65
77
 
66
- getDigits = () => {
67
- const { digits: innerDigits } = this.state
68
- const { code } = this.props
69
- return code === undefined ? innerDigits : code.split("")
70
- }
78
+ getDigits = () => {
79
+ const { digits: innerDigits } = this.state;
80
+ const { code } = this.props;
81
+ return code === undefined ? innerDigits : code.split('');
82
+ };
71
83
 
72
- private handleKeyboardDidHide = () => {
73
- this.blurAllFields()
74
- }
84
+ private handleKeyboardDidHide = () => {
85
+ this.blurAllFields();
86
+ };
75
87
 
76
- private notifyCodeChanged = () => {
77
- const { digits } = this.state
78
- const code = digits.join("")
79
- const { onCodeChanged } = this.props
80
- if (onCodeChanged) {
81
- onCodeChanged(code)
82
- }
88
+ private notifyCodeChanged = () => {
89
+ const { digits } = this.state;
90
+ const code = digits.join('');
91
+ const { onCodeChanged } = this.props;
92
+ if (onCodeChanged) {
93
+ onCodeChanged(code);
83
94
  }
95
+ };
84
96
 
85
- checkPinCodeFromClipBoard = () => {
86
- const { pinCount, onCodeFilled } = this.props
87
- const regexp = new RegExp(`^\\d{${pinCount}}$`)
88
- Clipboard.getString().then(code => {
89
- if (this.hasCheckedClipBoard && regexp.test(code) && (this.clipBoardCode !== code)) {
90
- this.setState({
91
- digits: code.split(""),
92
- }, () => {
93
- this.blurAllFields()
94
- this.notifyCodeChanged()
95
- onCodeFilled && onCodeFilled(code)
96
- })
97
+ checkPinCodeFromClipBoard = () => {
98
+ const { pinCount, onCodeFilled } = this.props;
99
+ const regexp = new RegExp(`^\\d{${pinCount}}$`);
100
+ Clipboard.getString()
101
+ .then((code) => {
102
+ if (
103
+ this.hasCheckedClipBoard &&
104
+ regexp.test(code) &&
105
+ this.clipBoardCode !== code
106
+ ) {
107
+ this.setState(
108
+ {
109
+ digits: code.split(''),
110
+ },
111
+ () => {
112
+ this.blurAllFields();
113
+ this.notifyCodeChanged();
114
+ onCodeFilled && onCodeFilled(code);
97
115
  }
98
- this.clipBoardCode = code
99
- this.hasCheckedClipBoard = true
100
- }).catch(() => {
101
- })
102
- }
103
-
104
- private handleChangeText = (index: number, text: string) => {
105
- const { onCodeFilled, pinCount } = this.props
106
- const digits = this.getDigits()
107
- let newdigits: any = digits.slice()
108
- const oldTextLength = newdigits[index] ? newdigits[index].length : 0
109
- const newTextLength = text.length
110
- if (newTextLength - oldTextLength === pinCount) { // user pasted text in.
111
- newdigits = text.split("").slice(oldTextLength, newTextLength)
112
- this.setState({ digits: newdigits }, this.notifyCodeChanged)
113
- } else {
114
- if (text.length === 0) {
115
- if (newdigits.length > 0) {
116
- newdigits = newdigits.slice(0, newdigits.length - 1)
117
- }
118
- } else {
119
- text.split("").forEach((value) => {
120
- if(index < pinCount) {
121
- newdigits[index] = value;
122
- index += 1;
123
- }
124
- })
125
- index -= 1
126
- }
127
- this.setState({ digits: newdigits }, this.notifyCodeChanged)
116
+ );
128
117
  }
118
+ this.clipBoardCode = code;
119
+ this.hasCheckedClipBoard = true;
120
+ })
121
+ .catch(() => {});
122
+ };
129
123
 
130
- let result = newdigits.join("")
131
- if (result.length >= pinCount) {
132
- onCodeFilled && onCodeFilled(result)
133
- this.focusField(pinCount - 1)
134
- this.blurAllFields()
135
- } else {
136
- if (text.length > 0 && index < pinCount - 1) {
137
- this.focusField(index + 1)
138
- }
124
+ private handleChangeText = (index: number, text: string) => {
125
+ const { onCodeFilled, pinCount } = this.props;
126
+ const digits = this.getDigits();
127
+ let newdigits: any = digits.slice();
128
+ const oldTextLength = newdigits[index] ? newdigits[index].length : 0;
129
+ const newTextLength = text.length;
130
+ if (newTextLength - oldTextLength === pinCount) {
131
+ // user pasted text in.
132
+ newdigits = text.split('').slice(oldTextLength, newTextLength);
133
+ this.setState({ digits: newdigits }, this.notifyCodeChanged);
134
+ } else {
135
+ if (text.length === 0) {
136
+ if (newdigits.length > 0) {
137
+ newdigits = newdigits.slice(0, newdigits.length - 1);
139
138
  }
139
+ } else {
140
+ text.split('').forEach((value) => {
141
+ if (index < pinCount) {
142
+ newdigits[index] = value;
143
+ index += 1;
144
+ }
145
+ });
146
+ index -= 1;
147
+ }
148
+ this.setState({ digits: newdigits }, this.notifyCodeChanged);
140
149
  }
141
150
 
142
- private handleKeyPressTextInput = (index: number, key: string) => {
143
- const digits = this.getDigits()
144
- if (key === 'Backspace') {
145
- if (!digits[index] && index > 0) {
146
- this.handleChangeText(index - 1, '')
147
- this.focusField(index - 1)
148
- }
149
- }
151
+ let result = newdigits.join('');
152
+ if (result.length >= pinCount) {
153
+ onCodeFilled && onCodeFilled(result);
154
+ this.focusField(pinCount - 1);
155
+ this.blurAllFields();
156
+ } else {
157
+ if (text.length > 0 && index < pinCount - 1) {
158
+ this.focusField(index + 1);
159
+ }
150
160
  }
161
+ };
151
162
 
152
-
153
-
154
- focusField = (index: number) => {
155
- if (index < this.fields.length) {
156
- this.fields[index]?.focus();
157
- this.setState({ selectedIndex: index });
158
- }
163
+ private handleKeyPressTextInput = (index: number, key: string) => {
164
+ const digits = this.getDigits();
165
+ if (key === 'Backspace') {
166
+ if (!digits[index] && index > 0) {
167
+ this.handleChangeText(index - 1, '');
168
+ this.focusField(index - 1);
169
+ }
159
170
  }
171
+ };
160
172
 
161
- blurAllFields = () => {
162
- this.fields.forEach(field => field?.blur());
163
- this.setState({ selectedIndex: -1 });
173
+ focusField = (index: number) => {
174
+ if (index < this.fields.length) {
175
+ this.fields[index]?.focus();
176
+ this.setState({ selectedIndex: index });
164
177
  }
178
+ };
165
179
 
180
+ blurAllFields = () => {
181
+ this.fields.forEach((field) => field?.blur());
182
+ this.setState({ selectedIndex: -1 });
183
+ };
166
184
 
167
- clearAllFields = () => {
168
- const { clearInputs, code } = this.props;
169
- if (clearInputs && code === "") {
170
- this.setState({ digits: [], selectedIndex: 0 })
171
- }
185
+ clearAllFields = () => {
186
+ const { clearInputs, code } = this.props;
187
+ if (clearInputs && code === '') {
188
+ this.setState({ digits: [], selectedIndex: 0 });
172
189
  }
190
+ };
173
191
 
174
- renderOneInputField = (_: TextInput, index: number) => {
175
- const { codeInputFieldStyle, codeInputHighlightStyle, secureTextEntry, editable, keyboardType, selectionColor, keyboardAppearance, showSoftInputOnFocus } = this.props
176
- const { defaultTextFieldStyle } = styles
177
- const { selectedIndex, digits } = this.state
178
- const { clearInputs, placeholderCharacter, placeholderTextColor } = this.props
179
- const { color: defaultPlaceholderTextColor } = { ...defaultTextFieldStyle, ...codeInputFieldStyle }
180
- return (
181
- <View pointerEvents="none" key={index + "view"} testID="inputSlotView">
182
- <TextInput
183
- testID="textInput"
184
- underlineColorAndroid='rgba(0,0,0,0)'
185
- style={selectedIndex === index ? [defaultTextFieldStyle, codeInputFieldStyle, codeInputHighlightStyle] : [defaultTextFieldStyle, codeInputFieldStyle]}
186
- ref={(ref) => {
187
- this.fields[index] = ref;
188
- }}
189
- onChangeText={text => {
190
- this.handleChangeText(index, text)
191
- }}
192
- onKeyPress={({ nativeEvent: { key } }) => { this.handleKeyPressTextInput(index, key) }}
193
- value={ !clearInputs ? digits[index]: "" }
194
- keyboardAppearance={keyboardAppearance}
195
- keyboardType={keyboardType}
196
- textContentType={isAutoFillSupported ? "oneTimeCode" : "none"}
197
- key={index}
198
- selectionColor={selectionColor}
199
- secureTextEntry={secureTextEntry}
200
- // showSoftInputOnFocus={showSoftInputOnFocus}
201
- editable={editable}
202
- placeholder={placeholderCharacter}
203
- placeholderTextColor={placeholderTextColor || defaultPlaceholderTextColor}
204
- />
205
- </View>
206
- )
207
- }
192
+ renderOneInputField = (_: TextInput, index: number) => {
193
+ const {
194
+ codeInputFieldStyle,
195
+ codeInputHighlightStyle,
196
+ secureTextEntry,
197
+ editable,
198
+ keyboardType,
199
+ selectionColor,
200
+ keyboardAppearance,
201
+ showSoftInputOnFocus,
202
+ } = this.props;
203
+ const { defaultTextFieldStyle } = styles;
204
+ const { selectedIndex, digits } = this.state;
205
+ const { clearInputs, placeholderCharacter, placeholderTextColor } =
206
+ this.props;
207
+ const { color: defaultPlaceholderTextColor } = {
208
+ ...defaultTextFieldStyle,
209
+ ...codeInputFieldStyle,
210
+ };
211
+ return (
212
+ <View pointerEvents="none" key={index + 'view'} testID="inputSlotView">
213
+ <TextInput
214
+ testID="textInput"
215
+ underlineColorAndroid="rgba(0,0,0,0)"
216
+ style={
217
+ selectedIndex === index
218
+ ? [
219
+ defaultTextFieldStyle,
220
+ codeInputFieldStyle,
221
+ codeInputHighlightStyle,
222
+ ]
223
+ : [defaultTextFieldStyle, codeInputFieldStyle]
224
+ }
225
+ ref={(ref) => {
226
+ this.fields[index] = ref;
227
+ }}
228
+ onChangeText={(text) => {
229
+ this.handleChangeText(index, text);
230
+ }}
231
+ onKeyPress={({ nativeEvent: { key } }) => {
232
+ this.handleKeyPressTextInput(index, key);
233
+ }}
234
+ value={!clearInputs ? digits[index] : ''}
235
+ keyboardAppearance={keyboardAppearance}
236
+ keyboardType={keyboardType}
237
+ textContentType={isAutoFillSupported ? 'oneTimeCode' : 'none'}
238
+ key={index}
239
+ selectionColor={selectionColor}
240
+ secureTextEntry={secureTextEntry}
241
+ // showSoftInputOnFocus={showSoftInputOnFocus}
242
+ editable={editable}
243
+ placeholder={placeholderCharacter}
244
+ placeholderTextColor={
245
+ placeholderTextColor || defaultPlaceholderTextColor
246
+ }
247
+ />
248
+ </View>
249
+ );
250
+ };
208
251
 
209
- renderTextFields = () => {
210
- const { pinCount } = this.props
211
- const array = new Array(pinCount).fill(0)
212
- return array.map(this.renderOneInputField)
213
- }
252
+ renderTextFields = () => {
253
+ const { pinCount } = this.props;
254
+ const array = new Array(pinCount).fill(0);
255
+ return array.map(this.renderOneInputField);
256
+ };
214
257
 
215
- render() {
216
- const { pinCount, style, clearInputs } = this.props
217
- const digits = this.getDigits()
218
- return (
219
- <View
220
- testID="OTPInputView"
221
- style={style}
222
- >
223
- <TouchableWithoutFeedback
224
- onPress={() => {
225
- if (!clearInputs) {
226
- let filledPinCount = digits.filter((digit) => { return (digit !== null && digit !== undefined) }).length
227
- this.focusField(Math.min(filledPinCount, pinCount - 1))
228
- } else {
229
- this.clearAllFields();
230
- this.focusField(0)
231
- }
232
- }}
233
- >
234
- <View
235
- style={{ flexDirection: 'row', justifyContent: 'center', alignItems: 'center', width: '100%', height: 100 , gap: '10px' }}
236
- >
237
- {this.renderTextFields()}
238
- </View>
239
- </TouchableWithoutFeedback>
240
- </View>
241
- );
242
- }
243
- }
258
+ render() {
259
+ const { pinCount, style, clearInputs } = this.props;
260
+ const digits = this.getDigits();
261
+ return (
262
+ <View testID="OTPInputView" style={style}>
263
+ <TouchableWithoutFeedback
264
+ onPress={() => {
265
+ if (!clearInputs) {
266
+ let filledPinCount = digits.filter((digit) => {
267
+ return digit !== null && digit !== undefined;
268
+ }).length;
269
+ this.focusField(Math.min(filledPinCount, pinCount - 1));
270
+ } else {
271
+ this.clearAllFields();
272
+ this.focusField(0);
273
+ }
274
+ }}
275
+ >
276
+ <View
277
+ style={{
278
+ flexDirection: 'row',
279
+ justifyContent: 'center',
280
+ alignItems: 'center',
281
+ width: '100%',
282
+ height: 100,
283
+ gap: '10px',
284
+ }}
285
+ >
286
+ {this.renderTextFields()}
287
+ </View>
288
+ </TouchableWithoutFeedback>
289
+ </View>
290
+ );
291
+ }
292
+ }
@@ -1,4 +1,4 @@
1
- import styled from "styled-components/native";
1
+ import styled from 'styled-components/native';
2
2
 
3
3
  export const HideInput = styled.TextInput`
4
4
  width: 80%;
@@ -1,3 +1,3 @@
1
- export const codeToArray = (code?: string): string[] => code?.split("") ?? [];
1
+ export const codeToArray = (code?: string): string[] => code?.split('') ?? [];
2
2
 
3
- export default { codeToArray }
3
+ export default { codeToArray };
@@ -1,6 +1,7 @@
1
- import { Platform } from 'react-native'
1
+ import { Platform } from 'react-native';
2
2
 
3
3
  const majorVersionIOS = parseInt(String(Platform.Version), 10);
4
- export const isAutoFillSupported = (Platform.OS === 'ios' && majorVersionIOS >= 12)
4
+ export const isAutoFillSupported =
5
+ Platform.OS === 'ios' && majorVersionIOS >= 12;
5
6
 
6
- export default { isAutoFillSupported }
7
+ export default { isAutoFillSupported };
@@ -1,17 +1,16 @@
1
- import { StyleSheet, type TextStyle, } from 'react-native';
1
+ import { StyleSheet, type TextStyle } from 'react-native';
2
2
 
3
-
4
- const styles = StyleSheet.create<{defaultTextFieldStyle: TextStyle}>({
5
- defaultTextFieldStyle : {
6
- width : 65,
7
- height : 65,
8
- borderColor : 'rgba(226, 226, 226, 1)',
9
- borderWidth : 1,
10
- borderRadius : 2,
11
- textAlign : 'center',
12
- color: 'rgba(226, 226, 226, 1)',
13
- marginHorizontal: 3.5
14
- },
3
+ const styles = StyleSheet.create<{ defaultTextFieldStyle: TextStyle }>({
4
+ defaultTextFieldStyle: {
5
+ width: 65,
6
+ height: 65,
7
+ borderColor: 'rgba(226, 226, 226, 1)',
8
+ borderWidth: 1,
9
+ borderRadius: 2,
10
+ textAlign: 'center',
11
+ color: 'rgba(226, 226, 226, 1)',
12
+ marginHorizontal: 3.5,
13
+ },
15
14
  });
16
15
 
17
- export default styles;
16
+ export default styles;