Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make stacked preview annotations generate showkaseMetadata components for each annotation #259

Merged
merged 15 commits into from Sep 5, 2022

Conversation

oas004
Copy link
Contributor

@oas004 oas004 commented Aug 28, 2022

This is the next step in supporting Multipreview annotations. Referencing #255 as the first step.

Here I have added functionality to make a ShowkaseMetadata object for each Preview annotation. Eg.

@Preview(
    name = "small font",
    group = "font scales",
    fontScale = 0.5f
)
@Preview(
    name = "large font",
    group = "font scales",
    fontScale = 1.5f
)
@Composable
fun ComposablePreviewFont() {

}

Before, this would only make one component in Showkase. Now it should make one for each preview and place them in their respective group. Here they would both be placed in the group font scales

Furthermore, I would advice to review this by commit as I had to update the tests because of some arrangement due to a check in the processor. I placed the test update in 8371ec2.

I'm leaving this as a draft PR because I'm having some issues with getting this to work with KAPT.
With KSP, the method roundEnvironment.getElementsAnnotatedWith(PREVIEW_CLASS_NAME) returns all the elements for multi stacked preview. However, with KAPT, it does not seem to work the same way. Is there some other function I should use here? Any suggestions are more than welcome 😄
Added a slack post for anyone interested 😄

@oas004 oas004 force-pushed the feature/stacked-preview-annotation branch from 8371ec2 to ba69d50 Compare August 28, 2022 16:15
&& showkaseMetadata.componentIndex != null
&& showkaseMetadata.componentIndex > 0
) {
"${showkaseMetadata.showkaseGroup}_${showkaseMetadata.showkaseName}_${showkaseMetadata.componentIndex}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we were hoping for a better name but we can probably append componentIndex for now.

Copy link
Collaborator

@vinaygaba vinaygaba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking in good shape. You can do the ShowkaseComposable support later on as it's not super pressing. I think you are at a point where you can move to the custom annotation stuff we discussed previously. Great job in making such a critical feature happen 👏🏻

@oas004
Copy link
Contributor Author

oas004 commented Aug 31, 2022

This is looking in good shape. You can do the ShowkaseComposable support later on as it's not super pressing. I think you are at a point where you can move to the custom annotation stuff we discussed previously. Great job in making such a critical feature happen 👏🏻

Thank you very much @vinaygaba! And thank you so much valuable review 🙏 I tried to add support for stacked @ShowkaseComposable in b109238. I also wrote some docs about these not working with KAPT because of https://youtrack.jetbrains.com/issue/KT-49682 . Furthermore, added tests for only KSP for stacked @Preview and @ShowkaseComposable cases 😃

@oas004 oas004 marked this pull request as ready for review August 31, 2022 20:17
@vinaygaba
Copy link
Collaborator

@oas004 Amazing! One final thing you can do is write a test for the ShowkaseBrowser that verifies the following:

  • Stacked previews show up in the browser
  • They are being treated as separate previews

Add the test cases here - https://github.com/airbnb/Showkase/blob/master/showkase-browser-testing/src/androidTest/java/com/airbnb/android/showkase_browser_testing/ShowkaseBrowserTest.kt

@oas004
Copy link
Contributor Author

oas004 commented Aug 31, 2022

@oas004 Amazing! One final thing you can do is write a test for the ShowkaseBrowser that verifies the following:

  • Stacked previews show up in the browser
  • They are being treated as separate previews

Add the test cases here - https://github.com/airbnb/Showkase/blob/master/showkase-browser-testing/src/androidTest/java/com/airbnb/android/showkase_browser_testing/ShowkaseBrowserTest.kt

That is a very good idea! 🙌 Is there a way for us to bypass it in KAPT on CI? I think if I added those BrowserTests, then it will fail on KAPT every time 🤔

@vinaygaba
Copy link
Collaborator

@oas004 Oh no, you are right. We currently run these tests for both ksp and kapt and pass the PuseKsp flag from CLI. Is there a way to access this value in the test case somehow? If there is, we can always pass the test when it's kapt and run the test as usual when its ksp. This is how we run these tests - https://github.com/airbnb/Showkase/blob/master/.github/workflows/android.yml#L59

@vinaygaba
Copy link
Collaborator

vinaygaba commented Aug 31, 2022

@oas004 Can you try this - in the android.yml file, also add -DuseKsp=true and -DuseKsp=false and then try accessing them in the new test cases using System.getProperty("useKsp")

@oas004
Copy link
Contributor Author

oas004 commented Aug 31, 2022

@oas004 Can you try this - in the android.yml file, also add -DuseKsp=true and -DuseKsp=false and then try accessing them in the new test cases using System.getProperty("useKsp")

I think that can work! Will test this out first thing in the morning😊

@oas004
Copy link
Contributor Author

oas004 commented Sep 1, 2022

@vinaygaba Can we re-run the UI Tests? It didn't provide me a log to check if it worked or not 😅

@oas004
Copy link
Contributor Author

oas004 commented Sep 1, 2022

@vinaygaba Can we re-run the UI Tests? It didn't provide me a log to check if it worked or not 😅

it seems like it was failing on the screenshot tests 🤔 I think I might need to take that into account as well somehow 🤔

@oas004
Copy link
Contributor Author

oas004 commented Sep 1, 2022

It seems like the KAPT stage is working on all but one emulator and then fails, so I can't see the others that checks green to verify if the System.getProperty trick works. I can't get it to work locally either though, so maybe I could try to save the variable in the gradle file as well? Or would that just be dumb? 🤔

@oas004 oas004 force-pushed the feature/stacked-preview-annotation branch from 2b16ce2 to d165e7d Compare September 2, 2022 10:05
@@ -37,31 +36,54 @@ class ShowcaseBrowserTest {
}
)

// This will alter now since KSP supports stacked preview annotations and KAPT does not.
private val componentSize = if (System.getProperty("useKsp") == "true") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a more descriptive comment about why we are doing this. Along with link to the issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Added something in fb87f3c :) Does that look okay? :)

Copy link
Collaborator

@vinaygaba vinaygaba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very exciting! Thank you for your patience and getting this to the finish line 👏

@oas004
Copy link
Contributor Author

oas004 commented Sep 2, 2022

Very exciting! Thank you for your patience and getting this to the finish line 👏

This is supercool! I will start on the actual mutlipreview annotation as soon as possible! 😄 🤩 Thank you so much for your valuable input! 🙏 Feel like I am learning a lot from this! 😃 😍

@oas004 oas004 force-pushed the feature/stacked-preview-annotation branch from 58a6ac2 to 84315b7 Compare September 3, 2022 21:27
@oas004 oas004 force-pushed the feature/stacked-preview-annotation branch from 8d57459 to fbf680a Compare September 4, 2022 20:01
Copy link
Collaborator

@vinaygaba vinaygaba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we have everything covered at this point 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants