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..6e6f1c3e1 --- /dev/null +++ b/designcompose/src/main/java/com/android/designcompose/DesignDocSettings.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2024 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 + +import androidx.compose.runtime.compositionLocalOf + +/** + * When applied as a compositionLocal, these settings will alter features or add functionality to + * DesignCompose Composables + * + * @property useSquoosh: Enable use of the Squoosh renderer. Squoosh implements its own view tree, + * rather than using Compose, which brings some performance and flexibility benefits. Squoosh + * isn't feature complete (no 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. + */ +class DesignDocSettings( + val useSquoosh: Boolean = false, +) + +val LocalDesignDocSettings = compositionLocalOf { DesignDocSettings() } diff --git a/designcompose/src/main/java/com/android/designcompose/DesignView.kt b/designcompose/src/main/java/com/android/designcompose/DesignView.kt index cc85b2ed0..9b5f66971 100644 --- a/designcompose/src/main/java/com/android/designcompose/DesignView.kt +++ b/designcompose/src/main/java/com/android/designcompose/DesignView.kt @@ -963,13 +963,6 @@ fun DesignDoc( endSection() } -// Enable the "Squoosh" refactor. Squoosh implements its own view tree, rather than using Compose, -// which brings some performance and flexibility benefits. Squoosh isn't feature complete (no -// 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( docName: String, @@ -985,7 +978,7 @@ internal fun DesignDocInternal( designComposeCallbacks: DesignComposeCallbacks? = null, parentComponents: List = listOf(), ) { - if (USE_SQUOOSH) { + if (LocalDesignDocSettings.current.useSquoosh) { SquooshRoot( docName = docName, incomingDocId = incomingDocId, 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 63b8df70f..ead2d75dd 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..7f513f4fb --- /dev/null +++ b/integration-tests/validation/src/main/java/com/android/designcompose/testapp/validation/examples/HelloSquoosh.kt @@ -0,0 +1,31 @@ +/* + * 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 androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import com.android.designcompose.DesignDocSettings +import com.android.designcompose.LocalDesignDocSettings + +@Composable +fun HelloSquoosh() { + CompositionLocalProvider(LocalDesignDocSettings provides DesignDocSettings(useSquoosh = true)) { + HelloWorldDoc.Main( + name = "Squoosh", + ) + } +} diff --git a/integration-tests/validation/src/testDebug/roborazzi/RenderAllExamples/HelloSquoosh.png b/integration-tests/validation/src/testDebug/roborazzi/RenderAllExamples/HelloSquoosh.png new file mode 100644 index 000000000..00a5030d2 Binary files /dev/null and b/integration-tests/validation/src/testDebug/roborazzi/RenderAllExamples/HelloSquoosh.png differ