diff --git a/codegen/src/main/kotlin/com/android/designcompose/codegen/BuilderProcessor.kt b/codegen/src/main/kotlin/com/android/designcompose/codegen/BuilderProcessor.kt index 09300e84c..322c4b5d2 100644 --- a/codegen/src/main/kotlin/com/android/designcompose/codegen/BuilderProcessor.kt +++ b/codegen/src/main/kotlin/com/android/designcompose/codegen/BuilderProcessor.kt @@ -113,6 +113,7 @@ class BuilderProcessor(private val codeGenerator: CodeGenerator, val logger: KSP file += "import com.android.designcompose.CustomizationContext\n" file += "import com.android.designcompose.DesignDoc\n" file += "import com.android.designcompose.DesignComposeCallbacks\n" + file += "import com.android.designcompose.DesignDocSettings\n" file += "import com.android.designcompose.DesignSwitcherPolicy\n" file += "import com.android.designcompose.OpenLinkCallback\n" file += "import com.android.designcompose.DesignNodeData\n" @@ -770,6 +771,8 @@ class BuilderProcessor(private val codeGenerator: CodeGenerator, val logger: KSP // Add optional callbacks to be called on certain document events val defaultCallbacks = if (override) "" else " = null" args.add(Pair("designComposeCallbacks", "DesignComposeCallbacks?$defaultCallbacks")) + val defaultDesignDocSettings = if (override) "" else " = null" + args.add(Pair("designDocSettings", "DesignDocSettings?$defaultDesignDocSettings")) // Add optional key that can be used to uniquely identify this particular instance val keyDefault = if (override) "" else " = null" @@ -989,6 +992,7 @@ class BuilderProcessor(private val codeGenerator: CodeGenerator, val logger: KSP out.appendText( " modifier = modifier.semantics { sDocClass = className},\n" ) + out.appendText(" squoosh = designDocSettings?.enableSquoosh?: false,\n") out.appendText( " serverParams = DocumentServerParams(queries, ignoredImages()),\n" ) @@ -997,7 +1001,9 @@ class BuilderProcessor(private val codeGenerator: CodeGenerator, val logger: KSP if (hideDesignSwitcher) "DesignSwitcherPolicy.HIDE" else "DesignSwitcherPolicy.SHOW_IF_ROOT" out.appendText(" designSwitcherPolicy = $switchPolicy,\n") - out.appendText(" designComposeCallbacks = designComposeCallbacks,\n") + out.appendText( + " designComposeCallbacks = designDocSettings?.designComposeCallbacks,\n" + ) out.appendText(" )\n") out.appendText(" }\n") out.appendText(" }\n\n") diff --git a/designcompose/src/main/java/com/android/designcompose/DesignDocSettings.kt b/designcompose/src/main/java/com/android/designcompose/DesignDocSettings.kt new file mode 100644 index 000000000..bdca38014 --- /dev/null +++ b/designcompose/src/main/java/com/android/designcompose/DesignDocSettings.kt @@ -0,0 +1,6 @@ +package com.android.designcompose + +class DesignDocSettings( + val designComposeCallbacks: DesignComposeCallbacks = DesignComposeCallbacks(), + val enableSquoosh: Boolean = false +) diff --git a/designcompose/src/main/java/com/android/designcompose/DesignView.kt b/designcompose/src/main/java/com/android/designcompose/DesignView.kt index cc85b2ed0..3b50b9914 100644 --- a/designcompose/src/main/java/com/android/designcompose/DesignView.kt +++ b/designcompose/src/main/java/com/android/designcompose/DesignView.kt @@ -938,6 +938,7 @@ fun DesignDoc( docId: String, rootNodeQuery: NodeQuery, modifier: Modifier = Modifier, + squoosh: Boolean = false, placeholder: (@Composable () -> Unit)? = null, customizations: CustomizationContext = CustomizationContext(), serverParams: DocumentServerParams = DocumentServerParams(), @@ -952,6 +953,7 @@ fun DesignDoc( docId, rootNodeQuery, modifier = modifier, + squoosh = squoosh, placeholder = placeholder, customizations = customizations, serverParams = serverParams, @@ -968,7 +970,6 @@ fun DesignDoc( // scrolling, no lists, no transformed input), but it does add animations and is likely the // direction that DesignCompose will move in to be lighter weight and better integrate with // external layout. -private const val USE_SQUOOSH = false @Composable internal fun DesignDocInternal( @@ -976,6 +977,7 @@ internal fun DesignDocInternal( incomingDocId: String, rootNodeQuery: NodeQuery, modifier: Modifier = Modifier, + squoosh: Boolean = false, placeholder: (@Composable () -> Unit)? = null, customizations: CustomizationContext = CustomizationContext(), serverParams: DocumentServerParams = DocumentServerParams(), @@ -985,7 +987,7 @@ internal fun DesignDocInternal( designComposeCallbacks: DesignComposeCallbacks? = null, parentComponents: List = listOf(), ) { - if (USE_SQUOOSH) { + if (squoosh) { SquooshRoot( docName = docName, incomingDocId = incomingDocId, diff --git a/designcompose/src/main/java/com/android/designcompose/squoosh/SquooshRoot.kt b/designcompose/src/main/java/com/android/designcompose/squoosh/SquooshRoot.kt index 009ff40a8..cfe9e8c96 100644 --- a/designcompose/src/main/java/com/android/designcompose/squoosh/SquooshRoot.kt +++ b/designcompose/src/main/java/com/android/designcompose/squoosh/SquooshRoot.kt @@ -40,6 +40,7 @@ import androidx.compose.ui.draw.drawWithContent import androidx.compose.ui.layout.ParentDataModifier import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalFontLoader +import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.TextStyle import androidx.compose.ui.unit.Constraints import androidx.compose.ui.unit.Density @@ -49,6 +50,7 @@ import com.android.designcompose.CustomizationContext import com.android.designcompose.DesignComposeCallbacks import com.android.designcompose.DesignSettings import com.android.designcompose.DesignSwitcherPolicy +import com.android.designcompose.DocRenderStatus import com.android.designcompose.DocServer import com.android.designcompose.DocumentSwitcher import com.android.designcompose.InteractionState @@ -60,6 +62,7 @@ import com.android.designcompose.common.DocumentServerParams import com.android.designcompose.doc import com.android.designcompose.rootNode import com.android.designcompose.rootOverlays +import com.android.designcompose.sDocRenderStatus import com.android.designcompose.serdegen.Dimension import com.android.designcompose.serdegen.Layout import com.android.designcompose.serdegen.NodeQuery @@ -252,6 +255,8 @@ fun SquooshRoot( liveUpdateMode == LiveUpdateMode.OFFLINE ) + LaunchedEffect(docName) { Log.i(TAG, "Squooshing $docName") } + // Design Switcher support val showDesignSwitcher = isRoot && @@ -430,16 +435,18 @@ fun SquooshRoot( CompositionLocalProvider(LocalSquooshIsRootContext provides SquooshIsRoot(false)) { androidx.compose.ui.layout.Layout( modifier = - modifier.squooshRender( - transitionRoot ?: root, - doc, - docName, - customizationContext, - childRenderSelector, - // Is there a nicer way of passing these two? - currentAnimations, - animationValues, - ), + modifier + .squooshRender( + transitionRoot ?: root, + doc, + docName, + customizationContext, + childRenderSelector, + // Is there a nicer way of passing these two? + currentAnimations, + animationValues, + ) + .semantics { sDocRenderStatus = DocRenderStatus.Rendered }, measurePolicy = { measurables, constraints -> // Update the root node style to have the incoming width/height from our parent // Composable. diff --git a/integration-tests/validation/src/main/java/com/android/designcompose/testapp/validation/examples/AllExamples.kt b/integration-tests/validation/src/main/java/com/android/designcompose/testapp/validation/examples/AllExamples.kt index db125599a..582f70ab6 100644 --- a/integration-tests/validation/src/main/java/com/android/designcompose/testapp/validation/examples/AllExamples.kt +++ b/integration-tests/validation/src/main/java/com/android/designcompose/testapp/validation/examples/AllExamples.kt @@ -24,6 +24,7 @@ val EXAMPLES: ArrayList Unit, String?>> = arrayListOf( Triple("Hello", { HelloWorld() }, HelloWorldDoc.javaClass.name), Triple("HelloBye", { HelloBye() }, HelloByeDoc.javaClass.name), + Triple("HelloSquoosh", { HelloSquoosh() }, HelloWorldDoc.javaClass.name), Triple("Image Update", { ImageUpdateTest() }, ImageUpdateTestDoc.javaClass.name), Triple("Telltales", { TelltaleTest() }, TelltaleTestDoc.javaClass.name), Triple("OpenLink", { OpenLinkTest() }, OpenLinkTestDoc.javaClass.name), diff --git a/integration-tests/validation/src/main/java/com/android/designcompose/testapp/validation/examples/HelloSquoosh.kt b/integration-tests/validation/src/main/java/com/android/designcompose/testapp/validation/examples/HelloSquoosh.kt new file mode 100644 index 000000000..d60ff001d --- /dev/null +++ b/integration-tests/validation/src/main/java/com/android/designcompose/testapp/validation/examples/HelloSquoosh.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.designcompose.testapp.validation.examples + +import android.util.Log +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import com.android.designcompose.DesignComposeCallbacks +import com.android.designcompose.DesignDocSettings + +@Composable +fun HelloSquoosh() { + + val designDocSettings = remember { + DesignDocSettings( + designComposeCallbacks = + DesignComposeCallbacks( + docReadyCallback = { id -> + Log.i("DesignCompose", "HelloWorld Ready: doc ID = $id") + }, + newDocDataCallback = { docId, data -> + Log.i( + "DesignCompose", + "HelloWorld Updated doc ID $docId: ${data?.size ?: 0} bytes" + ) + }, + ), + enableSquoosh = true + ) + } + HelloWorldDoc.Main( + name = "Squoosh", + designDocSettings = designDocSettings, + ) +} diff --git a/settings.gradle.kts b/settings.gradle.kts index a8fcf1098..b5deb0f15 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -99,10 +99,12 @@ if (unbundledAAOSDir.isNullOrBlank()) { val unbundledRepo = File(unbundledAAOSDir, "out/aaos-apps-gradle-build/unbundled_m2repo") if (unbundledRepo.exists()) { - include(":media-lib") - project(":media-lib").projectDir = File("reference-apps/aaos-unbundled/media") - include(":mediacompose-app") - project(":mediacompose-app").projectDir = File("reference-apps/aaos-unbundled/mediacompose") + // DO NOT SUBMIT Disabled for now + // include(":media-lib") + // project(":media-lib").projectDir = File("reference-apps/aaos-unbundled/media") + // include(":mediacompose-app") + // project(":mediacompose-app").projectDir = + // File("reference-apps/aaos-unbundled/mediacompose") dependencyResolutionManagement { repositories { maven(uri(unbundledRepo)) } } } else {