DEV Community

HarmonyOS
HarmonyOS

Posted on

Make Small Icons Easy to Tap: Enlarging Image Hit Areas with responseRegion or Wrapper Padding (ArkUI)

Read the original article:Make Small Icons Easy to Tap: Enlarging Image Hit Areas with responseRegion or Wrapper Padding (ArkUI)

Make Small Icons Easy to Tap: Enlarging Image Hit Areas with responseRegion or Wrapper Padding (ArkUI)

When a small Image is hard to tap, make its inter

Requirement Description

active/tap area larger while keeping the visual size unchanged.

Background Knowledge

  • responseRegion can enlarge the component’s hit area beyond its visual bounds. Docs:
  • Alternatively, wrap the Image in a container and enlarge that container’s size or padding, then attach the tap handler to the container.

Implementation Steps

  1. Approach A — responseRegion
    Keep the Image small but set a larger responseRegion { width, height } to expand its hit rectangle.

  2. Approach B — Wrapper Container
    Put the Image inside a Row/Stack/Container. Increase the wrapper’s padding (or explicit width/height) and place the .onClick on the wrapper, not the Image.

  3. (Wearables) Use a minimum tap target of 40–48 vp for comfort on small round screens.

  4. Test with Accessibility tools if applicable (bigger targets improve usability).

Code Snippet / Configuration

Approach A — Using responseRegion

@Entry
@Component
struct Index {
  build() {
    Column() {
      Image($r('app.media.startIcon'))
        .width(20)
        .height(20)
        .onClick(() => {
          this.getUIContext().getPromptAction().showToast({ message: 'Triggered' })
        })
        // Enlarges the interactive/tap area (does not change visual size)
        .responseRegion({ width: 200, height: 200 })
    }
    .justifyContent(FlexAlign.Center)
    .width('100%')
    .height('100%')
    .backgroundColor(0xDCDCDC)
    .padding({ top: 5 })
  }
}
Enter fullscreen mode Exit fullscreen mode

Approach B — Wrapper with Padding (attach onClick to wrapper)

@Entry
@Component
struct Index {
  build() {
    Column() {
      // The Row becomes the large tap target
      Row() {
        Image($r('app.media.startIcon'))
          .width(20)
          .height(20)
      }
      .padding({ all: 100 }) // Enlarge actual clickable area via padding
      .onClick(() => {
        this.getUIContext().getPromptAction().showToast({ message: 'Triggered' })
      })
    }
    .justifyContent(FlexAlign.Center)
    .width('100%')
    .height('100%')
    .backgroundColor(0xDCDCDC)
    .padding({ top: 5 })
  }
}
Enter fullscreen mode Exit fullscreen mode

Test Results

  • Both approaches allow comfortable tapping even when the icon’s visual size remains 20 vp.

7.gif

Limitations or Considerations

  • responseRegion enlarges a rectangular region; it doesn’t support arbitrary shapes.
  • Wrapper approach affects layout if you use margins; prefer padding on the wrapper to grow the hit area without pushing siblings.
  • For wearables, keep targets ≥ 40–48 vp and avoid placing critical targets near bezel edges.

Related Documents or Links

Written by Bunyamin Eymen Alagoz

Top comments (0)