Skip to content

Commit d79971a

Browse files
committed
1. Removed pexels_demo.jpg and used the existing image.
2. Excluded un-related code snippets using in the output. 3. Addressed comments on the PR
1 parent 7697fb6 commit d79971a

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

compose/snippets/src/main/java/com/example/compose/snippets/touchinput/scroll/ScrollSnippets.kt renamed to compose/snippets/src/main/java/com/example/compose/snippets/touchinput/scroll/TwoDimensionalScrollSnippets.kt

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ fun Scrollable2DSample() {
7373
Box(
7474
modifier = Modifier
7575
.fillMaxSize()
76+
// [START_EXCLUDE]
7677
.background(Color(0xFFF5F5F5)),
78+
// [END_EXCLUDE]
7779
contentAlignment = Alignment.Center
7880
) {
7981
Box(
@@ -89,7 +91,9 @@ fun Scrollable2DSample() {
8991
delta
9092
}
9193
)
94+
// [START_EXCLUDE]
9295
.background(Color(0xFF6200EE), shape = RoundedCornerShape(16.dp)),
96+
// [END_EXCLUDE]
9397
contentAlignment = Alignment.Center
9498
) {
9599
Column(horizontalAlignment = Alignment.CenterHorizontally) {
@@ -116,7 +120,7 @@ fun Scrollable2DSample() {
116120

117121
// [START android_compose_touchinput_scroll_scrollable2D_pan_large_viewport]
118122
@Composable
119-
fun ImageViewer2D(modifier: Modifier) {
123+
fun Panning2DImage(modifier: Modifier) {
120124

121125
// Manually track the total distance the user has moved in both X and Y directions
122126
val offset = remember { mutableStateOf(Offset.Zero) }
@@ -131,17 +135,19 @@ fun ImageViewer2D(modifier: Modifier) {
131135
Box(
132136
modifier = modifier
133137
.size(600.dp, 400.dp) // The visible area dimensions
138+
// [START_EXCLUDE]
134139
.border(width = 2.dp, color = Color.Black, shape = RoundedCornerShape(0.dp))
135140
.background(color = Color.LightGray)
136-
// Hide any parts of the large content that sit outside this container's boundarie
141+
// [END_EXCLUDE]
142+
// Hide any parts of the large content that sit outside this container's boundaries
137143
.clipToBounds()
138144
// Apply the 2D scroll modifier to intercept touch and fling gestures in all directions
139145
.scrollable2D(state = scrollState),
140146
contentAlignment = Alignment.Center,
141147
) {
142148
// The Content: An image given a much larger size than the container viewport
143149
Image(
144-
painter = painterResource(R.drawable.pexels_demo),
150+
painter = painterResource(R.drawable.cheese_5),
145151
contentDescription = null,
146152
modifier = Modifier
147153
.requiredSize(1200.dp, 800.dp)
@@ -164,7 +170,6 @@ fun NestedScrollable2DSample() {
164170
val offset = remember { mutableStateOf(Offset.Zero) }
165171
val maxScroll = 300f
166172

167-
// The Parent: A standard vertical scroll container
168173
Column(
169174
modifier = Modifier
170175
.fillMaxSize()
@@ -202,7 +207,9 @@ fun NestedScrollable2DSample() {
202207
consumed
203208
}
204209
)
210+
// [START_EXCLUDE]
205211
.background(Color(0xFF6200EE), shape = RoundedCornerShape(16.dp)),
212+
// [END_EXCLUDE]
206213
contentAlignment = Alignment.Center
207214
) {
208215
Column(horizontalAlignment = Alignment.CenterHorizontally) {
@@ -226,7 +233,7 @@ fun NestedScrollable2DSample() {
226233

227234
// [START android_compose_touchinput_scroll_draggable2D_basic]
228235
@Composable
229-
fun DraggableComposableWindow() {
236+
fun DraggableComposableElement() {
230237
// 1. Track the position of the floating window
231238
var offset by remember { mutableStateOf(Offset.Zero) }
232239

@@ -235,9 +242,11 @@ fun DraggableComposableWindow() {
235242
modifier = Modifier
236243
// 2. Apply the offset to the box's position
237244
.offset { IntOffset(offset.x.roundToInt(), offset.y.roundToInt()) }
245+
// [START_EXCLUDE]
238246
.size(160.dp, 90.dp)
239247
.background(Color.Black, RoundedCornerShape(8.dp))
240248
.border(1.dp, Color.White, RoundedCornerShape(8.dp))
249+
// [END_EXCLUDE]
241250
// 3. Attach the 2D drag logic
242251
.draggable2D(
243252
state = rememberDraggable2DState { delta ->
@@ -256,10 +265,12 @@ fun DraggableComposableWindow() {
256265

257266
// [START android_compose_touchinput_scroll_draggable2D_color_picker]
258267
@Composable
259-
fun ColorPicker2D(
268+
fun ExampleColorSelector(
269+
// [START_EXCLUDE]
260270
hue: Float = 0f,
261271
onColorSelected: (Saturation: Float, Value: Float) -> Unit
262-
) {
272+
// [END_EXCLUDE]
273+
) {
263274
// 1. Maintain the 2D position of the selector in state.
264275
var selectorOffset by remember { mutableStateOf(Offset.Zero) }
265276

@@ -279,40 +290,41 @@ fun ColorPicker2D(
279290
}
280291
)
281292
) {
282-
// The Selector Knob
283293
Box(
284294
modifier = Modifier
285295
.size(24.dp)
286-
// 3. This applies the offset during the Drawing phase
287296
.graphicsLayer {
288297
// Center the selector on the finger by subtracting half its size.
289298
translationX = selectorOffset.x - (24.dp.toPx() / 2)
290299
translationY = selectorOffset.y - (24.dp.toPx() / 2)
291300
}
292-
// 4. Configure the shadow
301+
// [START_EXCLUDE]
302+
// Configure the shadow
293303
.dropShadow(shape = CircleShape) {
294304
color = Color.Black.copy(alpha = 0.2f)
295305
radius = 4.dp.toPx()
296306
offset = Offset(0f, 2.dp.toPx())
297307
}
298308
.background(Color.Transparent, CircleShape)
299309
.border(2.dp, Color.White, CircleShape)
300-
// 5. Configure 2D touch dragging.
310+
// [END_EXCLUDE]
311+
// 3. Configure 2D touch dragging.
301312
.draggable2D(
302313
state = rememberDraggable2DState { delta ->
303-
// 6. Calculate the new position and clamp it to the container bounds
314+
// 4. Calculate the new position and clamp it to the container bounds
304315
val newX = (selectorOffset.x + delta.x)
305316
.coerceIn(0f, containerSize.width.toFloat())
306317
val newY = (selectorOffset.y + delta.y)
307318
.coerceIn(0f, containerSize.height.toFloat())
308319

309320
selectorOffset = Offset(newX, newY)
310-
311-
// 7. Map pixel coordinates to Saturation and Value percentages (0f..1f).
321+
// [START_EXCLUDE]
322+
// Map pixel coordinates to Saturation and Value percentages (0f..1f).
312323
onColorSelected(
313324
newX / containerSize.width,
314325
1f - (newY / containerSize.height)
315326
)
327+
// [END_EXCLUDE]
316328
}
317329
)
318330
)
-1.14 MB
Binary file not shown.

0 commit comments

Comments
 (0)