-
Notifications
You must be signed in to change notification settings - Fork 4
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
ANDROID-14792 Support Checkbox with Links for Compose implementation #400
base: main
Are you sure you want to change the base?
Conversation
📱 New catalog for testing generated: Download |
📱 New catalog for testing generated: Download |
compose_ui_version = "1.5.4" | ||
compose_ui_version = "1.7.6" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to the latest stable version in order to use the new withLink
method.
implementation "androidx.compose.material:material:$compose_ui_version" | ||
implementation("androidx.compose.material:material-icons-extended:$compose_ui_version") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some ComposeUI Icons used in Mística have been moved into a separated dependency, so I've just added the new one to support the already used Icons.
|
||
@OptIn(ExperimentalMaterialApi::class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New RippleTheme has been deprecated. So there's an error when compiling the App.
There is an official migration guide to replace RippleTheme: https://developer.android.com/develop/ui/compose/touch-input/user-interactions/migrate-indication-ripple#migrate-ripple-theme
The migration involves using ExperimentalMaterialApi classes.
@@ -1,11 +1,15 @@ | |||
@file:OptIn(ExperimentalMaterialApi::class) // Required for RippleConfiguration usage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 90% of the methods inside this class need use the new LocalRippleConfiguration
so I've added the OptIn annotation in the file level to avoid add the same annotation for each method.
@Composable | ||
private fun getMisticaRippleConfiguration(color: Color, alpha: RippleAlpha? = null) = | ||
RippleConfiguration(color, alpha ?: RippleDefaults.rippleAlpha(color, !isSystemInDarkTheme())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace deprecated RippleTheme into the new one recommended by Android, maintaining the previous configuration we had in Mistica.
Row(modifier = Modifier.toggleable( | ||
value = checked, | ||
onValueChange = onCheckedChange, | ||
role = Role.Checkbox | ||
)) { | ||
Checkbox( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the one of the two main changes: Apply Role.Checkbox to Row wrapper to improve component usability.
)) { | ||
Checkbox( | ||
checked = checked, | ||
onCheckedChange = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oncheckedChange is now handled here: https://github.com/Telefonica/mistica-android/pull/400/files#diff-f3463b3eedd33d85c4cfb17c6d000d0d19f8b035ad676630753bd23a47b59849R34
@@ -22,92 +22,51 @@ internal fun TextWithLinks( | |||
modifier: Modifier = Modifier, | |||
) { | |||
val textLinkColour = MisticaTheme.colors.textLink | |||
val linksText = remember { getAnnotatedLinksString(text = text, links = links, highlightColor = textLinkColour) } | |||
ClickableText( | |||
val linksText = remember { getAnnotatedLinksString(originalText = text, links = links, highlightColor = textLinkColour) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From here, you can see the second main change. The logic for creating the SpannableString has been redefined using the new withLink
method.
} | ||
} | ||
) = buildAnnotatedString { | ||
val linkMap = links.associateBy { it.link } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a map for faster link lookup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot of screenshot changes due to Ripple migration, no need to review them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great 👍
val (linkText, link) = linkEntry | ||
withLink( | ||
link = LinkAnnotation.Clickable( | ||
tag = TAG, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if TextLink should include a tag so that it has this "TextWithLinks" default value but it can be changed if needed for testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would be very useful specially when there are more than one link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done here: f85d561
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📱 New catalog for testing generated: Download |
🎟️ Jira ticket
ANDROID-14792
🥅 What's the goal?
Support Checkbox with Links for Compose implementation
🚧 How do we do it?
spannableString
withLink
method☑️ Checks
🧪 How can I test this?
Ripple effect still being the same after the migration
ripple_before.mp4
ripple_after.mp4
Demo of main change
demo_checkbox_with_links.mp4