সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
জেটপ্যাক কম্পোজে 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}}
JetLagged- এ ব্যাক জেসচারের প্রতিক্রিয়া হিসাবে একটি নেভিগেশন ড্রয়ারের সাথে একটি মসৃণ মিথস্ক্রিয়া তৈরি করতে PredictiveBackHandler ব্যবহার করে একটি কাস্টম ইন-অ্যাপ অ্যানিমেশন কীভাবে প্রয়োগ করা যায় এই উদাহরণটি দেখায়:
চিত্র 5. ভবিষ্যদ্বাণীমূলক ব্যাক সমর্থন সহ নেভিগেশন ড্রয়ার।
এই উদাহরণে, PredictiveBackHandler ব্যবহার করা হয়:
পিছনের অঙ্গভঙ্গির অগ্রগতি ট্র্যাক করুন।
অঙ্গভঙ্গি অগ্রগতির উপর ভিত্তি করে ড্রয়ারের translationX আপডেট করুন।
অঙ্গভঙ্গি সম্পূর্ণ বা বাতিল করার সময় অঙ্গভঙ্গি বেগের উপর ভিত্তি করে ড্রয়ারটি মসৃণভাবে খুলতে বা বন্ধ করতে একটি velocityTracker ব্যবহার করুন।
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। 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."]]