Skip to content

Commit

Permalink
Update examples for v1.36.0
Browse files Browse the repository at this point in the history
  • Loading branch information
imgly-bot committed Oct 1, 2024
1 parent 0980fb8 commit 1f37700
Show file tree
Hide file tree
Showing 211 changed files with 10,483 additions and 1,166 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ local.properties
.idea/*
!.idea/codeStyles
build
android-release.keystore
Binary file not shown.
167 changes: 0 additions & 167 deletions app/src/main/java/ly/img/editor/showcase/ShowcaseActivity.kt

This file was deleted.

7 changes: 0 additions & 7 deletions app/src/main/res/values/strings.xml

This file was deleted.

28 changes: 27 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version libs.versions.gradleAndroid apply false
id 'com.android.library' version libs.versions.gradleAndroid apply false
id 'org.jetbrains.kotlin.android' version "$kotlinVersion" apply false
id 'org.jetbrains.kotlin.android' version libs.versions.kotlin apply false
id 'com.google.gms.google-services' version libs.versions.googleServices apply false
id 'com.dropbox.dropshots' version libs.versions.dropshots apply false
id 'com.github.gmazzo.buildconfig' version libs.versions.buildConfig apply false
id 'com.google.firebase.appdistribution' version libs.versions.appDistributionPlugin apply false
id 'com.google.firebase.crashlytics' version libs.versions.gradleCrashlytics apply false
}

subprojects {
// To enable Compose compiler metrics and report (used for debugging Composable parameters stability),
// set `debugComposeCompilerStability=true` in gradle.properties
if ("$debugComposeCompilerStability" == "true") {
tasks.withType(KotlinCompile).configureEach {
kotlinOptions {
freeCompilerArgs += [
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" +
project.buildDir.absolutePath + "/compose_compiler"
]

freeCompilerArgs += [
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" +
project.buildDir.absolutePath + "/compose_compiler"
]
}
}
}
}


task clean(type: Delete) {
delete rootProject.buildDir
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import ly.img.editor.base.components.color_picker.LibraryButton
import ly.img.editor.base.components.LibraryButton
import ly.img.editor.base.ui.EditorUi
import ly.img.editor.base.ui.EditorUiTabIconMappings
import ly.img.editor.core.engine.EngineRenderTarget
Expand Down Expand Up @@ -77,7 +76,6 @@ fun ApparelUi(
mutableStateOf(Unit)
}

val uiScope = rememberCoroutineScope()
val uiState by viewModel.uiState.collectAsState()

EditorUi(
Expand All @@ -98,14 +96,12 @@ fun ApparelUi(
)
},
canvasOverlay = {
if (!uiState.isInPreviewMode && uiState.selectedBlock == null) {
if (!uiState.isInPreviewMode) {
LibraryButton(
modifier =
Modifier
.align(Alignment.BottomStart)
.padding(16.dp),
uiScope = uiScope,
bottomSheetState = uiState.bottomSheetState,
onEvent = viewModel::onEvent,
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ly.img.editor.base.components

import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import ly.img.editor.base.R
import ly.img.editor.base.ui.Event
import ly.img.editor.core.ui.iconpack.Add
import ly.img.editor.core.ui.iconpack.IconPack

@Composable
fun LibraryButton(
modifier: Modifier,
onEvent: (Event) -> Unit,
) {
FloatingActionButton(
modifier = modifier.testTag(tag = "LibraryButton"),
onClick = {
onEvent(Event.OnAddLibraryClick)
},
) {
Icon(IconPack.Add, stringResource(R.string.ly_img_editor_library))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import androidx.compose.ui.unit.dp
import ly.img.editor.base.R
import ly.img.editor.base.ui.BlockEvent
import ly.img.editor.core.ui.iconpack.Bringforward
import ly.img.editor.core.ui.iconpack.Controlpointduplicate
import ly.img.editor.core.ui.iconpack.Delete
import ly.img.editor.core.ui.iconpack.Duplicate
import ly.img.editor.core.ui.iconpack.IconPack
import ly.img.editor.core.ui.iconpack.NavigateBefore
import ly.img.editor.core.ui.iconpack.NavigateNext
import ly.img.editor.core.ui.iconpack.Sendbackward
import ly.img.editor.core.ui.utils.roundToPx
import ly.img.editor.core.ui.utils.toPx
import kotlin.math.cos
import kotlin.math.roundToInt
Expand All @@ -40,10 +41,11 @@ fun CanvasActionMenu(
if (!uiState.show) return

val rotation = uiState.selectedBlockRotation
val gizmoLength = 48.dp.toPx()
val topPadding = 24.dp
val gizmoLength = if (uiState.isGizmoPresent) 48.dp.toPx() else 0f
val topPadding = 24.dp.roundToPx()
val sideMargin = 16.dp.roundToPx()
val cos = cos(rotation)
val dy = cos * gizmoLength
val dy = (cos * gizmoLength).roundToInt()

Surface(
shape = MaterialTheme.shapes.extraLarge,
Expand All @@ -53,12 +55,41 @@ fun CanvasActionMenu(
Modifier
.layout { measurable, constraints ->
val placeable = measurable.measure(constraints)
layout(placeable.width, placeable.height) {
val x = uiState.selectedBlockRect.centerX().dp.roundToPx() - placeable.width / 2
val y =
(uiState.selectedBlockRect.centerY() - uiState.selectedBlockRect.height() / 2).dp.roundToPx() -
placeable.height - topPadding.roundToPx() + if (dy < 0) dy.roundToInt() else 0
placeable.place(x, y)
val width = placeable.width
val height = placeable.height
layout(width, height) {
// In certain scenarios (eg. changing theme while the Canvas Action Menu is visible),
// it was observed that minWidth = maxWidth = 0. Not sure why this happens, for now, we just return here.
if (constraints.isZero) return@layout

val x = uiState.selectedBlockRect.centerX().dp.roundToPx() - width / 2
val minX = constraints.minWidth + sideMargin
val maxX = constraints.maxWidth - width - sideMargin
val constrainedX = x.coerceIn(minX, maxX)

// Preference order -
// 1. Top
// 2. Bottom
// 3. Below top handle
fun calculateConstrainedY(): Int {
val blockCenterY = uiState.selectedBlockRect.centerY()
val blockHeight = uiState.selectedBlockRect.height()
val minY = constraints.minHeight + uiState.currentInsets.top.dp.roundToPx()
val topY =
(blockCenterY - blockHeight / 2).dp.roundToPx() - height - topPadding + if (dy < 0) dy else 0
if (topY > minY) {
return topY
}
val bottomY = (blockCenterY + blockHeight / 2).dp.roundToPx() + topPadding + if (dy > 0) dy else 0
val bottomCutOff = constraints.maxHeight - uiState.currentInsets.bottom.dp.roundToPx()
if (bottomY + height + sideMargin <= bottomCutOff) {
return bottomY
}
return (blockCenterY - blockHeight / 2).dp.roundToPx() + sideMargin + if (dy < 0) dy else 0
}

val constrainedY = calculateConstrainedY()
placeable.place(constrainedX, constrainedY)
}
},
) {
Expand All @@ -69,7 +100,7 @@ fun CanvasActionMenu(
if (uiState.isDuplicateAllowed) {
IconButton(onClick = { onEvent(BlockEvent.OnDuplicate) }) {
Icon(
IconPack.Controlpointduplicate,
IconPack.Duplicate,
contentDescription = stringResource(R.string.ly_img_editor_duplicate),
)
}
Expand Down
Loading

0 comments on commit 1f37700

Please sign in to comment.