| 504 | } |
| 505 | |
| 506 | export function focusWithin( |
| 507 | hostRoot: Instance, |
| 508 | selectors: Array<Selector>, |
| 509 | ): boolean { |
| 510 | if (!supportsTestSelectors) { |
| 511 | throw new Error('Test selector API is not supported by this renderer.'); |
| 512 | } |
| 513 | |
| 514 | const root = findFiberRootForHostRoot(hostRoot); |
| 515 | const matchingFibers = findPaths(root, selectors); |
| 516 | |
| 517 | const stack = Array.from(matchingFibers); |
| 518 | let index = 0; |
| 519 | while (index < stack.length) { |
| 520 | const fiber = ((stack[index++]: any): Fiber); |
| 521 | const tag = fiber.tag; |
| 522 | if (isHiddenSubtree(fiber)) { |
| 523 | continue; |
| 524 | } |
| 525 | if ( |
| 526 | tag === HostComponent || |
| 527 | tag === HostHoistable || |
| 528 | tag === HostSingleton |
| 529 | ) { |
| 530 | const node = fiber.stateNode; |
| 531 | if (setFocusIfFocusable(node)) { |
| 532 | return true; |
| 533 | } |
| 534 | } |
| 535 | let child = fiber.child; |
| 536 | while (child !== null) { |
| 537 | stack.push(child); |
| 538 | child = child.sibling; |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | return false; |
| 543 | } |
| 544 | |
| 545 | const commitHooks: Array<Function> = []; |
| 546 | |