File tree Expand file tree Collapse file tree
Demo/app/src/main/java/com/pureswift/swiftandroid Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com.pureswift.swiftandroid
2+
3+ import android.content.Context
4+ import android.widget.FrameLayout
5+ import androidx.activity.compose.BackHandler
6+ import androidx.compose.runtime.getValue
7+ import androidx.compose.runtime.mutableStateOf
8+ import androidx.compose.runtime.setValue
9+ import androidx.compose.ui.platform.ComposeView
10+
11+ // Hosts a Jetpack Compose `BackHandler` to intercept the system back button and forward it to
12+ // Swift via `onBack()`. Renders no visible UI of its own; used only for its back-press interception.
13+ class BackHandlerView (context : Context , val callback : SwiftObject ) : FrameLayout(context) {
14+
15+ private var handlerEnabled by mutableStateOf(true )
16+
17+ init {
18+ val composeView = ComposeView (context)
19+ composeView.setContent {
20+ BackHandler (enabled = handlerEnabled) {
21+ onBack()
22+ }
23+ }
24+ addView(composeView)
25+ }
26+
27+ fun setBackHandlerEnabled (value : Boolean ) {
28+ handlerEnabled = value
29+ }
30+
31+ external fun onBack ()
32+ }
You can’t perform that action at this time.
0 commit comments