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

KOA-4919 Add compose BpkDialog #1043

Merged
merged 5 commits into from
May 24, 2022
Merged

KOA-4919 Add compose BpkDialog #1043

merged 5 commits into from
May 24, 2022

Conversation

marianeum
Copy link
Contributor

Remember to include the following changes:

  • Component README.md
  • Tests
  • Docs (either update backpack-docs now, or create a follow up ticket)

If you are curious about how we review, please read through the code review guidelines

modifier = Modifier.padding(BpkSpacing.Base),
verticalArrangement = Arrangement.spacedBy(BpkSpacing.Base),
) {
var dialogShown by rememberSaveable { mutableStateOf<Dialog?>(null) }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is a good example for why we shouldn't handle the state within our component/decide how state is stored as it will depend on usage - some may also want to let the viewmodel handle the state etc - i'd rather focus on education around remember vs rememberSaveable than enforce it as essentially it isn't a state internal to the component - it's a state that decides if a component should exist or not

@marianeum marianeum force-pushed the KOA-4919-dialog branch 4 times, most recently from 84d3f1d to 8682de7 Compare May 20, 2022 14:26
}

when (dialogShown) {
Dialog.SuccessOneButton -> SuccessOneButtonDialogExample { dialogShown = null }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename it to showing dialogue type, and add an additional option for None? It'll make the code look cleaner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that'll make the creation of them more difficult as the enum is also there for the button creation

DialogButtons(buttons)
}
}
icon?.let { DialogIcon(icon = icon) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move this check inside DialogIcon?

}
}

private val IconShape = RoundedCornerShape(percent = 50)
Copy link
Contributor

Choose a reason for hiding this comment

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

CircleShape

Copy link
Contributor

@bvitaliyg bvitaliyg left a comment

Choose a reason for hiding this comment

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

Just few siggestions

}
}

private val CircleShape = RoundedCornerShape(percent = 50)
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a CircleShape in Material library you can use instead :)

@marianeum marianeum added the minor A new & backwards compatible feature/component label May 24, 2022
@marianeum marianeum marked this pull request as ready for review May 24, 2022 10:11
}
}

private fun record(content: @Composable () -> Unit) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

as dialogs are in a separate window we need to run the screenshot tests slightly different

}
}

composeTestRule.onNode(isDialog()).assertIsDisplayed()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need to add the assertion here to wait for the dialog to be shown

}

// we need this to be able to get the dialog root, rather than the window root
private fun getViewRoots(): List<ViewGroup> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

gotta love some reflection 😬

ViewScreenshot("Calendar 2 - Pre-selected range", "range", ::setupCalendar2),
ViewScreenshot("Calendar 2 - Day colours", "colored", ::setupCalendar2),
ViewScreenshot("Calendar 2 - Day labels", "labeled", ::setupCalendar2),
ViewScreenshot("Calendar - Default", "range") { setupCalendar() },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we now have a property passed through here for compose screenshots as they don't have the static api that the old view espresso tests use, so can't use the lambda API anymore

@@ -170,6 +178,10 @@ private fun setupDialog() {
Thread.sleep(50)
}

private fun setupComposeDialog(testRule: ComposeTestRule, dialog: ShownDialog) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

need to click the button for the dialog to show

title: String,
text: String,
confirmButton: DialogButton,
secondaryButton: DialogButton,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this enforces that if there's three buttons the secondary button is always set

}

@Composable
fun BpkDestructiveDialog(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the destructive dialog is not available with three buttons

icon = icon?.let { Dialog.Icon.Success(icon) },
title = title,
text = text,
buttons = listOfNotNull(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

externally we want to enforce the types of buttons & order, but internally we can be flexible to have a simpler API

Copy link
Member

@olliecurtis olliecurtis left a comment

Choose a reason for hiding this comment

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

LGTM!

@marianeum marianeum merged commit e385523 into main May 24, 2022
@marianeum marianeum deleted the KOA-4919-dialog branch May 24, 2022 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor A new & backwards compatible feature/component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants