You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you want to show the floating window while on the Activity, you can use the following code:
57
52
58
53
```kotlin
59
54
val floatingWindow =ComposeFloatingWindow(applicationContext)
@@ -69,65 +64,27 @@ floatingWindow.setContent {
69
64
floatingWindow.show()
70
65
```
71
66
72
-
> See [Sample App](https://github.com/only52607/compose-floating-window/tree/master/app).
73
-
74
-
## Advanced Usage
75
-
76
-
### Make Floating Window Draggable
77
-
78
-
Use the `Modifier.dragFloatingWindow()` modifier on the component you want to make draggable. Example:
79
-
80
-
```kotlin
81
-
FloatingActionButton(
82
-
modifier =Modifier.dragFloatingWindow()
83
-
) {
84
-
Icon(Icons.Filled.Call, "Call")
85
-
}
86
-
```
87
-
88
-
### Get the current instance of `ComposeFloatingWindow`
67
+
### Service
89
68
90
-
Using LocalComposeFloatingWindow to retrieve, here's an example:
69
+
When you want to show the floating window while on the Service, you can use the following code:
91
70
92
71
```kotlin
93
-
val floatingWindow =LocalComposeFloatingWindow.current
94
-
```
95
-
96
-
### Show Dialog
97
-
98
-
When the Context of the floating window is set to Application, using AlertDialog and Dialog in the Compose interface of the floating window may result in a 'token is null' exception. In such cases, you can use the SystemAlertDialog or SystemDialog components, which can be used in the same way as the built-in AlertDialog and Dialog components.
99
-
100
-
Example:
101
-
```kotlin
102
-
SystemAlertDialog(
103
-
onDismissRequest = { showDialog =false },
104
-
confirmButton = {
105
-
TextButton(onClick = { showDialog =false }) {
106
-
Text(text ="OK")
107
-
}
108
-
},
109
-
text = {
110
-
Text(text ="This is a system dialog")
72
+
val floatingWindow =ComposeServiceFloatingWindow(applicationContext)
73
+
floatingWindow.setContent {
74
+
FloatingActionButton(
75
+
modifier =Modifier.dragFloatingWindow(),
76
+
onClick = {
77
+
Log.i("")
78
+
}) {
79
+
Icon(Icons.Filled.Call, "Call")
111
80
}
112
-
)
113
-
```
114
-
115
-
### ViewModel
116
-
117
-
You can access the ViewModel from any Composable by calling the viewModel() function.
118
-
119
-
```kotlin
120
-
classMyViewModel : ViewModel() { /*...*/ }
121
-
122
-
@Composable
123
-
funMyScreen(
124
-
viewModel:MyViewModel = viewModel()
125
-
) {
126
-
// use viewModel here
127
81
}
82
+
floatingWindow.show()
128
83
```
129
84
130
-
> See https://developer.android.com/jetpack/compose/libraries#viewmodel
0 commit comments