Skip to content

Commit 996547c

Browse files
authored
V2 (#16)
* Upgradel Gradle + AGP * Remove unneccessary modules * clear readme * Build optimizations * Upgrade Kotlin + Compose + SDK * Big breaking change * Rename package name * useQuery refactor * Update query example * Update Mutation example * Refactor useMutation * Optimize imports * Fix Android app UI * Update CI
1 parent 0dd9b6b commit 996547c

File tree

95 files changed

+785
-1896
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+785
-1896
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v2
15-
- name: set up JDK 11
16-
uses: actions/setup-java@v2
14+
- uses: actions/checkout@v4
15+
- name: set up JDK 17
16+
uses: actions/setup-java@v4
1717
with:
18-
java-version: '11'
19-
distribution: 'adopt'
18+
java-version: '17'
19+
distribution: 'temurin'
2020
cache: gradle
2121
- name: Grant execute permission for gradlew
2222
run: chmod +x gradlew

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,4 @@ fabric.properties
209209
!/gradle/wrapper/gradle-wrapper.jar
210210

211211
# End of https://www.toptal.com/developers/gitignore/api/android,androidstudio,gradle,kotlin
212+
.kotlin/

.idea/codeStyles/Project.xml

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 2 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 85 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,113 @@
11
# useCompose
22

3-
Headless @Composable hooks that drive UI logic. Inspired by React.
3+
Headless @Composable hooks that drive UI logic. Inspired by React.
4+
5+
**🚀 Now supports Kotlin/Compose Multiplatform!** Run on Android, Desktop, and more!
6+
7+
> **📢 Looking for other hooks?** In v2.0, we focused on KMP support and kept only the `query` module. For other hooks like `useState`, `useEffect`, `useContext`, `useReducer`, `useToggle`, and `useConnectionStatus`, check out [**ComposeHooks**](https://github.com/junerver/ComposeHooks) - a comprehensive collection of Compose hooks!
48
59
[![](https://jitpack.io/v/pavi2410/useCompose.svg)](https://jitpack.io/#pavi2410/useCompose) [![CI](https://github.com/pavi2410/useCompose/actions/workflows/ci.yml/badge.svg)](https://github.com/pavi2410/useCompose/actions/workflows/ci.yml)
610

7-
| `react` | `query` |
8-
| --- | --- |
9-
| ![react example](https://github.com/pavi2410/useCompose/assets/28837746/0a271bda-fc47-47b3-8cb6-daf6748a2633) | ![query example](https://github.com/pavi2410/useCompose/assets/28837746/2317d447-8f8b-4626-b92e-2e024e242714) |
11+
|`query` |
12+
| --- |
13+
| ![query example](https://github.com/pavi2410/useCompose/assets/28837746/2317d447-8f8b-4626-b92e-2e024e242714) |
1014

15+
## Quick Start
1116

12-
## Modules
17+
### Run the Demo
18+
19+
**Desktop App:**
20+
```bash
21+
./gradlew :app:run
22+
```
23+
24+
**Android App:**
25+
```bash
26+
./gradlew :app:assembleDebug
27+
./gradlew :app:installDebug
28+
```
29+
30+
**Run Tests:**
31+
```bash
32+
# All tests
33+
./gradlew test
1334

14-
### ⚛ react
15-
- useState
16-
- useEffect
17-
- useContext
18-
- useReducer
35+
# Library tests only
36+
./gradlew :query:test
1937

20-
### 🪝 hooks
21-
- useToggle
38+
# App tests only
39+
./gradlew :app:test
40+
```
2241

23-
### 🕸 network
24-
- useConnnectionStatus
42+
## Modules
2543

2644
### ❓ query
27-
- useQuery
45+
- `useQuery` - Async data fetching with loading/error/success states
46+
- `useMutation` - Async mutations with callback handling
47+
48+
**Platforms supported:** Android, Desktop (JVM), ready for iOS/Web
2849

2950
## Installation
3051

31-
Step 1. Add the JitPack repository to your build file
52+
### For Kotlin/Compose Multiplatform Projects
3253

33-
Add it in your root build.gradle at the end of repositories:
34-
```gradle
35-
repositories {
36-
...
37-
maven {
38-
url = uri("https://jitpack.io")
39-
}
54+
Add to your `libs.versions.toml`:
55+
```toml
56+
[versions]
57+
useCompose = "2.0.0" # Use latest version
58+
59+
[repositories]
60+
maven { url = "https://jitpack.io" }
61+
62+
[libraries]
63+
useCompose-query = { module = "com.github.pavi2410.useCompose:query", version.ref = "useCompose" }
64+
```
65+
66+
Add to your module's `build.gradle.kts`:
67+
```kotlin
68+
kotlin {
69+
sourceSets {
70+
commonMain.dependencies {
71+
implementation(libs.useCompose.query)
72+
}
73+
}
4074
}
4175
```
4276

43-
Step 2. Add the dependency
44-
```gradle
77+
### For Android-only Projects
78+
79+
Add to your `build.gradle.kts`:
80+
```kotlin
81+
repositories {
82+
maven { url = uri("https://jitpack.io") }
83+
}
84+
4585
dependencies {
46-
implementation("com.github.pavi2410.useCompose:<module_name>:<version>")
86+
implementation("com.github.pavi2410.useCompose:query:2.0.0")
87+
}
88+
```
89+
90+
## Example Usage
91+
92+
```kotlin
93+
@Composable
94+
fun MyScreen() {
95+
val queryState by useQuery {
96+
// Async operation
97+
fetchDataFromApi()
98+
}
99+
100+
when (val state = queryState) {
101+
is QueryState.Loading -> Text("Loading...")
102+
is QueryState.Error -> Text("Error: ${state.message}")
103+
is QueryState.Content -> Text("Data: ${state.data}")
104+
}
47105
}
48106
```
49107

50108
## Help Wanted
51109

52-
I want your help in making this library extensive such that this cover many of the commonly used hooks. Also, I want your help in building a KMP friendly library.
110+
This library now supports Kotlin Multiplatform! Help us extend it with more hooks and platform support (iOS, Web, etc.).
53111

54112
## License
55113

app/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)