-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCursor.js
More file actions
46 lines (39 loc) · 983 Bytes
/
Cursor.js
File metadata and controls
46 lines (39 loc) · 983 Bytes
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
// @flow
import React, { Component } from 'react';
import { Text, StyleSheet } from 'react-native';
export const CURSOR_BLINKING_ANIMATION_SPEED = 500;
export const CURSOR_SYMBOL = '|';
const styles = StyleSheet.create({
root: {
backgroundColor: '#00000000',
fontWeight: 'normal',
fontStyle: 'normal',
textDecorationLine: 'none',
textTransform: 'none',
},
});
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={styles.root}>{this.state.cursorSymbol}</Text>;
}
}