Skip to content

Commit 18d8a75

Browse files
authored
Merge pull request #8 from jacobras/compose-kmp
Migrate to Compose multiplatform
2 parents b6b9ace + 8fa5bd0 commit 18d8a75

32 files changed

Lines changed: 599 additions & 410 deletions

File tree

.github/workflows/build.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v3
1919
with:
20-
clean: ${{ github.ref == 'refs/heads/develop' }}
20+
clean: ${{ github.ref == 'refs/heads/develop' }}
21+
22+
- name: Set up JDK 17
23+
uses: actions/setup-java@v1
24+
with:
25+
java-version: 17
2126

2227
- name: Compile
2328
run: ./gradlew assemble

.github/workflows/publish.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish
2+
on:
3+
workflow_dispatch:
4+
5+
jobs:
6+
publish:
7+
runs-on: macos-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
12+
- name: Set up JDK 17
13+
uses: actions/setup-java@v1
14+
with:
15+
java-version: 17
16+
17+
- name: Publish Library
18+
env:
19+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
20+
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }}
21+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
22+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }}
23+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }}
24+
run: ./gradlew publishAllPublicationsToMavenCentral --no-configuration-cache

README.md

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Compose Action Menu
22

3-
This library provides an easy-to-use action menu for Compose, since Compose doesn't offer this by default.
3+
![Android](https://img.shields.io/badge/-android-6EDB8D.svg?style=flat)
4+
![iOS](http://img.shields.io/badge/-ios-CDCDCD.svg?style=flat)
5+
![JVM](https://img.shields.io/badge/-jvm-DB413D.svg?style=flat)
6+
7+
This multi-platform library provides an easy-to-use action menu for Compose, since Compose doesn't offer this by default.
48

59
[![Android Arsenal]( https://img.shields.io/badge/Android%20Arsenal-ComposeActionMenu-green.svg?style=flat )]( https://android-arsenal.com/details/1/8261 )
610

@@ -11,37 +15,39 @@ This library provides an easy-to-use action menu for Compose, since Compose does
1115
- Icons (optional);
1216
- Selectable/checkable items;
1317
- Nested sub menus;
14-
- Automatic overflow for items that don't fit the specified maximum.
18+
- Automatic overflow for items that don't fit the specified maximum;
19+
- Kotlin Multiplatform (KMP) since version 2.0.0, supporting Android, iOS and JVM (desktop).
1520

1621
![Animated preview image](preview.gif)
1722

1823
# Installation
1924

20-
```groovy
21-
repositories {
22-
google()
23-
maven { url "https://jitpack.io" }
24-
}
25+
```kotlin
2526
dependencies {
26-
implementation "com.github.jacobras:ComposeActionMenu:1.2.0"
27+
implementation("nl.jacobras:compose-action-menu:2.0.0")
2728
}
2829
```
2930

30-
## Compose version
31+
Note: version 2 and newer are available from Maven Central, whereas previous versions were distributed through JitPack.
3132

32-
This library uses the Compose BOM (Bill of Materials). Each version depends on specific Compose dependencies.
33+
See also: [Migrating to V2](#migrating-from-v1-to-v2).
3334

34-
See the Android docs for information about the specific Compose library versions in each BOM: https://developer.android.com/jetpack/compose/bom/bom-mapping.
35+
## Compose version
36+
37+
Each version depends on specific Compose dependencies.
3538

3639
<table>
3740
<tr>
38-
<td>Compose 1.1.0-rc01</td><td><img alt="JitPack" src="https://img.shields.io/badge/jitpack-v1.0.0-blue"></td>
41+
<td><img alt="JitPack" src="https://img.shields.io/badge/jitpack-v1.0.0-blue"></td><td>Compose 1.1.0-rc01</td>
42+
</tr>
43+
<tr>
44+
<td><img alt="JitPack" src="https://img.shields.io/badge/jitpack-v1.1.0-blue"></td><td>Compose 1.3.3</td>
3945
</tr>
4046
<tr>
41-
<td>Compose 2023.01.00</td><td><img alt="JitPack" src="https://img.shields.io/badge/jitpack-v1.1.0-blue"></td>
47+
<td><img alt="JitPack" src="https://img.shields.io/badge/jitpack-v1.2.0-blue"></td><td>Compose 1.4.3</td>
4248
</tr>
4349
<tr>
44-
<td>Compose 2023.05.01</td><td><img alt="JitPack" src="https://img.shields.io/badge/jitpack-v1.2.0-blue"></td>
50+
<td><img alt="JitPack" src="https://img.shields.io/badge/mavencentral-v2.0.0-blue"></td><td>Compose Multiplatform 1.5.1</td>
4551
</tr>
4652
</table>
4753

@@ -50,9 +56,10 @@ See the Android docs for information about the specific Compose library versions
5056
```kotlin
5157
val toolbarActions = listOf(
5258
RegularActionItem(
53-
key = "settings",
54-
titleResId = R.string.settings,
55-
onClick = { /* TODO: Open settings screen */ }
59+
key = "search",
60+
title = stringResource(R.string.search),
61+
iconVector = Icons.Filled.Search,
62+
onClick = { /* TODO: Open search screen */ }
5663
)
5764
)
5865

@@ -81,7 +88,7 @@ val subOption3 = RegularActionItem(key = "subOption3", /* ... */)
8188

8289
val group = GroupActionItem(
8390
key = "myGroup",
84-
title = R.string.group_title,
91+
title = stringResource(R.string.group_title),
8592
childOptions = listOf(subOption1, subOption2, subOption3)
8693
)
8794
```
@@ -112,36 +119,39 @@ composeTestRule.onNodeWithTag("ActionMenu#myKey").performClick()
112119

113120
There's a reserved key for the overflow icon: `"ActionMenu#overflow"`.
114121

115-
# Production example
122+
# Migrating from v1 to v2
116123

117-
My note taking app uses ComposeActionMenu:
124+
Compose Action Menu version 2 is built using KMP. Android-specific resource support is replaced with broader string + Painter support.
118125

119-
<https://play.google.com/store/apps/details?id=nl.jacobras.notes>
126+
1.x:
120127

121-
![](preview_notes.png)
128+
```kotlin
129+
RegularActionItem(
130+
titleResId = R.string.search,
131+
iconDrawable = R.drawable.search
132+
)
133+
```
122134

123-
# License
135+
2.x:
124136

137+
```kotlin
138+
RegularActionItem(
139+
title = stringResource(R.string.search),
140+
icon = painterResource(R.drawable.search)
141+
)
125142
```
126-
MIT License
127-
128-
Copyright (c) 2021 Jacob Ras
129-
130-
Permission is hereby granted, free of charge, to any person obtaining a copy
131-
of this software and associated documentation files (the "Software"), to deal
132-
in the Software without restriction, including without limitation the rights
133-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
134-
copies of the Software, and to permit persons to whom the Software is
135-
furnished to do so, subject to the following conditions:
136-
137-
The above copyright notice and this permission notice shall be included in all
138-
copies or substantial portions of the Software.
139-
140-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
141-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
142-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
143-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
144-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
145-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
146-
SOFTWARE.
147-
```
143+
144+
# Sample apps
145+
146+
The repository contains two sample apps.
147+
148+
* Run Android: `gradlew sample-app:installDebug`
149+
* Run Desktop: `gradlew sample-desktop:run`
150+
151+
# Production example
152+
153+
My note taking app uses ComposeActionMenu:
154+
155+
<https://play.google.com/store/apps/details?id=nl.jacobras.notes>
156+
157+
![](preview_notes.png)

build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
plugins {
2+
kotlin("jvm") version libs.versions.kotlin apply false
3+
kotlin("multiplatform") version libs.versions.kotlin apply false
4+
kotlin("android") version libs.versions.kotlin apply false
25
id("com.android.application") version libs.versions.agp apply false
36
id("com.android.library") version libs.versions.agp apply false
4-
id("org.jetbrains.kotlin.android") version libs.versions.kotlin apply false
7+
id("org.jetbrains.compose") version libs.versions.compose.multiplatform apply false
58
}
Lines changed: 72 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,94 @@
1-
@file:Suppress("UnstableApiUsage")
2-
3-
import org.gradle.kotlin.dsl.implementation
4-
import org.gradle.kotlin.dsl.libs
1+
import com.vanniktech.maven.publish.SonatypeHost
52

63
plugins {
4+
kotlin("multiplatform")
5+
id("org.jetbrains.compose")
76
id("com.android.library")
8-
id("org.jetbrains.kotlin.android")
7+
id("com.vanniktech.maven.publish") version "0.27.0"
8+
}
9+
10+
group = "nl.jacobras"
11+
version = "2.0.0"
12+
13+
mavenPublishing {
14+
publishToMavenCentral(SonatypeHost.S01, true)
15+
signAllPublications()
16+
17+
@Suppress("UnstableApiUsage")
18+
pom {
19+
name.set("Compose Action Menu")
20+
description.set("An easy to use action/overflow menu for Jetpack Compose")
21+
url.set("https://github.com/jacobras/composeactionmenu")
22+
23+
licenses {
24+
license {
25+
name.set("MIT")
26+
url.set("https://opensource.org/licenses/MIT")
27+
}
28+
}
29+
developers {
30+
developer {
31+
id.set("jacobras")
32+
name.set("Jacob Ras")
33+
email.set("info@jacobras.nl")
34+
}
35+
}
36+
scm {
37+
url.set("https://github.com/jacobras/ComposeActionMenu")
38+
}
39+
}
940
}
1041

1142
android {
12-
compileSdk = 33
43+
compileSdk = 34
44+
namespace = "nl.jacobras.composeactionmenu"
1345

1446
buildFeatures {
1547
compose = true
1648
}
1749
defaultConfig {
1850
minSdk = 21
19-
targetSdk = 33
20-
21-
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
22-
consumerProguardFiles("consumer-rules.pro")
23-
}
24-
buildTypes {
25-
named("release") {
26-
isMinifyEnabled = false
27-
setProguardFiles(listOf(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"))
28-
}
2951
}
3052
compileOptions {
31-
sourceCompatibility = JavaVersion.VERSION_1_8
32-
targetCompatibility = JavaVersion.VERSION_1_8
53+
sourceCompatibility = JavaVersion.VERSION_17
54+
targetCompatibility = JavaVersion.VERSION_17
3355
}
3456
composeOptions {
3557
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
3658
}
37-
kotlinOptions {
38-
jvmTarget = "1.8"
39-
}
4059
}
4160

42-
dependencies {
43-
// BoMs
44-
implementation(platform(libs.compose.bom))
61+
kotlin {
62+
applyDefaultHierarchyTemplate()
63+
64+
androidTarget {
65+
publishLibraryVariants("release")
66+
}
67+
iosX64()
68+
iosArm64()
69+
iosSimulatorArm64()
70+
jvm("desktop")
71+
72+
sourceSets {
73+
val commonMain by getting {
74+
dependencies {
75+
implementation(compose.foundation)
76+
implementation(compose.material)
77+
implementation(compose.ui)
78+
}
79+
}
80+
val androidMain by getting {
81+
dependencies {
82+
implementation(compose.uiTooling)
83+
}
84+
}
85+
}
86+
87+
jvmToolchain(17)
88+
}
4589

46-
implementation(libs.compose.activity)
47-
implementation(libs.compose.compiler)
48-
implementation(libs.compose.foundation)
49-
implementation(libs.compose.material)
50-
implementation(libs.compose.ui)
51-
implementation(libs.compose.ui.tooling)
90+
// From https://github.com/gradle/gradle/issues/26091#issuecomment-1722947958
91+
tasks.withType<AbstractPublishToMaven>().configureEach {
92+
val signingTasks = tasks.withType<Sign>()
93+
mustRunAfter(signingTasks)
5294
}

compose-action-menu/consumer-rules.pro

Whitespace-only changes.

compose-action-menu/proguard-rules.pro

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)