@@ -16,14 +16,6 @@ import StyleSheet from '../../StyleSheet/StyleSheet';
1616import Text from '../../Text/Text' ;
1717import * as React from 'react' ;
1818
19- type Props = {
20- message : Message ,
21- style : TextStyleProp ,
22- plaintext ?: ?boolean ,
23- maxLength ?: ?number ,
24- ...
25- } ;
26-
2719type Range = {
2820 lowerBound : number ,
2921 upperBound : number ,
@@ -46,15 +38,12 @@ function getLinkRanges(string: string): ReadonlyArray<Range> {
4638 return matches ;
4739}
4840
49- function TappableLinks ( props : {
50- content : string ,
51- style : void | TextStyleProp ,
52- } ) : React . Node {
53- const matches = getLinkRanges ( props . content ) ;
41+ component TappableLinks ( content : string , style : void | TextStyleProp ) {
42+ const matches = getLinkRanges ( content ) ;
5443
5544 if ( matches . length === 0 ) {
5645 // No URLs detected. Just return the content.
57- return < Text style = { props . style } > { props . content } </ Text > ;
46+ return < Text style = { style } > { content } </ Text > ;
5847 }
5948
6049 // URLs were detected. Construct array of Text nodes.
@@ -65,14 +54,11 @@ function TappableLinks(props: {
6554
6655 for (const linkRange of matches) {
6756 if ( startIndex < linkRange . lowerBound ) {
68- const text = props . content . substring ( startIndex , linkRange . lowerBound ) ;
57+ const text = content . substring ( startIndex , linkRange . lowerBound ) ;
6958 fragments . push ( < Text key = { ++ indexCounter } > { text } </ Text > ) ;
7059 }
7160
72- const link = props . content . substring (
73- linkRange . lowerBound ,
74- linkRange . upperBound ,
75- ) ;
61+ const link = content . substring ( linkRange . lowerBound , linkRange . upperBound ) ;
7662 fragments . push (
7763 < Text
7864 onPress = { ( ) => {
@@ -88,46 +74,51 @@ function TappableLinks(props: {
8874 startIndex = linkRange . upperBound ;
8975 }
9076
91- if ( startIndex < props . content . length ) {
92- const text = props . content . substring ( startIndex ) ;
77+ if ( startIndex < content . length ) {
78+ const text = content . substring ( startIndex ) ;
9379 fragments . push (
94- < Text key = { ++ indexCounter } style = { props . style } >
80+ < Text key = { ++ indexCounter } style = { style } >
9581 { text }
9682 </ Text > ,
9783 ) ;
9884 }
9985
100- return < Text style = { props . style} > { fragments} < / T e x t > ;
86+ return < Text style = { style } > { fragments } </ Text > ;
10187}
10288
10389const cleanContent = ( content : string ) =>
10490 content . replace ( / ^ ( T r a n s f o r m E r r o r | E r r o r : ) / g, '' ) ;
10591
106- function LogBoxMessage ( props : Props ) : React . Node {
107- const { content, substitutions} : Message = props . message ;
92+ component LogBoxMessage (
93+ message : Message ,
94+ style : TextStyleProp ,
95+ plaintext ?: ?boolean ,
96+ maxLength ?: ?number ,
97+ ) {
98+ const { content , substitutions } : Message = message ;
10899
109- if ( props . plaintext === true ) {
100+ if ( plaintext === true ) {
110101 return < Text > { cleanContent ( content ) } </ Text > ;
111102 }
112103
113- const maxLength = props . maxLength != null ? props . maxLength : Infinity ;
114- const substitutionStyle : TextStyleProp = props . style ;
104+ const resolvedMaxLength = maxLength != null ? maxLength : Infinity ;
105+ const substitutionStyle : TextStyleProp = style ;
115106 const elements = [ ] ;
116107 let length = 0 ;
117108 const createUnderLength = (
118109 key : string ,
119- message : string ,
120- style : void | TextStyleProp ,
110+ messageText : string ,
111+ textStyle : void | TextStyleProp ,
121112 ) => {
122- let cleanMessage = cleanContent ( message ) ;
113+ let cleanMessage = cleanContent ( messageText ) ;
123114
124- if ( props . maxLength != null ) {
125- cleanMessage = cleanMessage . slice ( 0 , props . maxLength - length ) ;
115+ if ( maxLength != null ) {
116+ cleanMessage = cleanMessage . slice ( 0 , maxLength - length ) ;
126117 }
127118
128- if ( length < maxLength ) {
119+ if ( length < resolvedMaxLength ) {
129120 elements . push (
130- < TappableLinks content = { cleanMessage } key = { key } style = { style } /> ,
121+ < TappableLinks content = { cleanMessage } key = { key } style = { textStyle } /> ,
131122 ) ;
132123 }
133124
0 commit comments