Skip to content

Commit

Permalink
Merge pull request #688 from manuel-martos/2.x-update-compose
Browse files Browse the repository at this point in the history
Update Compose
  • Loading branch information
manuel-martos authored Apr 3, 2024
2 parents b5c73d0 + aef36ee commit 339a43c
Show file tree
Hide file tree
Showing 51 changed files with 183 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.Button
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Text
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
Expand All @@ -29,12 +29,12 @@ import com.bumble.appyx.interactions.composable.AppyxInteractionsContainer
import com.bumble.appyx.interactions.model.transition.Operation.Mode.IMMEDIATE
import com.bumble.appyx.interactions.model.transition.Operation.Mode.KEYFRAME
import com.bumble.appyx.interactions.ui.helper.AppyxComponentSetup
import com.bumble.appyx.interactions.utils.ui.Element
import com.bumble.appyx.interactions.utils.testing.TestTarget
import com.bumble.appyx.interactions.utils.testing.TestTarget.Child1
import com.bumble.appyx.interactions.utils.testing.TestTarget.Child2
import com.bumble.appyx.interactions.utils.testing.TestTarget.Child3
import com.bumble.appyx.interactions.utils.testing.TestTarget.Child4
import com.bumble.appyx.interactions.utils.ui.Element
import kotlin.math.roundToInt


