Skip to content

Commit

Permalink
Resolve various warnings in the code
Browse files Browse the repository at this point in the history
This should help us track down some of the bugs we're having with the proto conversion.

# Conflicts:
#	designcompose/src/main/java/com/android/designcompose/squoosh/SquooshText.kt
#	designcompose/src/main/java/com/android/designcompose/squoosh/SquooshTreeBuilder.kt
#	integration-tests/validation/src/main/java/com/android/designcompose/testapp/validation/examples/AllExamples.kt
#	integration-tests/validation/src/main/java/com/android/designcompose/testapp/validation/examples/VariantAnimationTimelineTest.kt
  • Loading branch information
timothyfroehlich committed Dec 26, 2024
1 parent b7e4597 commit fde2c87
Show file tree
Hide file tree
Showing 24 changed files with 251 additions and 577 deletions.
1 change: 0 additions & 1 deletion crates/figma_import/src/design_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ where
#[cfg(test)]
mod serialized_document_tests {


use dc_bundle::definition_file::{load_design_def, save_design_def};
use std::fs::File;
use std::io::Write;
Expand Down
Binary file modified crates/figma_import/tests/layout-unit-tests.dcf
Binary file not shown.
4 changes: 1 addition & 3 deletions crates/figma_import/tests/test_fetches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
#![cfg(feature = "fetch")]

use dc_bundle::definition::DesignComposeDefinitionHeader;
use dc_bundle::definition_file::{
load_design_def, save_design_def,
};
use dc_bundle::definition_file::{load_design_def, save_design_def};
use figma_import::tools::fetch::{build_definition, load_figma_token};
use figma_import::{Document, ProxyConfig};
use tempfile::NamedTempFile;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import kotlinx.coroutines.launch

// Need to rename all of this to use "Access Token" instead of "Auth Key". This will match Figma's
// terminology: https://help.figma.com/hc/en-us/articles/8085703771159-Manage-personal-access-tokens
public var ACTION_SET_API_KEY = "setApiKey"
public var EXTRA_SET_API_KEY = "ApiKey"
var ACTION_SET_API_KEY = "setApiKey"
var EXTRA_SET_API_KEY = "ApiKey"

class ApiKeyService : Service() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ typealias MeterState = FloatState

typealias Meter = Float

typealias ShaderUniformTime = Float

typealias ShaderUniformTimeState = FloatState

// A class that holds the scroll state of a horizontal or vertical autolayout view (row/column)
Expand Down Expand Up @@ -324,10 +322,6 @@ fun CustomizationContext.setVisibleState(nodeName: String, visible: State<Boolea
customize(nodeName) { c -> c.visibleState = Optional.ofNullable(visible) }
}

fun CustomizationContext.setTextStyle(nodeName: String, textStyle: TextStyle) {
customize(nodeName) { c -> c.textStyle = Optional.ofNullable(textStyle) }
}

fun CustomizationContext.setMeterValue(nodeName: String, value: Float) {
customize(nodeName) { c -> c.meterValue = Optional.ofNullable(value) }
}
Expand Down Expand Up @@ -389,10 +383,6 @@ fun CustomizationContext.getTextState(nodeName: String): State<String>? {
return cs[nodeName]?.textState?.getOrNull()
}

fun CustomizationContext.getModifier(nodeName: String): Modifier? {
return cs[nodeName]?.modifier?.getOrNull()
}

fun CustomizationContext.getTapCallback(nodeName: String): TapCallback? {
return cs[nodeName]?.tapCallback?.getOrNull()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,6 @@ private interface DesignSwitcher {
)
}

private fun nodeCustomizations(): Array<String> {
return arrayOf(
"#MiniViewMessage",
"#CurrentlyLoaded",
"#ChangingCurrent",
"#CurrentFileName",
"#ModDate",
"#BranchFileCount",
"#ProjectFileCount",
"#BranchList",
"#BranchSection",
"#ProjectFileList",
"#StatusMessageList",
"#DocIdTextEdit",
"#HelpText",
"#GoButton",
"#NodeNamesCheckbox",
"#MiniMessagesCheckbox",
"#ShowRecompositionCheckbox",
"#UseLocalResCheckbox",
"#Name",
"#Id",
"#Text",
"#TimeStamp",
"#Logout",
"#LiveMode",
"#TopStatusBar",
)
}

private fun ignoredImages(): HashMap<String, Array<String>> {
return hashMapOf(
"#SettingsView" to
Expand Down Expand Up @@ -374,7 +344,7 @@ private fun GetBranches(
}

private fun GetProjectFileCount(doc: DocContent?): String {
var count = doc?.c?.project_files?.size ?: 0
val count = doc?.c?.project_files?.size ?: 0
return count.toString()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ internal fun DocServer.fetchDocuments(firstFetch: Boolean): Boolean {
SpanCache.clear()
for (subscriber in subs) {
subscriber.onUpdate(doc)
subscriber.docUpdateCallback?.invoke(id, doc.c?.toSerializedBytes(Feedback))
subscriber.docUpdateCallback?.invoke(id, doc.c.toSerializedBytes(Feedback))
}
}
Feedback.documentUpdated(id, subs.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private fun calculateProgressBarData(
var endY = progressBarData.endY
parent?.let { p ->
val parentSize = p.computedLayout?.let { Size(it.width, it.height) }
parentSize?.let { pSize ->
parentSize?.let {
val parentRenderSize = getNodeRenderSize(null, parentSize, p.style, p.layoutId, 1f)
endY = parentRenderSize.height
}
Expand All @@ -212,7 +212,7 @@ private fun calculateProgressBarData(
var endX = progressBarData.endX
parent?.let { p ->
val parentSize = p.computedLayout?.let { Size(it.width, it.height) }
parentSize?.let { pSize ->
parentSize?.let {
val parentRenderSize = getNodeRenderSize(null, parentSize, p.style, p.layoutId, 1f)
endX = parentRenderSize.width
}
Expand Down Expand Up @@ -251,15 +251,15 @@ private fun calculateProgressMarkerData(
// along the x or y axis depending on whether it is horizontal or vertical
val overrideTransform = style.getTransform(density)
if (markerData.vertical) {
var startY =
val startY =
parentSize?.let { it.height - (mySize?.height ?: 0f) / 2f } ?: markerData.startY
val endY = mySize?.let { -it.height / 2f } ?: markerData.endY
val moveY = lerp(startY, endY, discretizedMeterValue, density)
val topOffset = style.layoutStyle.margin.top.pointsAsDp(density).value
overrideTransform.setYTranslation(moveY - topOffset)
} else {
var startX = mySize?.let { -it.width / 2f } ?: markerData.startX
var endX = parentSize?.let { it.width - (mySize?.width ?: 0f) / 2f } ?: markerData.endX
val startX = mySize?.let { -it.width / 2f } ?: markerData.startX
val endX = parentSize?.let { it.width - (mySize?.width ?: 0f) / 2f } ?: markerData.endX
val moveX = lerp(startX, endX, discretizedMeterValue, density)
val leftOffset = style.layoutStyle.margin.start.pointsAsDp(density).value
overrideTransform.setXTranslation(moveX - leftOffset)
Expand Down Expand Up @@ -418,12 +418,7 @@ internal fun ContentDrawScope.render(

// Push any transforms
val transform = overrideTransform ?: style.nodeStyle.transform.asComposeTransform(density)
var vectorScaleX = 1F
var vectorScaleY = 1F
if (transform != null) {
val decomposed = style.nodeStyle.transform.decompose(density)
vectorScaleX = abs(decomposed.scaleX)
vectorScaleY = abs(decomposed.scaleY)
drawContext.transform.transform(transform)
}

Expand Down Expand Up @@ -706,12 +701,7 @@ internal fun ContentDrawScope.squooshShapeRender(

// Push any transforms
val transform = overrideTransform ?: style.nodeStyle.transform.asComposeTransform(density)
var vectorScaleX = 1F
var vectorScaleY = 1F
if (transform != null) {
val decomposed = style.nodeStyle.transform.decompose(density)
vectorScaleX = abs(decomposed.scaleX)
vectorScaleY = abs(decomposed.scaleY)
drawContext.transform.transform(transform)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,34 @@ private fun getInstanceIdWithKey(instanceId: String, key: String?): String {
internal open class DeferredAction {
/// Navigate back, and restore the `overlay_memory`. This is used when a "navigate"
/// action has to be undone.
class NavigateBack(val overlayMemory: List<String>) : DeferredAction() {}
class NavigateBack(val overlayMemory: List<String>) : DeferredAction()

/// The temporary action was a "swap navigation" (where the top of the navigation
/// stack is swapped, rather than being appended to), so we need to swap back to
/// the previous entry. We keep a NodeQuery instead of a String, because we could
/// be swapping the first entry in the navigation stack which comes from application
/// code and is normally a node name (and NodeQuery contains names or IDs).
class SwapNavigation(val nodeQuery: NodeQuery) : DeferredAction() {}
class SwapNavigation(val nodeQuery: NodeQuery) : DeferredAction()

/// Close the top-most overlay
class CloseTopOverlay(val transition: Transition?) : DeferredAction() {}
class CloseTopOverlay(val transition: Transition?) : DeferredAction()

/// The temporary action was to open an overlay, so we need to close the same overlay
class CloseOverlay(val overlayId: String, val transition: Transition?) : DeferredAction() {}
class CloseOverlay(val overlayId: String, val transition: Transition?) : DeferredAction()

/// The temporary action was to close an overlay, so we need to open the overlay
/// again to undo the action (and the ID of the overlay to open is the String).
class OpenOverlay(val overlayId: String, val transition: Transition?) : DeferredAction() {}
class OpenOverlay(val overlayId: String, val transition: Transition?) : DeferredAction()

/// The temporary action was a "swap overlay", so we need to swap back to the
/// previously displayed overlay.
class SwapOverlay(val overlayId: String, val transition: Transition?) : DeferredAction() {}
class SwapOverlay(val overlayId: String, val transition: Transition?) : DeferredAction()

/// The temporary action was a "change to" on a component variant. We need to change
/// back to the variant we were showing before, which could be the default (in which
/// case the value is null), or could be some other specific variant (in which case
/// the value will be the node ID).
class ChangeTo(val nodeId: String?) : DeferredAction() {}
class ChangeTo(val nodeId: String?) : DeferredAction()
}

/// Execute a DeferredAction. An optional key is used to differentiate multiple component instances
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ data class DesignKeyEvent(val key: Char, val metaKeys: List<DesignMetaKey>) {
companion object {
// Construct a DesignKeyEvent from a list of javascript key codes
fun fromJsKeyCodes(jsKeyCodes: List<Byte>): DesignKeyEvent {
var metaKeys: ArrayList<DesignMetaKey> = arrayListOf()
var key: Char = '0'
val metaKeys: ArrayList<DesignMetaKey> = arrayListOf()
var key = '0'
jsKeyCodes
.map { it.toInt() }
.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package com.android.designcompose

open class FetchException() : RuntimeException()
open class FetchException : RuntimeException()

class AccessDeniedException : FetchException()

class FigmaFileNotFoundException() : FetchException()
class FigmaFileNotFoundException : FetchException()

class RateLimitedException() : FetchException()
class RateLimitedException : FetchException()

class InternalFigmaErrorException() : FetchException()
class InternalFigmaErrorException : FetchException()
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,22 @@ internal object VariableManager {

internal fun init(docId: DesignDocId, map: VariableMap) {

varMap = varMap.copy {
// Remove old entries for docId
val oldVarMap = docVarMap[docId.id]
oldVarMap?.collectionsMap?.forEach { this.collections.remove(it.key) }
oldVarMap?.collectionNameMapMap?.forEach { this.collectionNameMap.remove(it.key) }
oldVarMap?.variablesMap?.forEach { this.variables.remove(it.key) }
oldVarMap?.variableNameMapMap?.forEach { this.variableNameMap.remove(it.key) }

// Add new entries for docId
docVarMap[docId.id] = map
this.collections.putAll(map.collectionsMap)
this.collectionNameMap.putAll(map.collectionNameMapMap)
this.variables.putAll(map.variablesMap)
this.variableNameMap.putAll(map.variableNameMapMap)
}
varMap =
varMap.copy {
// Remove old entries for docId
val oldVarMap = docVarMap[docId.id]
oldVarMap?.collectionsMap?.forEach { this.collections.remove(it.key) }
oldVarMap?.collectionNameMapMap?.forEach { this.collectionNameMap.remove(it.key) }
oldVarMap?.variablesMap?.forEach { this.variables.remove(it.key) }
oldVarMap?.variableNameMapMap?.forEach { this.variableNameMap.remove(it.key) }

// Add new entries for docId
docVarMap[docId.id] = map
this.collections.putAll(map.collectionsMap)
this.collectionNameMap.putAll(map.collectionNameMapMap)
this.variables.putAll(map.variablesMap)
this.variableNameMap.putAll(map.variableNameMapMap)
}
currentDocId = docId
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ private fun updateLayoutTree(
if (updateLayoutChildren)
layoutParentChildren.add(
layoutParentChildren {
layoutId
layoutChildren
this.parentLayoutId = layoutId
this.childLayoutIds.addAll(layoutChildren)
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ internal fun Modifier.squooshRender(
fun renderNode(node: SquooshResolvedNode, parentVariableState: VariableState) {
// If there is no programmatic mode override and this node has explicitly set
// mode values, update variablestate with these values
val variableState =
val newVariableState =
if (!hasModeOverride && node.view.explicitVariableModesMap.isNotEmpty()) {
val explicitModeValues = node.view.explicitVariableModesMap
parentVariableState.copyWithModeValues(explicitModeValues)
Expand Down Expand Up @@ -134,7 +134,7 @@ internal fun Modifier.squooshRender(
computedLayout,
customizations,
node.view.name,
variableState,
newVariableState,
appContext = appContext,
)
nodeRenderCount++
Expand Down Expand Up @@ -182,7 +182,7 @@ internal fun Modifier.squooshRender(
shape,
document,
customizations,
variableState,
newVariableState,
computedPathCache,
appContext,
) {
Expand All @@ -202,7 +202,7 @@ internal fun Modifier.squooshRender(
pendingMask.computedLayout!!.left * density,
pendingMask.computedLayout!!.top * density,
) {
renderNode(pendingMask!!, variableState)
renderNode(pendingMask!!, newVariableState)
}

drawContext.canvas.restore()
Expand All @@ -228,7 +228,7 @@ internal fun Modifier.squooshRender(
childLayout.left * density,
childLayout.top * density,
) {
renderNode(child!!, variableState)
renderNode(child!!, newVariableState)
}
}
child = child.nextSibling
Expand All @@ -247,7 +247,7 @@ internal fun Modifier.squooshRender(
pendingMask.computedLayout!!.left * density,
pendingMask.computedLayout!!.top * density,
) {
renderNode(pendingMask, variableState)
renderNode(pendingMask, newVariableState)
}

drawContext.canvas.restore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,23 @@ internal fun squooshComputeTextInfo(
for (run in getTextContent(appContext, v.data.styledText)) {
val style = run.styleOrNull!!
val textBrushAndOpacity =
style.textColorOrNull!!
.asBrush(appContext, document, density.density, variableState)
val fontWeight =
style.fontWeightOrNull!!
.weight
.getValue(variableState)
style.textColorOrNull!!.asBrush(
appContext,
document,
density.density,
variableState,
)
val fontWeight = style.fontWeightOrNull!!.weight.getValue(variableState)
builder.pushStyle(
(SpanStyle(
brush = textBrushAndOpacity?.first,
alpha = textBrushAndOpacity?.second ?: 1.0f,
fontSize =
style.fontSizeOrNull!!
.getValue(variableState)
.sp,
fontSize = style.fontSizeOrNull!!.getValue(variableState).sp,
fontWeight = FontWeight(fontWeight.roundToInt()),
fontStyle =
when (style.fontStyle) {
com.android.designcompose.definition.element.FontStyle.FONT_STYLE_ITALIC -> FontStyle.Italic
com.android.designcompose.definition.element.FontStyle
.FONT_STYLE_ITALIC -> FontStyle.Italic
else -> FontStyle.Normal
},
fontFamily =
Expand All @@ -192,7 +191,7 @@ internal fun squooshComputeTextInfo(
else -> androidx.compose.ui.text.style.TextDecoration.None
},
// platformStyle = PlatformSpanStyle(includeFontPadding = false),
)),
))
)
builder.append(run.text)
builder.pop()
Expand Down
Loading

0 comments on commit fde2c87

Please sign in to comment.