@@ -12,14 +12,14 @@ class AutoScaleText extends React.Component {
12
12
static propTypes = {
13
13
...Text . propTypes ,
14
14
maxFontSize : React . PropTypes . number . isRequired ,
15
- maxHeight : React . PropTypes . number . isRequired ,
15
+ // maxHeight: React.PropTypes.number.isRequired,
16
16
color : React . PropTypes . string ,
17
- style : React . PropTypes . oneOfType ( [
18
- Text . propTypes . style ,
19
- React . PropTypes . shape ( {
20
- width : React . PropTypes . number ,
21
- } ) ,
22
- ] ) . isRequired ,
17
+ // style: React.PropTypes.oneOfType([
18
+ // React.PropTypes.number ,
19
+ // React.PropTypes.shape({
20
+ // width: React.PropTypes.number,
21
+ // }),
22
+ //]) ,
23
23
} ;
24
24
25
25
static defaultProps = {
@@ -31,17 +31,21 @@ class AutoScaleText extends React.Component {
31
31
32
32
this . state = {
33
33
fontSize : props . maxFontSize ,
34
- finished : false ,
34
+ finished : null ,
35
35
} ;
36
36
37
- this . visible = true ;
37
+ this . visible = true
38
38
}
39
39
40
40
determineFontSize = ( ) => {
41
41
UIManager . measure ( ReactNative . findNodeHandle ( this . refs . textView ) , ( x , y , w , h , px , py ) => {
42
42
if ( ! this . visible ) return ;
43
43
44
- if ( h > this . props . maxHeight ) {
44
+ var tooBig = this . props . maxHeight && h > this . props . maxHeight ;
45
+ if ( ! tooBig ) {
46
+ tooBig = this . props . maxWidth && w > this . props . maxWidth ;
47
+ }
48
+ if ( tooBig ) {
45
49
this . setState ( {
46
50
fontSize : this . state . fontSize - 0.5 ,
47
51
} ) ;
@@ -61,13 +65,14 @@ class AutoScaleText extends React.Component {
61
65
return (
62
66
< Text
63
67
ref = 'textView'
64
- onLayout = { this . determineFontSize }
68
+ //onLayout={this.determineFontSize}
69
+ allowFontScaling = { false }
65
70
{ ...this . props }
66
71
style = { [
67
72
this . props . style ,
68
73
{
69
74
fontSize : this . state . fontSize ,
70
- color : this . state . finished ? this . props . color : 'transparent' ,
75
+ // color: this.state.finished ? this.props.color || 'black' : 'transparent',
71
76
} ,
72
77
] }
73
78
>
0 commit comments