Expand Down Expand Up @@ -71,8 +71,10 @@ fun PromoterExperiment(modifier: Modifier = Modifier) {
.fillMaxSize()
) {
val density = LocalDensity.current
val screenWidthPx = (LocalConfiguration.current.screenWidthDp * density.density).roundToInt()
val screenHeightPx = (LocalConfiguration.current.screenHeightDp * density.density).roundToInt()
val screenWidthPx =
(LocalConfiguration.current.screenWidthDp * density.density).roundToInt()
val screenHeightPx =
(LocalConfiguration.current.screenHeightDp * density.density).roundToInt()

AppyxInteractionsContainer(
appyxComponent = promoter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
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.layout.onSizeChanged
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.CanvasBasedWindow
import com.bumble.appyx.components.experimental.puzzle15.ui.Puzzle15Ui
import org.jetbrains.skiko.wasm.onWasmReady

@OptIn(ExperimentalComposeUiApi::class)
fun main() {
onWasmReady {
Window("Puzzle15") {
CanvasBasedWindow("Puzzle15") {
val requester = remember { FocusRequester() }
var size by remember { mutableStateOf(IntSize.Zero) }
Surface(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.compose.animation.core.SpringSpec
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Surface
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ private const val CANVAS_ELEMENT_ID = "ComposeTarget" // Hardwired into ComposeW
/**
* A Skiko/Canvas-based top-level window using the browser's entire viewport. Supports resizing.
*/
@Composable
@Suppress("FunctionNaming")
fun BrowserViewportWindow(
title: String = "Untitled",
content: @Composable ComposeWindow.() -> Unit
content: @Composable () -> Unit
) {
val htmlHeadElement = document.head!!
htmlHeadElement.appendChild(
Expand Down Expand Up @@ -59,7 +60,7 @@ fun BrowserViewportWindow(
fillViewportSize()
}

ComposeWindow().apply {
ComposeWindow(canvasId = "Appyx", content = content).apply {
window.addEventListener("resize", {
canvas.fillViewportSize()
layer.layer.attachTo(canvas)
Expand All @@ -77,9 +78,5 @@ fun BrowserViewportWindow(
?: document.createElement("title").also { htmlHeadElement.appendChild(it) }
) as HTMLTitleElement
htmlTitleElement.textContent = title

setContent {
content(this)
}
}
}
57 changes: 56 additions & 1 deletion demos/appyx-interactions/android/lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="6" by="lint 7.4.0" type="baseline" client="gradle" dependencies="false" name="AGP (7.4.0)" variant="all" version="7.4.0">
<issues format="6" by="lint 8.2.1" type="baseline" client="gradle" dependencies="false" name="AGP (8.2.1)" variant="all" version="8.2.1">

<issue
id="UsingMaterialAndMaterial3Libraries"
message="Using a material import while also using the material3 library"
errorLine1="import androidx.compose.material.FractionalThreshold"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/com/bumble/appyx/interactions/sample/KnobControl.kt"
line="12"
column="8"/>
</issue>

<issue
id="UsingMaterialAndMaterial3Libraries"
message="Using a material import while also using the material3 library"
errorLine1="import androidx.compose.material.rememberSwipeableState"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/com/bumble/appyx/interactions/sample/KnobControl.kt"
line="13"
column="8"/>
</issue>

<issue
id="UsingMaterialAndMaterial3Libraries"
message="Using a material import while also using the material3 library"
errorLine1="import androidx.compose.material.swipeable"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/com/bumble/appyx/interactions/sample/KnobControl.kt"
line="14"
column="8"/>
</issue>

<issue
id="UsingMaterialAndMaterial3Libraries"
message="Using a material import while also using the material3 library"
errorLine1="import androidx.compose.material.Button"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/com/bumble/appyx/interactions/sample/SpotlightExperiment.kt"
line="12"
column="8"/>
</issue>

<issue
id="UsingMaterialAndMaterial3Libraries"
message="Using a material import while also using the material3 library"
errorLine1="import androidx.compose.material.Text"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/com/bumble/appyx/interactions/sample/SpotlightExperiment.kt"
line="13"
column="8"/>
</issue>

</issues>
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.CanvasBasedWindow
import com.bumble.appyx.components.internal.testdrive.TestDriveExperiment
import com.bumble.appyx.components.internal.testdrive.ui.md_amber_500
import com.bumble.appyx.components.internal.testdrive.ui.md_blue_500
Expand Down Expand Up @@ -53,9 +54,10 @@ enum class InteractionTarget {
Child1
}

@OptIn(ExperimentalComposeUiApi::class)
fun main() {
onWasmReady {
Window("Appyx") {
CanvasBasedWindow("Appyx") {
var size by remember { mutableStateOf(IntSize.Zero) }
Surface(
modifier = Modifier
Expand Down
2 changes: 1 addition & 1 deletion demos/appyx-navigation/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ kotlin {
api(project(":utils:utils-customisations"))
api(project(":utils:utils-material3"))
api(project(":utils:utils-multiplatform"))
api(project(":demos:image-loader:image-loader"))
api(project(":demos:image-loader:loader"))
implementation(project(":appyx-components:experimental:cards:cards"))
implementation(project(":appyx-components:experimental:promoter:promoter"))
implementation(project(":appyx-components:standard:backstack:backstack"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Card
import androidx.compose.material3.DismissDirection.EndToStart
import androidx.compose.material3.DismissValue
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SwipeToDismiss
import androidx.compose.material3.SwipeToDismissBox
import androidx.compose.material3.SwipeToDismissBoxValue
import androidx.compose.material3.Text
import androidx.compose.material3.rememberDismissState
import androidx.compose.material3.rememberSwipeToDismissBoxState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
Expand Down Expand Up @@ -118,12 +117,12 @@ private fun LazyItemScope.CartListItem(
val quantity = cakeToQuantity.second
val coroutineScope = rememberCoroutineScope()

val dismissState = rememberDismissState(confirmValueChange = { dismissValue ->
val dismissState = rememberSwipeToDismissBoxState(confirmValueChange = { dismissValue ->
when (dismissValue) {
DismissValue.Default,
DismissValue.DismissedToEnd -> false
SwipeToDismissBoxValue.Settled,
SwipeToDismissBoxValue.StartToEnd -> false

DismissValue.DismissedToStart -> {
SwipeToDismissBoxValue.EndToStart -> {
coroutineScope.launch {
delay(250)
onDeleteCake(cake)
Expand All @@ -133,21 +132,21 @@ private fun LazyItemScope.CartListItem(
}
})

SwipeToDismiss(
SwipeToDismissBox(
modifier = Modifier.animateItemPlacement(),
state = dismissState,
directions = setOf(EndToStart),
background = { CartItemDismissBackground() },
dismissContent = {
CardItem(
cake = cake,
quantity = quantity,
onGoToCake = onGoToCake,
plusOneCakeAction = onPlusOneCake,
minusOneCakeAction = onMinusOneCake,
)
},
)
enableDismissFromStartToEnd = false,
enableDismissFromEndToStart = true,
backgroundContent = { CartItemDismissBackground() },
) {
CardItem(
cake = cake,
quantity = quantity,
onGoToCake = onGoToCake,
plusOneCakeAction = onPlusOneCake,
minusOneCakeAction = onMinusOneCake,
)
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.layout.ContentScale
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.resource
import org.jetbrains.compose.resources.InternalResourceApi
import org.jetbrains.compose.resources.readResourceBytes

@OptIn(InternalResourceApi::class)
@Suppress("TooGenericExceptionCaught", "SwallowedException")
@OptIn(ExperimentalResourceApi::class)
@Composable
fun ResourceImage(
path: String,
Expand All @@ -29,13 +29,11 @@ fun ResourceImage(
LaunchedEffect(Unit) {
image = withContext(Dispatchers.Default) {
try {
resource(path)
.readBytes()
readResourceBytes(path)
.toImageBitmap()
} catch (e: Throwable) {
try {
resource(fallbackUrl)
.readBytes()
readResourceBytes(fallbackUrl)
.toImageBitmap()
} catch (e: Throwable) {
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.CanvasBasedWindow
import com.bumble.appyx.demos.appyxSample
import com.bumble.appyx.demos.common.color_dark


@OptIn(ExperimentalComposeUiApi::class)
fun main() {
appyxSample {
Window("Appyx") {
CanvasBasedWindow("Appyx") {
var size by remember { mutableStateOf(IntSize.Zero) }
Surface(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.CanvasBasedWindow
import com.bumble.appyx.demos.appyxSample
import com.bumble.appyx.demos.common.color_dark


@OptIn(ExperimentalComposeUiApi::class)
fun main() {
appyxSample {
Window("Appyx") {
CanvasBasedWindow("Appyx") {
var size by remember { mutableStateOf(IntSize.Zero) }
Surface(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.CanvasBasedWindow
import com.bumble.appyx.demos.appyxSample
import com.bumble.appyx.demos.common.color_dark


@OptIn(ExperimentalComposeUiApi::class)
fun main() {
appyxSample {
Window("Appyx") {
CanvasBasedWindow("Appyx") {
var size by remember { mutableStateOf(IntSize.Zero) }
Surface(
modifier = Modifier
Expand Down
Loading

0 comments on commit 339a43c

Please sign in to comment.