Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Jetpack Compose'daki PredictiveBackHandler composable'ı, geri gitme hareketini durdurmanıza ve ilerleme durumuna erişmenize olanak tanır. Kullanıcının geri hareketine gerçek zamanlı olarak tepki verebilir, kullanıcının ne kadar kaydırdığına bağlı olarak özel animasyonlar veya davranışlar oluşturabilirsiniz.
PredictiveBackHandler özelliğini kullanmak için androidx.activity:activity:1.6.0 veya sonraki bir sürümü kullandığınızdan emin olun.
PredictiveBackHandler, geri gitme hareketinin ilerleme durumunu temsil eden etkinlikler yayan bir Flow<BackEventCompat> sağlar. Her etkinlikte aşağıdaki gibi bilgiler bulunur:
progress: Geri hareketinin ilerleme durumunu gösteren 0 ile 1 arasında değişen kayan nokta değeri (0 = hareket başladı, 1 = hareket tamamlandı).
touchX ve touchY: Dokunma etkinliğinin X ve Y koordinatları.
Aşağıdaki snippet'te PredictiveBackHandler temel kullanımı gösterilmektedir:
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}}
Bu örnekte, JetLagged'de geri hareketlerine yanıt olarak gezinme çekmecesiyle sorunsuz bir etkileşim oluşturmak için PredictiveBackHandler kullanılarak özel bir uygulama içi animasyonun nasıl uygulanacağı gösterilmektedir:
5.Şekil Tahmin edilen geri gitme desteğiyle gezinme çekmecesi.
Bu örnekte PredictiveBackHandler şu amaçlarla kullanılır:
Geri hareketinin ilerleme durumunu izleyin.
Çekmecenin translationX özelliğini, hareketin ilerleme durumuna göre güncelleyin.
Çekmeceyi, hareket tamamlandığında veya iptal edildiğinde hareket hızına göre sorunsuz bir şekilde açmak ya da kapatmak için velocityTracker kullanın.
Bu sayfadaki içerik ve kod örnekleri, İçerik Lisansı sayfasında açıklanan lisanslara tabidir. Java ve OpenJDK, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-08-27 UTC.
[[["Anlaması kolay","easyToUnderstand","thumb-up"],["Sorunumu çözdü","solvedMyProblem","thumb-up"],["Diğer","otherUp","thumb-up"]],[["İhtiyacım olan bilgiler yok","missingTheInformationINeed","thumb-down"],["Çok karmaşık / çok fazla adım var","tooComplicatedTooManySteps","thumb-down"],["Güncel değil","outOfDate","thumb-down"],["Çeviri sorunu","translationIssue","thumb-down"],["Örnek veya kod sorunu","samplesCodeIssue","thumb-down"],["Diğer","otherDown","thumb-down"]],["Son güncelleme tarihi: 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."]]