संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
'नीचे खींचकर रीफ़्रेश करें' सुविधा की मदद से, उपयोगकर्ता किसी ऐप्लिकेशन के कॉन्टेंट को नीचे की ओर खींचकर डेटा रीफ़्रेश कर सकते हैं.
एपीआई सरफेस
पुल-टू-रिफ़्रेश की सुविधा लागू करने के लिए, PullToRefreshBox कंपोज़ेबल का इस्तेमाल करें. यह स्क्रोल किए जा सकने वाले कॉन्टेंट के लिए कंटेनर के तौर पर काम करता है. ये मुख्य पैरामीटर, रीफ़्रेश होने की प्रोसेस और दिखने के तरीके को कंट्रोल करते हैं:
isRefreshing: यह एक बूलियन वैल्यू है. इससे पता चलता है कि रीफ़्रेश करने की प्रोसेस चल रही है या नहीं.
onRefresh: यह एक लैम्डा फ़ंक्शन है, जो उपयोगकर्ता के रीफ़्रेश करने पर काम करता है.
indicator: इससे उस इंडिकेटर को पसंद के मुताबिक बनाया जाता है जिसे सिस्टम, पुल-टू-रीफ़्रेश पर दिखाता है.
बुनियादी उदाहरण
इस स्निपेट में, PullToRefreshBox के बुनियादी इस्तेमाल के बारे में बताया गया है:
indicator पैरामीटर में मौजूद containerColor और color प्रॉपर्टी की मदद से, इंडिकेटर के रंग को पसंद के मुताबिक बनाया जाता है.
rememberPullToRefreshState() रीफ़्रेश करने की कार्रवाई की स्थिति को मैनेज करता है.
इस स्थिति का इस्तेमाल, indicator पैरामीटर के साथ किया जाता है.
नतीजा
इस वीडियो में, रंगीन इंडिकेटर के साथ पुल-टू-रिफ़्रेश सुविधा को लागू करने का तरीका दिखाया गया है:
दूसरी इमेज. कस्टम स्टाइल के साथ पुल-टू-रीफ़्रेश सुविधा लागू करने का उदाहरण.
ऐडवांस उदाहरण: पूरी तरह से कस्टम इंडिकेटर बनाना
मौजूदा कंपोज़ेबल और ऐनिमेशन का इस्तेमाल करके, जटिल कस्टम इंडिकेटर बनाए जा सकते हैं.इस स्निपेट में, पुल-टू-रिफ़्रेश सुविधा को लागू करने के दौरान, पूरी तरह से कस्टम इंडिकेटर बनाने का तरीका बताया गया है:
पिछले स्निपेट में, लाइब्रेरी से मिले Indicator का इस्तेमाल किया गया था. इस स्निपेट से, MyCustomIndicator नाम का कस्टम इंडिकेटर कंपोज़ेबल बनाया जाता है. इस कॉम्पोज़ेबल में, pullToRefreshIndicator मॉडिफ़ायर, रीफ़्रेश करने की सुविधा को चालू करने और उसकी पोज़िशन को मैनेज करता है.
पिछले स्निपेट की तरह, इस उदाहरण में PullToRefreshState इंस्टेंस को एक्सट्रैक्ट किया गया है, ताकि PullToRefreshBox और pullToRefreshModifier, दोनों को एक ही इंस्टेंस पास किया जा सके.
इस उदाहरण में, PullToRefreshDefaults क्लास से कंटेनर के रंग और पोज़िशन थ्रेशोल्ड का इस्तेमाल किया गया है. इस तरह, Material लाइब्रेरी के डिफ़ॉल्ट व्यवहार और स्टाइल का फिर से इस्तेमाल किया जा सकता है. साथ ही, सिर्फ़ उन एलिमेंट को पसंद के मुताबिक बनाया जा सकता है जिनमें आपकी दिलचस्पी है.
MyCustomIndicator, क्लाउड आइकॉन और CircularProgressIndicator के बीच ट्रांज़िशन के लिए Crossfade का इस्तेमाल करता है. उपयोगकर्ता के खींचने पर, क्लाउड आइकॉन बड़ा होता है. इसके बाद, रीफ़्रेश करने की प्रोसेस शुरू होने पर, यह CircularProgressIndicator में बदल जाता है.
targetState, isRefreshing का इस्तेमाल करके यह तय करता है कि कौनसी स्थिति दिखानी है. जैसे, क्लाउड आइकॉन या गतिविधि की स्थिति सर्कुलर फ़ॉर्मैट में दिखाने वाला इंडिकेटर.
animationSpec ट्रांज़िशन के लिए tween ऐनिमेशन तय करता है. इसकी अवधि CROSSFADE_DURATION_MILLIS होती है.
state.distanceFraction से पता चलता है कि उपयोगकर्ता ने स्क्रीन को कितना नीचे खींचा है. इसकी रेंज 0f (नीचे नहीं खींचा गया) से लेकर 1f (पूरी तरह से नीचे खींचा गया) तक होती है.
graphicsLayer मॉडिफ़ायर, स्केल और पारदर्शिता में बदलाव करता है.
नतीजा
इस वीडियो में, ऊपर दिए गए कोड से बनाया गया कस्टम इंडिकेटर दिखाया गया है:
तीसरी इमेज. कस्टम इंडिकेटर के साथ पुल-टू-रिफ़्रेश सुविधा लागू करने का उदाहरण.
इस पेज पर मौजूद कॉन्टेंट और कोड सैंपल कॉन्टेंट के लाइसेंस में बताए गए लाइसेंस के हिसाब से हैं. Java और OpenJDK, Oracle और/या इससे जुड़ी हुई कंपनियों के ट्रेडमार्क या रजिस्टर किए हुए ट्रेडमार्क हैं.
आखिरी बार 2025-08-27 (UTC) को अपडेट किया गया.
[[["समझने में आसान है","easyToUnderstand","thumb-up"],["मेरी समस्या हल हो गई","solvedMyProblem","thumb-up"],["अन्य","otherUp","thumb-up"]],[["वह जानकारी मौजूद नहीं है जो मुझे चाहिए","missingTheInformationINeed","thumb-down"],["बहुत मुश्किल है / बहुत सारे चरण हैं","tooComplicatedTooManySteps","thumb-down"],["पुराना","outOfDate","thumb-down"],["अनुवाद से जुड़ी समस्या","translationIssue","thumb-down"],["सैंपल / कोड से जुड़ी समस्या","samplesCodeIssue","thumb-down"],["अन्य","otherDown","thumb-down"]],["आखिरी बार 2025-08-27 (UTC) को अपडेट किया गया."],[],[],null,["The pull to refresh component allows users to drag downwards at the beginning of\nan app's content to refresh the data.\n| **Note:** [`PullToRefreshBox()`](/reference/kotlin/androidx/compose/material3/pulltorefresh/package-summary#PullToRefreshBox(kotlin.Boolean,kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.material3.pulltorefresh.PullToRefreshState,androidx.compose.ui.Alignment,kotlin.Function1,kotlin.Function1)) is experimental.\n\nAPI surface\n\nUse the [`PullToRefreshBox`](/reference/kotlin/androidx/compose/material3/pulltorefresh/package-summary#PullToRefreshBox(kotlin.Boolean,kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.material3.pulltorefresh.PullToRefreshState,androidx.compose.ui.Alignment,kotlin.Function1,kotlin.Function1)) composable to implement pull-to-refresh, which\nacts as a container for your scrollable content. The following key parameters\ncontrol the refresh behavior and appearance:\n\n- `isRefreshing`: A boolean value indicating whether the refresh action is in progress.\n- `onRefresh`: A lambda function that executes when the user initiates a refresh.\n- `indicator`: Customizes the indicator that the system draws on pull-to-refresh.\n\nBasic example\n\nThis snippet demonstrates basic usage of `PullToRefreshBox`:\n\n\n```kotlin\n@Composable\nfun PullToRefreshBasicSample(\n items: List\u003cString\u003e,\n isRefreshing: Boolean,\n onRefresh: () -\u003e Unit,\n modifier: Modifier = Modifier\n) {\n PullToRefreshBox(\n isRefreshing = isRefreshing,\n onRefresh = onRefresh,\n modifier = modifier\n ) {\n LazyColumn(Modifier.fillMaxSize()) {\n items(items) {\n ListItem({ Text(text = it) })\n }\n }\n }\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/PullToRefreshBox.kt#L92-L110\n```\n\n\u003cbr /\u003e\n\nKey points about the code\n\n- `PullToRefreshBox` wraps a [`LazyColumn`](/reference/kotlin/androidx/compose/foundation/lazy/package-summary#LazyColumn(androidx.compose.ui.Modifier,androidx.compose.foundation.lazy.LazyListState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.layout.Arrangement.Vertical,androidx.compose.ui.Alignment.Horizontal,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,kotlin.Function1)), which displays a list of strings.\n- `PullToRefreshBox` requires `isRefreshing` and `onRefresh` parameters.\n- The content within the `PullToRefreshBox` block represents the scrollable content.\n\nResult\n\nThis video demonstrates the basic pull-to-refresh implementation from\nthe preceding code:\n**Figure 1**. A basic pull-to-refresh implementation on a list of items.\n\nAdvanced example: Customize indicator color\n\n\n```kotlin\n@Composable\nfun PullToRefreshCustomStyleSample(\n items: List\u003cString\u003e,\n isRefreshing: Boolean,\n onRefresh: () -\u003e Unit,\n modifier: Modifier = Modifier\n) {\n val state = rememberPullToRefreshState()\n\n PullToRefreshBox(\n isRefreshing = isRefreshing,\n onRefresh = onRefresh,\n modifier = modifier,\n state = state,\n indicator = {\n Indicator(\n modifier = Modifier.align(Alignment.TopCenter),\n isRefreshing = isRefreshing,\n containerColor = MaterialTheme.colorScheme.primaryContainer,\n color = MaterialTheme.colorScheme.onPrimaryContainer,\n state = state\n )\n },\n ) {\n LazyColumn(Modifier.fillMaxSize()) {\n items(items) {\n ListItem({ Text(text = it) })\n }\n }\n }\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/PullToRefreshBox.kt#L115-L145\n```\n\n\u003cbr /\u003e\n\nKey points about the code\n\n- The indicator color is customized through the `containerColor` and `color` properties in the `indicator` parameter.\n- [`rememberPullToRefreshState()`](/reference/kotlin/androidx/compose/material3/pulltorefresh/PullToRefreshState) manages the state of the refresh action. You use this state in conjunction with the `indicator` parameter.\n\n| **Note:** In the basic example, `state` was not passed to `PullToRefreshBox` because it was using the default parameter value. However, in this example, you need to define the state, and pass that state to both the box and indicator to coordinate their behavior.\n\nResult\n\nThis video shows a pull-to-refresh implementation with a colored\nindicator:\n**Figure 2**. A pull-to-refresh implementation with a custom style.\n\nAdvanced example: Create a fully customized indicator\n\nYou can create complex custom indicators by leveraging existing composables and\nanimations.This snippet demonstrates how to create a fully custom indicator in\nyour pull-to-refresh implementation:\n\n\n```kotlin\n@Composable\nfun PullToRefreshCustomIndicatorSample(\n items: List\u003cString\u003e,\n isRefreshing: Boolean,\n onRefresh: () -\u003e Unit,\n modifier: Modifier = Modifier\n) {\n val state = rememberPullToRefreshState()\n\n PullToRefreshBox(\n isRefreshing = isRefreshing,\n onRefresh = onRefresh,\n modifier = modifier,\n state = state,\n indicator = {\n MyCustomIndicator(\n state = state,\n isRefreshing = isRefreshing,\n modifier = Modifier.align(Alignment.TopCenter)\n )\n }\n ) {\n LazyColumn(Modifier.fillMaxSize()) {\n items(items) {\n ListItem({ Text(text = it) })\n }\n }\n }\n}\n\n// ...\n@Composable\nfun MyCustomIndicator(\n state: PullToRefreshState,\n isRefreshing: Boolean,\n modifier: Modifier = Modifier,\n) {\n Box(\n modifier = modifier.pullToRefreshIndicator(\n state = state,\n isRefreshing = isRefreshing,\n containerColor = PullToRefreshDefaults.containerColor,\n threshold = PositionalThreshold\n ),\n contentAlignment = Alignment.Center\n ) {\n Crossfade(\n targetState = isRefreshing,\n animationSpec = tween(durationMillis = CROSSFADE_DURATION_MILLIS),\n modifier = Modifier.align(Alignment.Center)\n ) { refreshing -\u003e\n if (refreshing) {\n CircularProgressIndicator(Modifier.size(SPINNER_SIZE))\n } else {\n val distanceFraction = { state.distanceFraction.coerceIn(0f, 1f) }\n Icon(\n imageVector = Icons.Filled.CloudDownload,\n contentDescription = \"Refresh\",\n modifier = Modifier\n .size(18.dp)\n .graphicsLayer {\n val progress = distanceFraction()\n this.alpha = progress\n this.scaleX = progress\n this.scaleY = progress\n }\n )\n }\n }\n }\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/PullToRefreshBox.kt#L150-L222\n```\n\n\u003cbr /\u003e\n\nKey points about the code\n\n- The previous snippet used the `Indicator` provided by the library. This snippet creates a custom indicator composable called `MyCustomIndicator`. In this composable, the `pullToRefreshIndicator` modifier handles positioning and triggering a refresh.\n- As in the previous snippet, the example extracts the `PullToRefreshState` instance, so you can pass the same instance to both the `PullToRefreshBox` and the `pullToRefreshModifier`.\n- The example uses the container color and the position threshold from the `PullToRefreshDefaults` class. This way, you can reuse the default behavior and styling from the Material library, while customizing only the elements you're interested in.\n- `MyCustomIndicator` uses [`Crossfade`](/reference/kotlin/androidx/compose/animation/package-summary#Crossfade(kotlin.Any,androidx.compose.ui.Modifier,androidx.compose.animation.core.FiniteAnimationSpec,kotlin.String,kotlin.Function1)) to transition between a cloud icon and a `CircularProgressIndicator`. The cloud icon scales up as the user pulls, and transitions to a `CircularProgressIndicator` when the refresh action begins.\n - `targetState` uses `isRefreshing` to determine which state to display (the cloud icon or the circular progress indicator).\n - `animationSpec` defines a `tween` animation for the transition, with a specified duration of `CROSSFADE_DURATION_MILLIS`.\n - `state.distanceFraction` represents how far the user has pulled down, ranging from `0f` (no pull) to `1f` (fully pulled).\n - The `graphicsLayer` modifier modifies scale and transparency.\n\nResult\n\nThis video shows the custom indicator from the preceding code:\n**Figure 3**. A pull-to-refresh implementation with a custom indicator.\n\nAdditional resources\n\n- [`PullToRefreshState`](/reference/kotlin/androidx/compose/material3/pulltorefresh/PullToRefreshState)"]]