@@ -15,13 +15,10 @@ const filterNodeByName = (node, name) =>
15
15
typeof node . type !== 'string' &&
16
16
( node . type . displayName === name || node . type . name === name ) ;
17
17
18
- let textContent = [ ] ;
19
-
20
18
const getNodeByText = ( node , text ) => {
21
19
try {
22
20
// eslint-disable-next-line
23
- const { Text } = require ( 'react-native' ) ;
24
- textContent = [ ] ;
21
+ const { Text } = require ( 'react-native' ) ;
25
22
const isTextComponent = filterNodeByType ( node , Text ) ;
26
23
if ( isTextComponent ) {
27
24
const textChildren = getChildrenAsText ( node . props . children , Text ) ;
@@ -38,18 +35,20 @@ const getNodeByText = (node, text) => {
38
35
}
39
36
} ;
40
37
41
- const getChildrenAsText = ( children , textComponent ) => {
42
- React . Children . map ( children , child => {
38
+ const getChildrenAsText = ( children , TextComponent , textContent = [ ] ) => {
39
+ React . Children . forEach ( children , child => {
43
40
if ( typeof child === 'string' ) {
44
- return textContent . push ( child ) ;
41
+ textContent . push ( child ) ;
42
+ return ;
45
43
}
46
44
47
45
if ( typeof child === 'number' ) {
48
- return textContent . push ( child . toString ( ) ) ;
46
+ textContent . push ( child . toString ( ) ) ;
47
+ return ;
49
48
}
50
49
51
- if ( child . props . children ) {
52
- getChildrenAsText ( child . props . children , textComponent ) ;
50
+ if ( child ? .props ? .children ) {
51
+ getChildrenAsText ( child . props . children , TextComponent , textContent ) ;
53
52
}
54
53
} ) ;
55
54
0 commit comments