-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix but rendering component instance that has nested variants
Fixes #2012. When resolving a variant by matching property and value names, don't give up as soon as a property doesn't match. This property could be used for a nested variant. As long as at least one property matches, keep looping through properties, then find a view with the resulting set of matched properties/values. If no properties match at all, then return null.
- Loading branch information
Showing
5 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+10.7 KB
...ation-tests/validation/src/main/assets/figma/VariantNestingDoc_lpUWHv5gZh6WOx56pRnJ2s.dcf
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ion/src/main/java/com/android/designcompose/testapp/validation/examples/VariantNesting.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2025 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 com.android.designcompose.ComponentReplacementContext | ||
import com.android.designcompose.annotation.Design | ||
import com.android.designcompose.annotation.DesignComponent | ||
import com.android.designcompose.annotation.DesignDoc | ||
import com.android.designcompose.annotation.DesignVariant | ||
|
||
enum class BoxType { | ||
Blue, | ||
Red, | ||
} | ||
|
||
enum class CircleType { | ||
Green, | ||
Purple, | ||
} | ||
|
||
@DesignDoc(id = "lpUWHv5gZh6WOx56pRnJ2s") | ||
interface VariantNesting { | ||
@DesignComponent(node = "#stage") | ||
fun Main(@Design(node = "#replace") replace: @Composable (ComponentReplacementContext) -> Unit) | ||
|
||
@DesignComponent(node = "#Box") | ||
fun Box( | ||
@DesignVariant(property = "#BoxType") boxType: BoxType, | ||
@DesignVariant(property = "#CircleType") circleType: CircleType, | ||
) | ||
} | ||
|
||
@Composable | ||
fun VariantNesting() { | ||
VariantNestingDoc.Main( | ||
replace = { VariantNestingDoc.Box(boxType = BoxType.Blue, circleType = CircleType.Purple) } | ||
) | ||
} |
Binary file added
BIN
+7.32 KB
...-tests/validation/src/testDebug/roborazzi/RenderAllExamples/Variant-Nesting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.