11import { jsx , Canvas , Component } from '../../../src' ;
2+ import { getWorkTag } from '../../../src/canvas/workTags' ;
23import { computeComponentBBox } from '../../../src/canvas/render' ;
34import { createContext , delay } from '@antv/f-test-utils' ;
45
6+ const FunctionComponent = 0 ;
7+ const ClassComponent = 1 ;
8+
59class View extends Component {
610 willMount ( ) : void { }
711 render ( ) {
@@ -68,6 +72,9 @@ class ViewText extends Component {
6872 }
6973}
7074
75+ const ViewWithDisplay = ( props ) => {
76+ return < ViewWithDisplayGroup { ...props } /> ;
77+ } ;
7178class GuideGroup extends Component {
7279 bbox = [ ] ;
7380
@@ -76,10 +83,16 @@ class GuideGroup extends Component {
7683 const { updater, context } = this ;
7784 const childArray = Array . isArray ( children ) ? children : [ children ] ;
7885 childArray . map ( ( child ) => {
79- const component = new child . type ( child . props , context , updater ) ;
80- component . context = context ;
86+ const tag = getWorkTag ( child . type ) ;
87+ let element = child ;
8188
82- const bbox = computeComponentBBox ( this , component . render ( ) ) ;
89+ if ( tag === FunctionComponent ) {
90+ element = child . type ( child . props , context , updater ) ;
91+ }
92+ const component = new element . type ( { ...element . props } , context , updater ) ;
93+ component . context = context ;
94+ const newElement = component . render ( ) ;
95+ const bbox = computeComponentBBox ( this , newElement ) ;
8396 this . bbox . push ( bbox ) ;
8497 } ) ;
8598 }
@@ -127,6 +140,7 @@ describe('computeComponent', () => {
127140 < Canvas context = { context } >
128141 < GuideGroup ref = { guideGroupRef } >
129142 < ViewWithDisplayGroup />
143+ < ViewWithDisplay position = { [ 20 , 20 ] } />
130144 </ GuideGroup >
131145 </ Canvas >
132146 ) ;
@@ -141,6 +155,9 @@ describe('computeComponent', () => {
141155 expect ( bbox [ 0 ] . y ) . toEqual ( 0 ) ;
142156 expect ( bbox [ 0 ] . width ) . toBeGreaterThan ( 20 ) ;
143157 expect ( bbox [ 0 ] . height ) . toBeGreaterThan ( 10 ) ;
158+
159+ expect ( bbox [ 1 ] . x ) . toEqual ( 20 ) ;
160+ expect ( bbox [ 1 ] . y ) . toEqual ( 20 ) ;
144161 } ) ;
145162
146163 it ( 'View内的group带padding样式' , async ( ) => {
0 commit comments