Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into BPKR-215_Android_Graphic_p…
Browse files Browse the repository at this point in the history
…romo_contribution
  • Loading branch information
Saidu Ernest Kamara committed Sep 19, 2023
2 parents 260388f + 363d562 commit 4486279
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ open class BpkBottomNav @JvmOverloads constructor(
Menu.NONE,
id,
menu.size(),
SpannableStringBuilder().append(title, fontSpan, Spannable.SPAN_INCLUSIVE_INCLUSIVE),
wrapFontSpan(title),
)
.setIcon(icon)

Expand Down Expand Up @@ -100,6 +100,13 @@ open class BpkBottomNav @JvmOverloads constructor(
throw UnsupportedOperationException("Not supported")
}

private fun wrapFontSpan(text: CharSequence): CharSequence =
if (resources.configuration.layoutDirection == LAYOUT_DIRECTION_LTR) {
SpannableStringBuilder().append(text, fontSpan, Spannable.SPAN_INCLUSIVE_INCLUSIVE)
} else {
text
}

private class ListenersDelegate(
private val menu: Menu,
) : OnItemSelectedListener, OnItemReselectedListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ class BpkCircleSkeleton @JvmOverloads constructor(
super.onLayout(changed, 0, 0, internalSize, internalSize)
}

override fun onDraw(canvas: Canvas?) {
override fun onDraw(canvas: Canvas) {
val internalSize = getInternalSize()
val radius = internalSize.toFloat().div(2)
canvas?.drawCircle(radius, radius, radius, paint)
canvas.drawCircle(radius, radius, radius, paint)
}

private companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ class BpkHeadlineSkeleton @JvmOverloads constructor(
setMeasuredDimension(widthMeasureSpec, heightSize)
}

override fun onDraw(canvas: Canvas?) {
override fun onDraw(canvas: Canvas) {
val borderRadius = context.resources.getDimensionPixelSize(R.dimen.bpkBorderRadiusXs)
canvas?.drawRoundRect(0f, 0f, width.toFloat(), height.toFloat(), borderRadius.toFloat(), borderRadius.toFloat(), paint)
canvas.drawRoundRect(0f, 0f, width.toFloat(), height.toFloat(), borderRadius.toFloat(), borderRadius.toFloat(), paint)
}

private companion object {
Expand Down
2 changes: 1 addition & 1 deletion android-configuration.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

android {
compileSdk 33
compileSdk 34

defaultConfig {
minSdkVersion 28
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package net.skyscanner.backpack.compose.barchart.internal

import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedContentScope
import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.ContentTransform
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.fadeIn
Expand Down Expand Up @@ -62,14 +62,14 @@ internal fun BarChartTitle(
when (scrollingDirection) {
ScrollingDirection.Forward ->
ContentTransform(
targetContentEnter = fadeIn() + slideIntoContainer(AnimatedContentScope.SlideDirection.Start),
initialContentExit = fadeOut() + slideOutOfContainer(AnimatedContentScope.SlideDirection.Start),
targetContentEnter = fadeIn() + slideIntoContainer(AnimatedContentTransitionScope.SlideDirection.Start),
initialContentExit = fadeOut() + slideOutOfContainer(AnimatedContentTransitionScope.SlideDirection.Start),
)

ScrollingDirection.Backward ->
ContentTransform(
targetContentEnter = fadeIn() + slideIntoContainer(AnimatedContentScope.SlideDirection.End),
initialContentExit = fadeOut() + slideOutOfContainer(AnimatedContentScope.SlideDirection.End),
targetContentEnter = fadeIn() + slideIntoContainer(AnimatedContentTransitionScope.SlideDirection.End),
initialContentExit = fadeOut() + slideOutOfContainer(AnimatedContentTransitionScope.SlideDirection.End),
)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ fun BpkCarousel(
modifier = Modifier
.testTag("pager")
.fillMaxSize(),
pageCount = if (internalState.pageCount > 1) Int.MAX_VALUE else 1, // if count > 1, set to Int.MAX_VALUE for infinite looping
state = internalState.delegate,
) {
content(internalState.getModdedPageNumber(it, internalState.pageCount))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.gestures.ScrollableState
import androidx.compose.foundation.interaction.InteractionSource
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.listSaver
import androidx.compose.runtime.saveable.rememberSaveable

sealed interface BpkCarouselState : ScrollableState {

Expand Down Expand Up @@ -58,7 +60,14 @@ fun rememberBpkCarouselState(
initialImage: Int = 0,
): BpkCarouselState {
val initialPage = (Int.MAX_VALUE / 2) + initialImage
val pagerState = rememberPagerState(initialPage = initialPage)

val pagerState = rememberSaveable(saver = InfinitePagerState.Saver) {
InfinitePagerState(
initialPage,
totalImages,
)
}

return remember(pagerState, totalImages) {
BpkCarouselInternalState(delegate = pagerState, totalImages = totalImages)
}
Expand All @@ -70,7 +79,10 @@ fun BpkCarouselState(
initialImage: Int = 0,
): BpkCarouselState {
val initialPage = (Int.MAX_VALUE / 2) + initialImage
return BpkCarouselInternalState(delegate = PagerState(initialPage = initialPage), totalImages = totalImages)
return BpkCarouselInternalState(
delegate = InfinitePagerState(initialPage = initialPage, totalPages = totalImages),
totalImages = totalImages,
)
}

internal fun BpkCarouselState.asInternalState(): BpkCarouselInternalState =
Expand All @@ -79,7 +91,7 @@ internal fun BpkCarouselState.asInternalState(): BpkCarouselInternalState =
}

@OptIn(ExperimentalFoundationApi::class)
internal class BpkCarouselInternalState constructor(
internal class BpkCarouselInternalState(
val delegate: PagerState,
val totalImages: Int,
) : BpkCarouselState, ScrollableState by delegate {
Expand Down Expand Up @@ -113,3 +125,31 @@ internal class BpkCarouselInternalState constructor(
else -> this - floorDiv(other) * other
}
}

@OptIn(ExperimentalFoundationApi::class)
private class InfinitePagerState(
initialPage: Int,
private val totalPages: Int,
) : PagerState(initialPage, initialPageOffsetFraction = 0f) {

override val pageCount: Int
// if count > 1, set to Int.MAX_VALUE for infinite looping
get() = if (totalPages > 1) Int.MAX_VALUE else 1

companion object {
val Saver: Saver<InfinitePagerState, *> = listSaver(
save = {
listOf(
it.currentPage,
it.totalPages,
)
},
restore = {
InfinitePagerState(
initialPage = it[0],
totalPages = it[1],
)
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package net.skyscanner.backpack.compose.floatingnotification.internal

import androidx.compose.animation.AnimatedContentScope
import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.ContentTransform
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.core.tween
Expand Down Expand Up @@ -100,7 +100,7 @@ internal fun BpkFloatingNotificationImpl(
@Composable
internal fun floatingNotificationTransforms(
slideDistancePx: Int,
): AnimatedContentScope<BpkFloatingNotificationData?>.() -> ContentTransform =
): AnimatedContentTransitionScope<BpkFloatingNotificationData?>.() -> ContentTransform =
{
ContentTransform(
targetContentEnter = fadeIn(tween(TRANSITION_DURATION)) + slideInVertically(tween(TRANSITION_DURATION)) { slideDistancePx },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal fun BpkSelectImpl(
onSelectionChange: ((selectedIndex: Int) -> Unit)? = null,
) {
var expanded by remember { mutableStateOf(false) }
val selectText = if (selectedIndex != null && selectedIndex > -1 && options.size >= selectedIndex) options[selectedIndex] else ""
val selectText = selectedIndex?.let { options.getOrNull(selectedIndex) } ?: ""

ExposedDropdownMenuBox(
expanded = expanded,
Expand All @@ -72,16 +72,27 @@ internal fun BpkSelectImpl(
)
ExposedDropdownMenu(
expanded = if (status != BpkFieldStatus.Disabled) expanded else false,
modifier = Modifier.background(BpkTheme.colors.surfaceDefault).fillMaxWidth(),
modifier = Modifier
.background(BpkTheme.colors.surfaceDefault)
.fillMaxWidth(),
onDismissRequest = { expanded = false },
) {
options.forEachIndexed { index, option ->
val itemBackgroundColor = if (index == selectedIndex) BpkTheme.colors.surfaceHighlight else BpkTheme.colors.surfaceDefault
val itemBackgroundColor =
if (index == selectedIndex) BpkTheme.colors.surfaceHighlight else BpkTheme.colors.surfaceDefault
DropdownMenuItem(
modifier = Modifier
.height(BpkSpacing.Lg.times(2))
.background(itemBackgroundColor),
text = { BpkText(text = option, color = BpkTheme.colors.textPrimary, maxLines = 1, overflow = TextOverflow.Ellipsis) },
text = {
BpkText(
text = option,
color = BpkTheme.colors.textPrimary,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = BpkTheme.typography.label1,
)
},
onClick = {
expanded = false
if (index != selectedIndex) {
Expand All @@ -104,10 +115,12 @@ internal fun BpkSelectImpl(
onClick: (() -> Unit)? = null,
) {
BpkTextFieldImpl(
modifier = if (status == BpkFieldStatus.Disabled) modifier else modifier.clickable(bounded = true, role = Role.Button) {
onClick?.let {
it()
} },
modifier = if (status == BpkFieldStatus.Disabled) modifier else modifier.clickable(
bounded = true,
role = Role.Button,
) {
onClick?.let { it() }
},
value = text,
onValueChange = {},
readOnly = true,
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ plugin-nexusPublishing = "io.github.gradle-nexus:publish-plugin:1.3.0"
plugin-detekt = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" }
plugin-ksp = { module = "com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin", version.ref = "ksp" }

detektRules-compose = "io.nlopez.compose.rules:detekt:0.2.1"
detektRules-compose = "io.nlopez.compose.rules:detekt:0.2.2"
detektRules-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" }
detektRules-libraries = { module = "io.gitlab.arturbosch.detekt:detekt-rules-libraries", version.ref = "detekt" }

Expand Down Expand Up @@ -62,7 +62,7 @@ test-compose = { group = "androidx.compose.ui", name = "ui-test-junit4" }

google-material = "com.google.android.material:material:1.9.0"
google-maps = "com.google.android.gms:play-services-maps:18.1.0"
google-mapsCompose = "com.google.maps.android:maps-compose:2.14.0"
google-mapsCompose = "com.google.maps.android:maps-compose:2.14.1"
google-kspApi = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
google-guava = "com.google.guava:guava:32.1.2-jre"

Expand All @@ -80,7 +80,7 @@ kotlin-compilerTestingKsp = { module = "com.github.tschuchortdev:kotlin-compile-
lint-lint = { module = "com.android.tools.lint:lint", version.ref = "lint" }
lint-api = { module = "com.android.tools.lint:lint-api", version.ref = "lint" }

compose-bom = { group = "androidx.compose", name = "compose-bom", version = "2023.06.01" }
compose-bom = { group = "androidx.compose", name = "compose-bom", version = "2023.09.00" }
compose-ui = { group = "androidx.compose.ui", name = "ui" }
compose-foundation = { group = "androidx.compose.foundation", name = "foundation" }
compose-runtime = { group = "androidx.compose.runtime", name = "runtime" }
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4486279

Please sign in to comment.