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}}
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 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."]]