Skip to content

Commit

Permalink
Inline ComposeDialog due to compilations errors on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstyl committed Oct 16, 2024
1 parent c8f52c0 commit 9ed8f15
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 46 deletions.
32 changes: 30 additions & 2 deletions core/src/appleMain/kotlin/Modal.apple.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
package com.composables.core

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.KeyEvent
import internal.ComposeDialog
import androidx.compose.ui.input.key.onKeyEvent
import androidx.compose.ui.window.DialogProperties

@Composable
internal actual fun Modal(
protectNavBars: Boolean,
onKeyEvent: (KeyEvent) -> Boolean,
content: @Composable () -> Unit
) = ComposeDialog(onKeyEvent, content)
) = androidx.compose.ui.window.Dialog(
onDismissRequest = {},
properties = DialogProperties(
dismissOnBackPress = false,
dismissOnClickOutside = false,
usePlatformInsets = false,
usePlatformDefaultWidth = false,
scrimColor = Color.Transparent
),
content = {
val focusRequester = remember { FocusRequester() }
Box(Modifier.focusRequester(focusRequester).fillMaxSize().onKeyEvent(onKeyEvent)) {
LaunchedEffect(Unit) {
focusRequester.requestFocus()
}
content()
}
}
)

38 changes: 0 additions & 38 deletions core/src/commonMain/kotlin/internal/ComposeDialog.kt

This file was deleted.

32 changes: 30 additions & 2 deletions core/src/jsMain/kotlin/Modal.js.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
package com.composables.core

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.KeyEvent
import internal.ComposeDialog
import androidx.compose.ui.input.key.onKeyEvent
import androidx.compose.ui.window.DialogProperties

@Composable
internal actual fun Modal(
protectNavBars: Boolean,
onKeyEvent: (KeyEvent) -> Boolean,
content: @Composable () -> Unit
) = ComposeDialog(onKeyEvent, content)
) = androidx.compose.ui.window.Dialog(
onDismissRequest = {},
properties = DialogProperties(
dismissOnBackPress = false,
dismissOnClickOutside = false,
usePlatformInsets = false,
usePlatformDefaultWidth = false,
scrimColor = Color.Transparent
),
content = {
val focusRequester = remember { FocusRequester() }
Box(Modifier.focusRequester(focusRequester).fillMaxSize().onKeyEvent(onKeyEvent)) {
LaunchedEffect(Unit) {
focusRequester.requestFocus()
}
content()
}
}
)

31 changes: 29 additions & 2 deletions core/src/jvmMain/kotlin/Modal.jvm.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
package com.composables.core

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.KeyEvent
import internal.ComposeDialog
import androidx.compose.ui.input.key.onKeyEvent
import androidx.compose.ui.window.DialogProperties

@Composable
internal actual fun Modal(
protectNavBars: Boolean,
onKeyEvent: (KeyEvent) -> Boolean,
content: @Composable () -> Unit
) = ComposeDialog(onKeyEvent, content)
) = androidx.compose.ui.window.Dialog(
onDismissRequest = {},
properties = DialogProperties(
dismissOnBackPress = false,
dismissOnClickOutside = false,
usePlatformInsets = false,
usePlatformDefaultWidth = false,
scrimColor = Color.Transparent
),
content = {
val focusRequester = remember { FocusRequester() }
Box(Modifier.focusRequester(focusRequester).fillMaxSize().onKeyEvent(onKeyEvent)) {
LaunchedEffect(Unit) {
focusRequester.requestFocus()
}
content()
}
}
)
31 changes: 29 additions & 2 deletions core/src/wasmJsMain/kotlin/Modal.wasmJs.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
package com.composables.core

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.KeyEvent
import internal.ComposeDialog
import androidx.compose.ui.input.key.onKeyEvent
import androidx.compose.ui.window.DialogProperties

@Composable
internal actual fun Modal(
protectNavBars: Boolean,
onKeyEvent: (KeyEvent) -> Boolean,
content: @Composable () -> Unit
) = ComposeDialog(onKeyEvent, content)
) = androidx.compose.ui.window.Dialog(
onDismissRequest = {},
properties = DialogProperties(
dismissOnBackPress = false,
dismissOnClickOutside = false,
usePlatformInsets = false,
usePlatformDefaultWidth = false,
scrimColor = Color.Transparent
),
content = {
val focusRequester = remember { FocusRequester() }
Box(Modifier.focusRequester(focusRequester).fillMaxSize().onKeyEvent(onKeyEvent)) {
LaunchedEffect(Unit) {
focusRequester.requestFocus()
}
content()
}
}
)

0 comments on commit 9ed8f15

Please sign in to comment.