@@ -15,13 +15,10 @@ const filterNodeByName = (node, name) =>
1515 typeof node . type !== 'string' &&
1616 ( node . type . displayName === name || node . type . name === name ) ;
1717
18- let textContent = [ ] ;
19-
2018const getNodeByText = ( node , text ) => {
2119 try {
2220 // eslint-disable-next-line
23- const { Text } = require ( 'react-native' ) ;
24- textContent = [ ] ;
21+ const { Text } = require ( 'react-native' ) ;
2522 const isTextComponent = filterNodeByType ( node , Text ) ;
2623 if ( isTextComponent ) {
2724 const textChildren = getChildrenAsText ( node . props . children , Text ) ;
@@ -38,18 +35,20 @@ const getNodeByText = (node, text) => {
3835 }
3936} ;
4037
41- const getChildrenAsText = ( children , textComponent ) => {
42- React . Children . map ( children , child => {
38+ const getChildrenAsText = ( children , TextComponent , textContent = [ ] ) => {
39+ React . Children . forEach ( children , child => {
4340 if ( typeof child === 'string' ) {
44- return textContent . push ( child ) ;
41+ textContent . push ( child ) ;
42+ return ;
4543 }
4644
4745 if ( typeof child === 'number' ) {
48- return textContent . push ( child . toString ( ) ) ;
46+ textContent . push ( child . toString ( ) ) ;
47+ return ;
4948 }
5049
51- if ( child . props . children ) {
52- getChildrenAsText ( child . props . children , textComponent ) ;
50+ if ( child ? .props ? .children ) {
51+ getChildrenAsText ( child . props . children , TextComponent , textContent ) ;
5352 }
5453 } ) ;
5554
0 commit comments