Skip to content

Commit 9a40ab3

Browse files
committed
Implemented OulinedTextField component
1 parent a4a3c65 commit 9a40ab3

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import TextField from './src/components/field';
2-
import FilledTextField from './src/components/filled';
2+
import FilledTextField from './src/components/field-filled';
3+
import OutlinedTextField from './src/components/field-outlined';
34

4-
export { TextField, FilledTextField };
5+
export { TextField, FilledTextField, OutlinedTextField };
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from 'react';
2+
import { Animated, StyleSheet } from 'react-native';
3+
4+
import TextField from '../field';
5+
import Outline from '../outline';
6+
7+
export default class OutlinedTextField extends TextField {
8+
static contentInset = {
9+
...TextField.contentInset,
10+
11+
input: 16,
12+
13+
top: 0,
14+
left: 12,
15+
right: 12,
16+
};
17+
18+
static labelOffset = {
19+
...TextField.labelOffset,
20+
21+
y0: 0,
22+
y1: -10,
23+
};
24+
25+
static defaultProps = {
26+
...TextField.defaultProps,
27+
28+
lineWidth: 1,
29+
disabledLineWidth: StyleSheet.hairlineWidth,
30+
};
31+
32+
constructor(props) {
33+
super(props);
34+
35+
this.onTextLayout = this.onTextLayout.bind(this);
36+
this.state.labelWidth = new Animated.Value(0);
37+
}
38+
39+
onTextLayout({ nativeEvent: { lines } }) {
40+
let { fontSize, labelFontSize } = this.props;
41+
let { labelWidth } = this.state;
42+
43+
let scale = labelFontSize / fontSize;
44+
45+
labelWidth.setValue(lines[0].width * scale);
46+
}
47+
48+
renderLabel(props) {
49+
let { onTextLayout } = this;
50+
51+
return super.renderLabel({ ...props, onTextLayout });
52+
}
53+
54+
renderLine(props) {
55+
let { labelWidth } = this.state;
56+
57+
return (
58+
<Outline {...props} labelWidth={labelWidth} />
59+
);
60+
}
61+
}

0 commit comments

Comments
 (0)