Skip to content

Commit

Permalink
Fix super small previews when @Preview annotation doesn't specify wid…
Browse files Browse the repository at this point in the history
…th and height (#219)
  • Loading branch information
vinaygaba authored Feb 8, 2022
1 parent 54a16ec commit e1ae330
Show file tree
Hide file tree
Showing 24 changed files with 23 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
showkaseKDoc = "",
enclosingClass = [ShowkaseClass::class],
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun group_name(): Unit {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
showkaseKDoc = "",
enclosingClass = [WrapperClass::class],
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun group_name(): Unit {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
showkaseKDoc = "",
enclosingClass = [ShowkaseObject::class],
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun group_name(): Unit {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
showkaseKDoc = "",
enclosingClass = [WrapperObject::class],
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun group_name(): Unit {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
showkaseKDoc = "",
enclosingClass = [Composables::class],
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun group_name(): Unit {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
showkaseKDoc = "",
enclosingClass = [WrapperClass::class],
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun WrapperClass_TestComposable(): Unit {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
showkaseKDoc = "",
enclosingClass = [WrapperClass::class],
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun WrapperClass_TestComposable(): Unit {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
showkaseKDoc = "",
enclosingClass = [WrapperClass::class],
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun WrapperClass_TestComposable(): Unit {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
insideWrapperClass = false,
showkaseKDoc = "",
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun group1_name1(): Unit {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
insideWrapperClass = false,
showkaseKDoc = "",
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun group1_name1(): Unit {
}
Expand All @@ -32,9 +30,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
insideWrapperClass = false,
showkaseKDoc = "",
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun group1_name2(): Unit {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
enclosingClass = [WrapperClass::class],
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1,
previewParameterClass = [ParameterProvider::class]
)
public fun group_name(): Unit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public class TestShowkaseRootCodegen : ShowkaseProvider {
componentKey =
"""com.airbnb.android.showkase_processor_testing_com.airbnb.android.showkase_processor_testing.WrapperClass_group_name_null_$index""",
isDefaultStyle = false,
widthDp = -1,
heightDp = -1,
component = @Composable { WrapperClass.TestComposable(previewParam) }
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
insideWrapperClass = false,
showkaseKDoc = "",
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun group_name(): Unit {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class TestShowkaseRootCodegen : ShowkaseProvider {
componentKDoc = "",
componentKey = """com.airbnb.android.showkase_processor_testing_null_group_name_null""",
isDefaultStyle = false,
widthDp = -1,
heightDp = -1,
component = @Composable { TestComposable() })
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
insideWrapperClass = false,
showkaseKDoc = "",
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun group_name(): Unit {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
insideWrapperClass = false,
showkaseKDoc = "",
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun group_name(): Unit {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
showkaseKDoc = "",
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1,
previewParameterClass = [ParameterProvider::class]
)
public fun group_name(): Unit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
insideWrapperClass = false,
showkaseKDoc = "",
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun Default_Group_TestComposable(): Unit {
}
Expand All @@ -34,8 +32,6 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
showkaseKDoc = "",
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1,
previewParameterClass = [ParameterProvider::class]
)
public fun Default_Group_TestComposable2(): Unit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public class TestShowkaseRootCodegen : ShowkaseProvider {
componentKey =
"""com.airbnb.android.showkase_processor_testing_null_DefaultGroup_TestComposable_null""",
isDefaultStyle = false,
widthDp = -1,
heightDp = -1,
component = @Composable { TestComposable() })
).apply {
ParameterProvider().values.iterator().asSequence().forEachIndexed { index, previewParam ->
Expand All @@ -39,8 +37,6 @@ public class TestShowkaseRootCodegen : ShowkaseProvider {
componentKey =
"""com.airbnb.android.showkase_processor_testing_null_DefaultGroup_TestComposable2_null_$index""",
isDefaultStyle = false,
widthDp = -1,
heightDp = -1,
component = @Composable { TestComposable2(previewParam) }
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
insideWrapperClass = false,
showkaseKDoc = "",
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun Default_Group_TestComposable(): Unit {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public class TestShowkaseRootCodegen : ShowkaseProvider {
componentKey =
"""com.airbnb.android.showkase_processor_testing_null_DefaultGroup_TestComposable_null""",
isDefaultStyle = false,
widthDp = -1,
heightDp = -1,
component = @Composable { TestComposable() })
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
insideWrapperClass = false,
showkaseKDoc = "",
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun Default_Group_TestComposable(): Unit {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
showkaseKDoc = "",
enclosingClass = [WrapperClass::class],
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
showkaseWidthDp = -1,
showkaseHeightDp = -1
isDefaultStyle = false
)
public fun group_name(): Unit {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ internal fun getShowkaseMetadataFromPreview(
commonMetadata.enclosingClass,
)

val width = previewAnnotation.getAsInt("widthDp")
val height = previewAnnotation.getAsInt("heightDp")

return ShowkaseMetadata.Component(
packageSimpleName = commonMetadata.moduleName,
packageName = commonMetadata.packageName,
Expand All @@ -271,8 +274,8 @@ internal fun getShowkaseMetadataFromPreview(
showkaseKDoc = commonMetadata.kDoc,
showkaseName = showkaseName,
showkaseGroup = showkaseGroup,
showkaseWidthDp = previewAnnotation.getAsInt("widthDp"),
showkaseHeightDp = previewAnnotation.getAsInt("heightDp"),
showkaseWidthDp = if (width == -1) null else width,
showkaseHeightDp = if (height == -1) null else width,
insideWrapperClass = commonMetadata.showkaseFunctionType == ShowkaseFunctionType.INSIDE_CLASS,
insideObject = commonMetadata.showkaseFunctionType.insideObject(),
element = element,
Expand Down

0 comments on commit e1ae330

Please sign in to comment.