forked from retyui/react-native-confirmation-code-field
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCursor.js
41 lines (34 loc) · 843 Bytes
/
Cursor.js
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
// @flow
import React, { Component } from 'react';
import { Text } from 'react-native';
export const CURSOR_BLINKING_ANIMATION_SPEED = 500;
export const CURSOR_SYMBOL = '|';
const style = {
// reset inherit value
backgroundColor: '#00000000',
};
export default class Cursor extends Component<
{||},
{| cursorSymbol: string |},
> {
timeout: IntervalID;
state = {
cursorSymbol: CURSOR_SYMBOL,
};
componentDidMount() {
// Simulate cursor blink animation
this.timeout = setInterval(
() =>
this.setState(({ cursorSymbol }) => ({
cursorSymbol: cursorSymbol ? '' : CURSOR_SYMBOL,
})),
CURSOR_BLINKING_ANIMATION_SPEED,
);
}
componentWillUnmount() {
clearInterval(this.timeout);
}
render() {
return <Text style={style}>{this.state.cursorSymbol}</Text>;
}
}