react-native-fpay 0.3.5 → 0.3.6
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.
- package/lib/module/FountainPayProvider.js +106 -16
- package/lib/module/FountainPayProvider.js.map +1 -1
- package/lib/module/core/api/client.js +13 -1
- package/lib/module/core/api/client.js.map +1 -1
- package/lib/module/core/api/index.js +66 -24
- package/lib/module/core/api/index.js.map +1 -1
- package/lib/module/engine/BLEReceiverService.js.map +1 -1
- package/lib/module/engine/BLESenderService.js.map +1 -1
- package/lib/module/engine/FPEngine.js +164 -43
- package/lib/module/engine/FPEngine.js.map +1 -1
- package/lib/module/engine/NearbyUsersService.js +1 -1
- package/lib/module/engine/NearbyUsersService.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/store/FPStore.js +155 -0
- package/lib/module/store/FPStore.js.map +1 -0
- package/lib/module/ui/components/AnimatedDots.js +3 -3
- package/lib/module/ui/components/AnimatedDots.js.map +1 -1
- package/lib/module/ui/components/ConfirmScreen.js +137 -123
- package/lib/module/ui/components/ConfirmScreen.js.map +1 -1
- package/lib/module/ui/components/FPButton.js.map +1 -1
- package/lib/module/ui/components/LoadingAnimation/InLoading.js +3 -3
- package/lib/module/ui/components/LoadingAnimation/InLoading.js.map +1 -1
- package/lib/module/ui/components/LoadingAnimation/index.js +3 -3
- package/lib/module/ui/components/LoadingAnimation/index.js.map +1 -1
- package/lib/module/ui/components/OtpInput/OTPInputView.js +11 -11
- package/lib/module/ui/components/OtpInput/OTPInputView.js.map +1 -1
- package/lib/module/ui/components/OtpInput/Styles.js +1 -1
- package/lib/module/ui/components/OtpInput/helpers/codeToArray.js +1 -1
- package/lib/module/ui/components/OtpInput/helpers/device.js.map +1 -1
- package/lib/module/ui/components/OtpInput/helpers/styles.js.map +1 -1
- package/lib/module/ui/components/OtpInput/index.js +3 -1
- package/lib/module/ui/components/OtpInput/index.js.map +1 -1
- package/lib/module/ui/components/PulseAnimation.js +2 -2
- package/lib/module/ui/components/PulseAnimation.js.map +1 -1
- package/lib/module/ui/modals/FPPaymentRequestModal.js +8 -7
- package/lib/module/ui/modals/FPPaymentRequestModal.js.map +1 -1
- package/lib/module/ui/modals/FPShell.js +2 -0
- package/lib/module/ui/modals/FPShell.js.map +1 -1
- package/lib/module/ui/screens/ReceiveScreen.js +8 -9
- package/lib/module/ui/screens/ReceiveScreen.js.map +1 -1
- package/lib/module/ui/screens/SendScreen.js +43 -94
- package/lib/module/ui/screens/SendScreen.js.map +1 -1
- package/lib/module/ui/screens/styles.js +15 -3
- package/lib/module/ui/screens/styles.js.map +1 -1
- package/lib/module/ui/screens/sub/receivePayment/Nfc/index.js +4 -4
- package/lib/module/ui/screens/sub/receivePayment/Nfc/index.js.map +1 -1
- package/lib/module/ui/screens/sub/receivePayment/Qr/index.js +5 -5
- package/lib/module/ui/screens/sub/receivePayment/Qr/index.js.map +1 -1
- package/lib/module/ui/screens/sub/receivePayment/Transfer/index.js +10 -11
- package/lib/module/ui/screens/sub/receivePayment/Transfer/index.js.map +1 -1
- package/lib/module/ui/screens/sub/sendPayment/BluetoothSubScreen.js +31 -8
- package/lib/module/ui/screens/sub/sendPayment/BluetoothSubScreen.js.map +1 -1
- package/lib/module/ui/screens/sub/sendPayment/NFCSubScreen.js +12 -8
- package/lib/module/ui/screens/sub/sendPayment/NFCSubScreen.js.map +1 -1
- package/lib/module/ui/screens/sub/sendPayment/NQRSubScreen.js +17 -5
- package/lib/module/ui/screens/sub/sendPayment/NQRSubScreen.js.map +1 -1
- package/lib/module/ui/screens/sub/sendPayment/ProximitySubScreen.js +67 -35
- package/lib/module/ui/screens/sub/sendPayment/ProximitySubScreen.js.map +1 -1
- package/lib/module/ui/screens/sub/sendPayment/TransferSubScreen.js +110 -34
- package/lib/module/ui/screens/sub/sendPayment/TransferSubScreen.js.map +1 -1
- package/lib/module/ui/theme/index.js.map +1 -1
- package/lib/typescript/src/FountainPayProvider.d.ts +1 -1
- package/lib/typescript/src/FountainPayProvider.d.ts.map +1 -1
- package/lib/typescript/src/core/api/client.d.ts.map +1 -1
- package/lib/typescript/src/core/api/index.d.ts +42 -26
- package/lib/typescript/src/core/api/index.d.ts.map +1 -1
- package/lib/typescript/src/core/types/index.d.ts +53 -28
- package/lib/typescript/src/core/types/index.d.ts.map +1 -1
- package/lib/typescript/src/engine/BLEReceiverService.d.ts +2 -0
- package/lib/typescript/src/engine/BLEReceiverService.d.ts.map +1 -1
- package/lib/typescript/src/engine/BLESenderService.d.ts.map +1 -1
- package/lib/typescript/src/engine/FPEngine.d.ts +5 -3
- package/lib/typescript/src/engine/FPEngine.d.ts.map +1 -1
- package/lib/typescript/src/engine/useIsForeground.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/store/FPStore.d.ts +60 -0
- package/lib/typescript/src/store/FPStore.d.ts.map +1 -0
- package/lib/typescript/src/ui/components/AnimatedDots.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/ConfirmScreen.d.ts +5 -5
- package/lib/typescript/src/ui/components/ConfirmScreen.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/FPButton.d.ts +1 -1
- package/lib/typescript/src/ui/components/FPButton.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/LoadingAnimation/InLoading.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/LoadingAnimation/index.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/OtpInput/OTPInputView.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/OtpInput/helpers/codeToArray.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/OtpInput/helpers/device.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/OtpInput/helpers/styles.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/OtpInput/helpers/types.d.ts +1 -2
- package/lib/typescript/src/ui/components/OtpInput/helpers/types.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/OtpInput/index.d.ts +3 -1
- package/lib/typescript/src/ui/components/OtpInput/index.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/PulseAnimation.d.ts.map +1 -1
- package/lib/typescript/src/ui/modals/FPPaymentRequestModal.d.ts.map +1 -1
- package/lib/typescript/src/ui/modals/FPShell.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/ReceiveScreen.d.ts +1 -1
- package/lib/typescript/src/ui/screens/ReceiveScreen.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/SendScreen.d.ts +1 -1
- package/lib/typescript/src/ui/screens/SendScreen.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/styles.d.ts +197 -0
- package/lib/typescript/src/ui/screens/styles.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/sub/receivePayment/Nfc/index.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/sub/receivePayment/Qr/index.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/sub/receivePayment/Transfer/index.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/BluetoothSubScreen.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/NFCSubScreen.d.ts +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/NFCSubScreen.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/NQRSubScreen.d.ts +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/NQRSubScreen.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/ProximitySubScreen.d.ts +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/ProximitySubScreen.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/TransferSubScreen.d.ts +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/TransferSubScreen.d.ts.map +1 -1
- package/lib/typescript/src/ui/theme/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/FountainPayProvider.tsx +164 -23
- package/src/core/api/client.ts +26 -4
- package/src/core/api/index.ts +170 -49
- package/src/core/types/index.ts +81 -48
- package/src/engine/BLEReceiverService.ts +86 -28
- package/src/engine/BLESenderService.ts +133 -69
- package/src/engine/FPEngine.ts +316 -97
- package/src/engine/NearbyUsersService.ts +6 -6
- package/src/engine/useIsForeground.ts +12 -12
- package/src/index.ts +10 -4
- package/src/store/FPStore.ts +216 -0
- package/src/ui/components/AnimatedDots.tsx +4 -5
- package/src/ui/components/ConfirmScreen.tsx +182 -169
- package/src/ui/components/FPButton.tsx +50 -9
- package/src/ui/components/LoadingAnimation/InLoading.tsx +23 -27
- package/src/ui/components/LoadingAnimation/index.tsx +3 -7
- package/src/ui/components/OtpInput/OTPInputView.tsx +254 -205
- package/src/ui/components/OtpInput/Styles.ts +1 -1
- package/src/ui/components/OtpInput/helpers/codeToArray.ts +2 -2
- package/src/ui/components/OtpInput/helpers/device.ts +4 -3
- package/src/ui/components/OtpInput/helpers/styles.ts +13 -14
- package/src/ui/components/OtpInput/helpers/types.ts +83 -79
- package/src/ui/components/OtpInput/index.tsx +18 -15
- package/src/ui/components/PulseAnimation.tsx +3 -5
- package/src/ui/modals/FPPaymentRequestModal.tsx +111 -28
- package/src/ui/modals/FPShell.tsx +60 -34
- package/src/ui/screens/ReceiveScreen.tsx +245 -84
- package/src/ui/screens/SendScreen.tsx +419 -167
- package/src/ui/screens/styles.ts +17 -5
- package/src/ui/screens/sub/receivePayment/Nfc/index.tsx +17 -25
- package/src/ui/screens/sub/receivePayment/Qr/index.tsx +21 -20
- package/src/ui/screens/sub/receivePayment/Transfer/index.tsx +34 -28
- package/src/ui/screens/sub/sendPayment/BluetoothSubScreen.tsx +135 -67
- package/src/ui/screens/sub/sendPayment/NFCSubScreen.tsx +188 -112
- package/src/ui/screens/sub/sendPayment/NQRSubScreen.tsx +102 -69
- package/src/ui/screens/sub/sendPayment/ProximitySubScreen.tsx +225 -99
- package/src/ui/screens/sub/sendPayment/TransferSubScreen.tsx +209 -89
- 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 {
|
|
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<
|
|
19
|
+
export default class OTPInputView extends Component<
|
|
20
|
+
InputProps,
|
|
21
|
+
OTPInputViewState
|
|
22
|
+
> {
|
|
23
|
+
private fields: Array<TextInputRef | null> = [];
|
|
13
24
|
|
|
14
|
-
|
|
25
|
+
private keyboardDidHideListener?: EmitterSubscription;
|
|
26
|
+
private timer?: NodeJS.Timeout;
|
|
27
|
+
private hasCheckedClipBoard?: boolean;
|
|
28
|
+
private clipBoardCode?: string;
|
|
15
29
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
private handleKeyboardDidHide = () => {
|
|
85
|
+
this.blurAllFields();
|
|
86
|
+
};
|
|
75
87
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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,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 =
|
|
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
|
|
1
|
+
import { StyleSheet, type TextStyle } from 'react-native';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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;
|