|
1 | 1 | # Modifier.zoomable()
|
2 | 2 |
|
3 |
| -A `Modifier` for handling pan & zoom gestures, designed to be shared across all your media composables so that your users can use the same familiar gestures throughout your app. It offers, |
| 3 | +A `Modifier` for handling pan & zoom gestures, designed to be shared across all your media composables so that your users can use the same familiar gestures throughout your app. |
4 | 4 |
|
5 |
| -- Pinch to zoom and flings |
6 |
| -- Double click to zoom |
7 |
| -- Single finger zoom (double click and hold) |
8 |
| -- Haptic feedback for over/under zoom |
| 5 | +**Features** |
| 6 | + |
| 7 | +- Gestures: |
| 8 | + - Pinch-to-zoom and flings |
| 9 | + - Double click to zoom |
| 10 | + - Single finger zoom (double-tap and hold) |
| 11 | +- Haptic feedback when reaching zoom limits |
9 | 12 | - Compatibility with nested scrolling
|
10 | 13 | - Click listeners
|
11 | 14 | - [Keyboard and mouse shortcuts](#keyboard-shortcuts)
|
| 15 | +- State preservation across config changes (including screen rotations) |
12 | 16 |
|
13 | 17 | ### Installation
|
14 | 18 |
|
@@ -42,11 +46,9 @@ For preventing your content from over-zooming or over-panning, `Modifier.zoomabl
|
42 | 46 | For richer content such as an `Image()` whose _visual_ size may not always match its layout size, `Modifier.zoomable()` will need your assistance.
|
43 | 47 |
|
44 | 48 | ```kotlin hl_lines="5-7"
|
45 |
| -val state = rememberZoomableState() |
46 | 49 | val painter = resourcePainter(R.drawable.example)
|
47 |
| - |
48 |
| -LaunchedEffect(painter.intrinsicSize) { |
49 |
| - state.setContentLocation( |
| 50 | +val zoomableState = rememberZoomableState().apply { |
| 51 | + setContentLocation( |
50 | 52 | ZoomableContentLocation.scaledInsideAndCenterAligned(painter.intrinsicSize)
|
51 | 53 | )
|
52 | 54 | }
|
|
55 | 57 | modifier = Modifier
|
56 | 58 | .fillMaxSize()
|
57 | 59 | .background(Color.Orange)
|
58 |
| - .zoomable(state), |
| 60 | + .zoomable(zoomableState), |
59 | 61 | painter = painter,
|
60 | 62 | contentDescription = …,
|
61 | 63 | contentScale = ContentScale.Inside,
|
|
0 commit comments