Skip to content

Commit

Permalink
Merge pull request #8 from jacobras/compose-kmp
Browse files Browse the repository at this point in the history
Migrate to Compose multiplatform
  • Loading branch information
jacobras authored Jan 11, 2024
2 parents b6b9ace + 8fa5bd0 commit 18d8a75
Show file tree
Hide file tree
Showing 32 changed files with 599 additions and 410 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
clean: ${{ github.ref == 'refs/heads/develop' }}
clean: ${{ github.ref == 'refs/heads/develop' }}

- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17

- name: Compile
run: ./gradlew assemble
24 changes: 24 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Publish
on:
workflow_dispatch:

jobs:
publish:
runs-on: macos-latest

steps:
- uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17

- name: Publish Library
env:
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }}
run: ./gradlew publishAllPublicationsToMavenCentral --no-configuration-cache
100 changes: 55 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Compose Action Menu

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

This multi-platform library provides an easy-to-use action menu for Compose, since Compose doesn't offer this by default.

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

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

![Animated preview image](preview.gif)

# Installation

```groovy
repositories {
google()
maven { url "https://jitpack.io" }
}
```kotlin
dependencies {
implementation "com.github.jacobras:ComposeActionMenu:1.2.0"
implementation("nl.jacobras:compose-action-menu:2.0.0")
}
```

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

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

See the Android docs for information about the specific Compose library versions in each BOM: https://developer.android.com/jetpack/compose/bom/bom-mapping.
## Compose version

Each version depends on specific Compose dependencies.

<table>
<tr>
<td>Compose 1.1.0-rc01</td><td><img alt="JitPack" src="https://img.shields.io/badge/jitpack-v1.0.0-blue"></td>
<td><img alt="JitPack" src="https://img.shields.io/badge/jitpack-v1.0.0-blue"></td><td>Compose 1.1.0-rc01</td>
</tr>
<tr>
<td><img alt="JitPack" src="https://img.shields.io/badge/jitpack-v1.1.0-blue"></td><td>Compose 1.3.3</td>
</tr>
<tr>
<td>Compose 2023.01.00</td><td><img alt="JitPack" src="https://img.shields.io/badge/jitpack-v1.1.0-blue"></td>
<td><img alt="JitPack" src="https://img.shields.io/badge/jitpack-v1.2.0-blue"></td><td>Compose 1.4.3</td>
</tr>
<tr>
<td>Compose 2023.05.01</td><td><img alt="JitPack" src="https://img.shields.io/badge/jitpack-v1.2.0-blue"></td>
<td><img alt="JitPack" src="https://img.shields.io/badge/mavencentral-v2.0.0-blue"></td><td>Compose Multiplatform 1.5.1</td>
</tr>
</table>

Expand All @@ -50,9 +56,10 @@ See the Android docs for information about the specific Compose library versions
```kotlin
val toolbarActions = listOf(
RegularActionItem(
key = "settings",
titleResId = R.string.settings,
onClick = { /* TODO: Open settings screen */ }
key = "search",
title = stringResource(R.string.search),
iconVector = Icons.Filled.Search,
onClick = { /* TODO: Open search screen */ }
)
)

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

val group = GroupActionItem(
key = "myGroup",
title = R.string.group_title,
title = stringResource(R.string.group_title),
childOptions = listOf(subOption1, subOption2, subOption3)
)
```
Expand Down Expand Up @@ -112,36 +119,39 @@ composeTestRule.onNodeWithTag("ActionMenu#myKey").performClick()

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

# Production example
# Migrating from v1 to v2

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

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

![](preview_notes.png)
```kotlin
RegularActionItem(
titleResId = R.string.search,
iconDrawable = R.drawable.search
)
```

# License
2.x:

```kotlin
RegularActionItem(
title = stringResource(R.string.search),
icon = painterResource(R.drawable.search)
)
```
MIT License
Copyright (c) 2021 Jacob Ras
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

# Sample apps

The repository contains two sample apps.

* Run Android: `gradlew sample-app:installDebug`
* Run Desktop: `gradlew sample-desktop:run`

# Production example

My note taking app uses ComposeActionMenu:

<https://play.google.com/store/apps/details?id=nl.jacobras.notes>

![](preview_notes.png)
5 changes: 4 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
plugins {
kotlin("jvm") version libs.versions.kotlin apply false
kotlin("multiplatform") version libs.versions.kotlin apply false
kotlin("android") version libs.versions.kotlin apply false
id("com.android.application") version libs.versions.agp apply false
id("com.android.library") version libs.versions.agp apply false
id("org.jetbrains.kotlin.android") version libs.versions.kotlin apply false
id("org.jetbrains.compose") version libs.versions.compose.multiplatform apply false
}
102 changes: 72 additions & 30 deletions compose-action-menu/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,52 +1,94 @@
@file:Suppress("UnstableApiUsage")

import org.gradle.kotlin.dsl.implementation
import org.gradle.kotlin.dsl.libs
import com.vanniktech.maven.publish.SonatypeHost

plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("com.vanniktech.maven.publish") version "0.27.0"
}

group = "nl.jacobras"
version = "2.0.0"

mavenPublishing {
publishToMavenCentral(SonatypeHost.S01, true)
signAllPublications()

@Suppress("UnstableApiUsage")
pom {
name.set("Compose Action Menu")
description.set("An easy to use action/overflow menu for Jetpack Compose")
url.set("https://github.com/jacobras/composeactionmenu")

licenses {
license {
name.set("MIT")
url.set("https://opensource.org/licenses/MIT")
}
}
developers {
developer {
id.set("jacobras")
name.set("Jacob Ras")
email.set("[email protected]")
}
}
scm {
url.set("https://github.com/jacobras/ComposeActionMenu")
}
}
}

android {
compileSdk = 33
compileSdk = 34
namespace = "nl.jacobras.composeactionmenu"

buildFeatures {
compose = true
}
defaultConfig {
minSdk = 21
targetSdk = 33

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
buildTypes {
named("release") {
isMinifyEnabled = false
setProguardFiles(listOf(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"))
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
}
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
// BoMs
implementation(platform(libs.compose.bom))
kotlin {
applyDefaultHierarchyTemplate()

androidTarget {
publishLibraryVariants("release")
}
iosX64()
iosArm64()
iosSimulatorArm64()
jvm("desktop")

sourceSets {
val commonMain by getting {
dependencies {
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.ui)
}
}
val androidMain by getting {
dependencies {
implementation(compose.uiTooling)
}
}
}

jvmToolchain(17)
}

implementation(libs.compose.activity)
implementation(libs.compose.compiler)
implementation(libs.compose.foundation)
implementation(libs.compose.material)
implementation(libs.compose.ui)
implementation(libs.compose.ui.tooling)
// From https://github.com/gradle/gradle/issues/26091#issuecomment-1722947958
tasks.withType<AbstractPublishToMaven>().configureEach {
val signingTasks = tasks.withType<Sign>()
mustRunAfter(signingTasks)
}
Empty file.
21 changes: 0 additions & 21 deletions compose-action-menu/proguard-rules.pro

This file was deleted.

Loading

0 comments on commit 18d8a75

Please sign in to comment.