block / block/radiography

Feature Request: Add Position Coordinates to View Hierarchy Output

Open
#181 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
899
Forks
55
PR merge metrics
No merged PRs in 30d

Description

## Summary

what do you guys think in add an optional parameter to include position coordinates (x, y) in the view hierarchy output, making it easier to understand the spatial layout of views on screen.

## Motivation

Currently, Radiography displays the dimensions (width × height) of each view but doesn't show their position on screen. This makes it difficult to:

- Debug layout positioning issues
- Understand overlapping views
- Identify views at specific screen coordinates
- Correlate the hierarchy with visual bugs in screenshots

### Current Output Example
```
DecorView { 1080×2400px }
╰─LinearLayout { 1080×2400px }
├─ViewStub { id:action_mode_bar_stub, GONE, 0×0px }
╰─FrameLayout { id:content, 1080×2400px }
╰─ComposeView { 1080×2400px }
╰─Button { 954×147px, role:Button }
```

### Proposed Output Example (with positions)
```
DecorView { 1080×2400px@(0,0) }
╰─LinearLayout { 1080×2400px@(0,0) }
├─ViewStub { id:action_mode_bar_stub, GONE, 0×0px@(0,0) }
╰─FrameLayout { id:content, 1080×2400px@(0,0) }
╰─ComposeView { 1080×2400px@(0,0) }
╰─Button { 954×147px@(63,1226), role:Button }
```

## Proposed Solution

Add an optional `includePosition` parameter to the `Radiography.scan()` method that defaults to `false` to maintain backward compatibility.

### API Changes

```kotlin
fun scan(
scanScope: ScanScope = AllWindowsScope,
viewStateRenderers: List = DefaultsNoPii,
viewFilter: ViewFilter = ViewFilters.NoFilter,
includePosition: Boolean = false // New parameter
): String
```

### Usage Example

```kotlin
// Default behavior (backward compatible)
val hierarchy = Radiography.scan()

// With position coordinates
val hierarchyWithPositions = Radiography.scan(includePosition = true)
```

I'm happy to submit a PR with the proposed changes if the maintainers are interested in this functionality.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.