Skip to content

Commit

Permalink
Add package com.composables.ui
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstyl committed May 3, 2024
1 parent 425c8e9 commit a61eefd
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 23 deletions.
4 changes: 4 additions & 0 deletions demo/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.composables.ui.Menu
import com.composables.ui.MenuButton
import com.composables.ui.MenuContent
import com.composables.ui.MenuItem

@Composable
fun App() {
Expand Down
20 changes: 4 additions & 16 deletions demo/src/wasmJsMain/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,11 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Compose Menu</title>
<script>
const canRunDemo = WebAssembly.validate(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 95, 1, 120, 0]));
if (canRunDemo) {
const skikoScript = document.createElement('script');
skikoScript.src = "skiko.js";
document.head.appendChild(skikoScript);

const composeAppScript = document.createElement('script');
composeAppScript.src = "composeApp.js";
document.head.appendChild(composeAppScript);
} else {
console.error("Cannot run demo");
}
</script>
<title>KotlinProject</title>
<script type="application/javascript" src="skiko.js"></script>
<script type="application/javascript" src="composeApp.js"></script>
</head>
<body>
<canvas id="ComposeTarget"></canvas>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#Gradle
org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M"
org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=2048m -XX:+HeapDumpOnOutOfMemoryError

kotlin.code.style=official

Expand Down
2 changes: 2 additions & 0 deletions menu/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ val publishVersion = "1.2.0"
val githubUrl = "github.com/composablehorizons/compose-menu"

kotlin {
explicitApi()

androidTarget {
publishLibraryVariants("release", "debug")
compilations.all {
Expand Down
2 changes: 2 additions & 0 deletions menu/src/androidMain/kotlin/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.composables.ui

import android.view.KeyEvent
import android.view.View.OnKeyListener
import androidx.compose.runtime.Composable
Expand Down
3 changes: 3 additions & 0 deletions menu/src/appleMain/kotlin/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.composables.ui

import androidx.compose.runtime.Composable

@Composable
internal actual fun KeyDownHandler(onEvent: (KeyDownEvent) -> Boolean) {
// not handled
}
14 changes: 8 additions & 6 deletions menu/src/commonMain/kotlin/Menu.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.composables.ui

import androidx.compose.animation.*
import androidx.compose.animation.core.MutableTransitionState
import androidx.compose.animation.core.tween
Expand All @@ -23,7 +25,7 @@ import kotlinx.coroutines.launch

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun Menu(modifier: Modifier = Modifier, contents: @Composable MenuScope.() -> Unit) {
public fun Menu(modifier: Modifier = Modifier, contents: @Composable MenuScope.() -> Unit) {
val scope = remember { MenuScope() }
val coroutineScope = rememberCoroutineScope()
var hasFocus by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -77,18 +79,18 @@ fun Menu(modifier: Modifier = Modifier, contents: @Composable MenuScope.() -> Un


@Composable
fun MenuScope.MenuButton(modifier: Modifier = Modifier, contents: @Composable () -> Unit) {
public fun MenuScope.MenuButton(modifier: Modifier = Modifier, contents: @Composable () -> Unit) {
Box(modifier = modifier.clickable(role = Role.DropdownList) { this.expanded = expanded.not() }) {
contents()
}
}

@Stable
class MenuScope {
public class MenuScope {
internal var expanded by mutableStateOf(false)
internal val menuFocusRequester = FocusRequester()
internal var currentFocusManager by mutableStateOf<FocusManager?>(null)
internal var hasMenuFocus by mutableStateOf<Boolean>(false)
internal var hasMenuFocus by mutableStateOf(false)
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false
Expand Down Expand Up @@ -172,7 +174,7 @@ internal data class DropdownMenuPositionProvider(
}

@Composable
fun MenuScope.MenuContent(
public fun MenuScope.MenuContent(
modifier: Modifier = Modifier,
showTransition: EnterTransition = fadeIn(animationSpec = tween(durationMillis = 0)),
hideTransition: ExitTransition = fadeOut(animationSpec = tween(durationMillis = 0)),
Expand Down Expand Up @@ -213,7 +215,7 @@ fun MenuScope.MenuContent(
}

@Composable
fun MenuScope.MenuItem(
public fun MenuScope.MenuItem(
modifier: Modifier = Modifier,
onClick: () -> Unit,
enabled: Boolean = true,
Expand Down
2 changes: 2 additions & 0 deletions menu/src/commonMain/kotlin/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.composables.ui

import androidx.compose.runtime.Composable
import androidx.compose.ui.input.key.Key

Expand Down
2 changes: 2 additions & 0 deletions menu/src/jvmMain/kotlin/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.composables.ui

import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.input.key.Key
Expand Down
2 changes: 2 additions & 0 deletions menu/src/wasmJsMain/kotlin/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.composables.ui

import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.input.key.Key
Expand Down

0 comments on commit a61eefd

Please sign in to comment.