Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ trim_trailing_whitespace = true
indent_size = 2
indent_style = space

[*.md]
indent_size = 4
indent_style = space

# noinspection EditorConfigKeyCorrectness
[*.{kt,kts}]
max_line_length = 120
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ on:
- '.gitignore'
- 'renovate.json'
- 'FUNDING.yml'
- 'docs/**'
- 'mkdocs.yaml'
workflow_dispatch:

env:
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Publish Docs
on:
push:
branches:
- master
- docs/**
paths:
- 'docs/**'
- mkdocs.yml
- '.github/workflows/docs.yml'
# Manual triggers
workflow_dispatch:

permissions:
contents: write

concurrency:
group: ${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
publish-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0

- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV

- uses: actions/cache@v4
with:
key: mkdocs-material-${{ env.cache_id }}
path: ~/.cache
restore-keys: |
mkdocs-material-
- run: pip install -r .github/workflows/requirements.txt

- run: mkdocs gh-deploy --force

2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:
- '.github/**'
- '!.github/workflows/**'
- 'renovate.json'
- 'docs/**'
- 'mkdocs.yaml'

env:
JAVA_VERSION: 17
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mkdocs-material
mkdocs-git-revision-date-localized-plugin
mkdocs-awesome-nav
pymdown-extensions

# Imaging dependencies for mkdocs-material social plugin
# https://squidfunk.github.io/mkdocs-material/plugins/requirements/image-processing/
cairosvg==2.8.2
pillow==11.3.0
119 changes: 3 additions & 116 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# compose-floating-window

[![Release](https://jitpack.io/v/only52607/compose-floating-window.svg)](https://jitpack.io/#User/Repo)
[![Release](https://jitpack.io/v/ArthurKun21/compose-overlay-window.svg)](https://jitpack.io/#ArthurKun21/compose-overlay-window)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

Global Floating Window Framework based on Jetpack Compose

[简体中文](README_CN.md)

## Preview

![Preview](/preview/example.gif)
![Preview](docs/assets/example.gif)

## Features

Expand All @@ -18,117 +16,6 @@ Global Floating Window Framework based on Jetpack Compose
- Support for draggable floating windows.
- Dialog components based on the Application Context.

## Basic Usage

### Import Dependencies

- If the Gradle version is less than 7.0, add the Jitpack repository in the `build.gradle` of your app.

```groovy
repositories {
maven { url 'https://jitpack.io' }
}
```

- If the Gradle version is greater than or equal to 7.0, add it in the settings.gradle file.
```groovy
dependencyResolutionManagement {
repositories {
maven { url 'https://jitpack.io' }
}
}
```

- Add `compose-floating-window` Dependency
```groovy
dependencies {
implementation "com.github.only52607:compose-floating-window:1.0"
}
```

### Grant Floating Window Permission

Add to `AndroidManifest.xml`
```xml
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
```

### Create Floating Window and Show

```kotlin
val floatingWindow = ComposeFloatingWindow(applicationContext)
floatingWindow.setContent {
FloatingActionButton(
modifier = Modifier.dragFloatingWindow(),
onClick = {
Log.i("")
}) {
Icon(Icons.Filled.Call, "Call")
}
}
floatingWindow.show()
```

> See [Sample App](https://github.com/only52607/compose-floating-window/tree/master/app).

## Advanced Usage

### Make Floating Window Draggable

Use the `Modifier.dragFloatingWindow()` modifier on the component you want to make draggable. Example:

```kotlin
FloatingActionButton(
modifier = Modifier.dragFloatingWindow()
) {
Icon(Icons.Filled.Call, "Call")
}
```

### Get the current instance of `ComposeFloatingWindow`

Using LocalComposeFloatingWindow to retrieve, here's an example:

```kotlin
val floatingWindow = LocalComposeFloatingWindow.current
```

### Show Dialog

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.

Example:
```kotlin
SystemAlertDialog(
onDismissRequest = { showDialog = false },
confirmButton = {
TextButton(onClick = { showDialog = false }) {
Text(text = "OK")
}
},
text = {
Text(text = "This is a system dialog")
}
)
```

### ViewModel

You can access the ViewModel from any Composable by calling the viewModel() function.

```kotlin
class MyViewModel : ViewModel() { /*...*/ }

@Composable
fun MyScreen(
viewModel: MyViewModel = viewModel()
) {
// use viewModel here
}
```

> See https://developer.android.com/jetpack/compose/libraries#viewmodel

## License

Apache 2.0 License
Apache 2.0 License
132 changes: 0 additions & 132 deletions README_CN.md

This file was deleted.

2 changes: 2 additions & 0 deletions docs/.nav.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nav:
- Overview: index.md
File renamed without changes
Loading
Loading