-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathUnderline.js
More file actions
70 lines (67 loc) · 1.54 KB
/
Underline.js
File metadata and controls
70 lines (67 loc) · 1.54 KB
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
import React, {Component, PropTypes} from "react";
import {View, StyleSheet, Animated} from "react-native";
export default class Underline extends Component {
constructor(props: Object) {
super(props);
this.state = {
lineLength: new Animated.Value(0),
};
this.wrapperWidth = 0;
}
componentDidMount() {
requestAnimationFrame(() => {
if (this.refs.wrapper == null) {
return;
}
const container = this.refs.wrapper; // un-box animated view
container.measure((left, top, width, height) => {
this.wrapperWidth = width;
});
});
}
expandLine() {
Animated.timing(this.state.lineLength, {
toValue: this.wrapperWidth,
duration: this.props.duration
}).start();
}
shrinkLine() {
Animated.timing(this.state.lineLength, {
toValue: 0,
duration: this.props.duration
}).start();
}
render() {
let {
borderColor,
highlightColor
} = this.props;
return (
<View
style={[styles.underlineWrapper, {
backgroundColor: borderColor
}]}
ref="wrapper"
>
<Animated.View
style={[{
width: this.state.lineLength,
height: 1,
backgroundColor: highlightColor
}]}>
</Animated.View>
</View>
);
}
}
Underline.propTypes = {
duration: PropTypes.number,
highlightColor: PropTypes.string,
borderColor: PropTypes.string
};
const styles = StyleSheet.create({
underlineWrapper: {
height: 1,
alignItems: 'center'
}
});