संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
Jetpack Compose में मौजूद PredictiveBackHandler कंपोज़ेबल की मदद से, पिछले पेज पर वापस जाने के लिए किए गए जेस्चर को इंटरसेप्ट किया जा सकता है. साथ ही, इसकी प्रोग्रेस को ऐक्सेस किया जा सकता है. उपयोगकर्ता के बैक जेस्चर पर रीयल-टाइम में प्रतिक्रिया दी जा सकती है. साथ ही, उपयोगकर्ता के स्वाइप करने की दूरी के आधार पर कस्टम ऐनिमेशन या व्यवहार बनाए जा सकते हैं.
PredictiveBackHandler का इस्तेमाल करने के लिए, पक्का करें कि आपके पास androidx.activity:activity:1.6.0 या इसके बाद वाला वर्शन हो.
PredictiveBackHandler एक Flow<BackEventCompat> उपलब्ध कराता है, जो पिछले पेज पर वापस जाने के लिए किए गए जेस्चर की प्रोग्रेस दिखाने वाले इवेंट जनरेट करता है. हर इवेंट में इस तरह की जानकारी होती है:
progress: यह 0 और 1 के बीच की फ़्लोट वैल्यू होती है. इससे बैक जेस्चर की प्रोग्रेस का पता चलता है (0 = जेस्चर शुरू हुआ, 1 = जेस्चर पूरा हुआ).
touchX और touchY: टच इवेंट के X और Y कोऑर्डिनेट.
इस स्निपेट में, PredictiveBackHandler के बुनियादी इस्तेमाल के बारे में बताया गया है:
PredictiveBackHandler(true){progress:Flow<BackEventCompat>->
// code for gesture back startedtry{progress.collect{backEvent->
// code for progressboxScale=1F-(1F*backEvent.progress)}// code for completionboxScale=0F}catch(e:CancellationException){// code for cancellationboxScale=1Fthrowe}}
इस उदाहरण में, PredictiveBackHandler का इस्तेमाल करके ऐप्लिकेशन में कस्टम ऐनिमेशन लागू करने का तरीका दिखाया गया है. इससे JetLagged में बैक जेस्चर के जवाब में, नेविगेशन ड्रॉअर के साथ आसानी से इंटरैक्ट किया जा सकता है:
पांचवीं इमेज. पीछे जाने पर झलक दिखाने वाले हाथ के जेस्चर की सुविधा के साथ नेविगेशन पैनल.
इस उदाहरण में, PredictiveBackHandler का इस्तेमाल इन कामों के लिए किया गया है:
पिछले पेज पर वापस जाने के लिए किए गए जेस्चर की प्रोग्रेस को ट्रैक करता है.
जेस्चर की प्रोग्रेस के आधार पर, ड्रॉअर के translationX को अपडेट करें.
जेस्चर पूरा होने या रद्द होने पर, जेस्चर की वेलोसिटी के आधार पर ड्रॉअर को आसानी से खोलने या बंद करने के लिए, velocityTracker का इस्तेमाल करें.
इस पेज पर मौजूद कॉन्टेंट और कोड सैंपल कॉन्टेंट के लाइसेंस में बताए गए लाइसेंस के हिसाब से हैं. 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,["# Access progress manually\n\nThe [`PredictiveBackHandler`](https://developer.android.com/reference/kotlin/androidx/activity/compose/PredictiveBackHandler) composable in Jetpack Compose lets you\nintercept the back gesture and access its progress. You can react to the user's\nback gesture in real-time, creating custom animations or behaviors based on how\nfar the user swipes.\n\nTo use the `PredictiveBackHandler`, ensure you are using\n`androidx.activity:activity:1.6.0` or higher.\n\n`PredictiveBackHandler` provides a `Flow\u003cBackEventCompat\u003e` that emits events\nrepresenting the progress of the back gesture. Each event contains information\nsuch as:\n\n- `progress`: A float value between 0 and 1 indicating the progress of the back gesture (0 = gesture started, 1 = gesture completed).\n- `touchX` and `touchY`: The X and Y coordinates of the touch event.\n\nThe following snippet shows basic usage of `PredictiveBackHandler`:\n\n\n```kotlin\nPredictiveBackHandler(true) { progress: Flow\u003cBackEventCompat\u003e -\u003e\n // code for gesture back started\n try {\n progress.collect { backEvent -\u003e\n // code for progress\n boxScale = 1F - (1F * backEvent.progress)\n }\n // code for completion\n boxScale = 0F\n } catch (e: CancellationException) {\n // code for cancellation\n boxScale = 1F\n throw e\n }\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/predictiveback/PredictiveBackSnippets.kt#L122-L136\n```\n\n\u003cbr /\u003e\n\nExample: Integrate with a navigation drawer\n-------------------------------------------\n\nThis example demonstrates how to implement a custom in-app animation using `PredictiveBackHandler` to create a smooth interaction with a navigation\ndrawer in response to back gestures in [JetLagged](https://github.com/android/compose-samples/blob/main/JetLagged/app/src/main/java/com/example/jetlagged/JetLaggedDrawer.kt):\n**Figure 5.** Navigation drawer with predictive back support.\n\nIn this example, `PredictiveBackHandler` is used to:\n\n- Track the progress of the back gesture.\n- Update the `translationX` of the drawer based on the gesture progress.\n- Use a `velocityTracker` to smoothly open or close the drawer based on the gesture velocity when the gesture is completed or canceled."]]