File tree 2 files changed +64
-2
lines changed
src/components/field-outlined
2 files changed +64
-2
lines changed Original file line number Diff line number Diff line change 1
1
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' ;
3
4
4
- export { TextField , FilledTextField } ;
5
+ export { TextField , FilledTextField , OutlinedTextField } ;
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments