fix: [PREVIEW] android preview fix (#66)

* fix: [PREVIEW] android preview fix

* fix: [PREVIEW] android preview fix

---------

Co-authored-by: Florent Champigny <florent@bere.al>
This commit is contained in:
Florent CHAMPIGNY 2025-08-07 09:43:43 +02:00 committed by GitHub
parent 2dc5daba01
commit 6f6623fff2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 83 additions and 16 deletions

View file

@ -0,0 +1,18 @@
package io.github.openflocon.flocondesktop.common.ui.window
import androidx.compose.runtime.Composable
actual fun createFloconWindowState(): FloconWindowState {
TODO("Not yet implemented")
}
@Composable
actual fun FloconWindow(
title: String,
state: FloconWindowState,
onCloseRequest: () -> Unit,
content: @Composable () -> Unit,
) {
TODO()
}

View file

@ -0,0 +1,15 @@
package io.github.openflocon.flocondesktop.common.ui.window
import androidx.compose.runtime.Composable
interface FloconWindowState
expect fun createFloconWindowState(): FloconWindowState
@Composable
expect fun FloconWindow(
title: String,
state: FloconWindowState,
onCloseRequest: () -> Unit,
content: @Composable () -> Unit,
)

View file

@ -25,11 +25,9 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowState
import com.sebastianneubauer.jsontree.search.rememberSearchState
import flocondesktop.composeapp.generated.resources.Res
import flocondesktop.composeapp.generated.resources.app_icon
import io.github.openflocon.flocondesktop.common.ui.window.FloconWindow
import io.github.openflocon.flocondesktop.common.ui.window.FloconWindowState
import io.github.openflocon.flocondesktop.features.network.ui.model.NetworkJsonUi
import io.github.openflocon.library.designsystem.FloconTheme
import io.github.openflocon.library.designsystem.components.FloconIcon
@ -38,12 +36,11 @@ import io.github.openflocon.library.designsystem.components.FloconJsonTree
import io.github.openflocon.library.designsystem.components.FloconSurface
import io.github.openflocon.library.designsystem.components.FloconTextField
import kotlinx.coroutines.launch
import org.jetbrains.compose.resources.painterResource
@Composable
fun NetworkJsonScreen(
json: NetworkJsonUi,
state: WindowState,
state: FloconWindowState,
onCloseRequest: () -> Unit
) {
var query by remember { mutableStateOf("") }
@ -56,9 +53,8 @@ fun NetworkJsonScreen(
searchState.query = query
}
Window(
FloconWindow(
title = "Body",
icon = painterResource(Res.drawable.app_icon),
state = state,
onCloseRequest = onCloseRequest
) {

View file

@ -23,10 +23,9 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.WindowPlacement
import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.window.WindowState
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import io.github.openflocon.flocondesktop.common.ui.window.FloconWindowState
import io.github.openflocon.flocondesktop.common.ui.window.createFloconWindowState
import io.github.openflocon.flocondesktop.features.network.ui.NetworkAction
import io.github.openflocon.flocondesktop.features.network.ui.NetworkUiState
import io.github.openflocon.flocondesktop.features.network.ui.NetworkViewModel
@ -145,7 +144,7 @@ fun NetworkScreen(
}
}
val states = remember { mutableStateMapOf<NetworkJsonUi, WindowState>() }
val states = remember { mutableStateMapOf<NetworkJsonUi, FloconWindowState>() }
LaunchedEffect(uiState.contentState.detailJsons) {
@ -155,10 +154,7 @@ fun NetworkScreen(
deletedJson.forEach { states.remove(it) }
addedJson.forEach {
states.put(
it, WindowState(
placement = WindowPlacement.Floating,
position = WindowPosition(Alignment.Center)
)
it, createFloconWindowState()
)
}
}

View file

@ -0,0 +1,42 @@
package io.github.openflocon.flocondesktop.common.ui.window
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowPlacement
import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.window.WindowState
import flocondesktop.composeapp.generated.resources.Res
import flocondesktop.composeapp.generated.resources.app_icon
import org.jetbrains.compose.resources.painterResource
data class FloconWindowStateDesktop(
val windowState: WindowState
) : FloconWindowState
actual fun createFloconWindowState(): FloconWindowState {
return FloconWindowStateDesktop(
WindowState(
placement = WindowPlacement.Floating,
position = WindowPosition(Alignment.Center)
)
)
}
@Composable
actual fun FloconWindow(
title: String,
state: FloconWindowState,
onCloseRequest: () -> Unit,
content: @Composable () -> Unit,
) {
Window(
title = title,
icon = painterResource(Res.drawable.app_icon),
state = (state as FloconWindowStateDesktop).windowState,
onCloseRequest = onCloseRequest,
) {
content()
}
}