Skip to content

Commit

Permalink
Remove Accompanist lib (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandregpereira authored Feb 11, 2024
1 parent d60b5e9 commit 74d142c
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.lerp
import br.alexandregpereira.hunter.app.BottomBarItem
import br.alexandregpereira.hunter.ui.theme.HunterTheme
import br.alexandregpereira.hunter.ui.util.BottomNavigationHeight
import kotlin.math.roundToInt

@Composable
Expand All @@ -88,7 +89,8 @@ fun BoxScope.AppBottomNavigation(
BottomNavigation(
backgroundColor = MaterialTheme.colors.surface,
elevation = 0.dp,
modifier = Modifier.height(56.dp + paddingBottom).padding(bottom = paddingBottom)
modifier = Modifier.height(BottomNavigationHeight + paddingBottom)
.padding(bottom = paddingBottom)
) {
BottomBarItem.entries.forEach { bottomBarItem ->
AppBottomNavigationItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import br.alexandregpereira.hunter.monster.registration.MonsterRegistrationFeatu
import br.alexandregpereira.hunter.spell.compendium.SpellCompendiumFeature
import br.alexandregpereira.hunter.spell.detail.SpellDetailFeature
import br.alexandregpereira.hunter.sync.SyncFeature
import br.alexandregpereira.hunter.ui.util.BottomNavigationHeight

@Composable
fun MainScreen(
Expand All @@ -44,7 +45,8 @@ fun MainScreen(
) {
Box {
val bottomBarNavigationSize by animateDpAsState(
targetValue = if (state.showBottomBar) 56.dp else 0.dp, label = "bottomBarNavigationSize"
targetValue = if (state.showBottomBar) BottomNavigationHeight else 0.dp,
label = "bottomBarNavigationSize",
)
val contentPaddingWithBottomBar = PaddingValues(
top = contentPadding.calculateTopPadding(),
Expand Down
1 change: 0 additions & 1 deletion feature/monster-compendium/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ dependencies {
implementation libs.bundles.viewmodel.bundle

implementation libs.bundles.compose
implementation libs.accompanist.flowlayout

implementation libs.koin.compose

Expand Down
3 changes: 1 addition & 2 deletions feature/monster-detail/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ android {

kotlinOptions {
freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
freeCompilerArgs += "-opt-in=androidx.compose.foundation.layout.ExperimentalLayoutApi"
}

buildFeatures {
Expand Down Expand Up @@ -48,8 +49,6 @@ dependencies {

implementation libs.bundles.compose
implementation libs.compose.util
implementation libs.accompanist.flowlayout
implementation libs.accompanist.pager
implementation libs.coil.compose

implementation libs.koin.compose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun AbilityScore(
contentDescription = stringResource(id = abilityScore.type.stringRes),
modifier = Modifier
.width(69.dp)
.height(89.dp)
.height(88.dp)
)

Column(
Expand All @@ -76,8 +76,7 @@ fun AbilityScore(
Text(
text = abilityScoreModifier,
fontWeight = FontWeight.Normal,
fontSize = 12.sp,
modifier = Modifier.padding(top = 1.dp)
fontSize = 16.sp,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private fun ActionDamageGrid(
painter = painterResource(iconRes),
iconColor = damageDice.damage.type.getIconColor(),
iconAlpha = 1f,
iconSize = iconSize
iconSize = iconSize,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package br.alexandregpereira.hunter.detail.ui

import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
Expand Down Expand Up @@ -43,7 +44,8 @@ private fun ConditionGrid(
val iconRes = condition.type.iconRes
IconInfo(
title = condition.name,
painter = painterResource(iconRes)
painter = painterResource(iconRes),
modifier = Modifier.width(GridItemWidth)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package br.alexandregpereira.hunter.detail.ui

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.LocalContentAlpha
import androidx.compose.material.LocalContentColor
import androidx.compose.material.Text
Expand Down Expand Up @@ -80,7 +81,8 @@ fun DamageGrid(
title = damage.name,
painter = painterResource(iconRes),
iconColor = damage.type.getIconColor(),
iconAlpha = 1f
iconAlpha = 1f,
modifier = Modifier.width(GridItemWidth)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,48 @@

package br.alexandregpereira.hunter.detail.ui

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.FlowRowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import com.google.accompanist.flowlayout.FlowMainAxisAlignment
import com.google.accompanist.flowlayout.FlowRow
import com.google.accompanist.flowlayout.SizeMode
import kotlin.math.roundToInt

@Composable
fun Grid(
modifier: Modifier = Modifier,
content: @Composable () -> Unit
content: @Composable FlowRowScope.() -> Unit
) = FlowRow(
modifier.fillMaxWidth(),
mainAxisSize = SizeMode.Wrap,
mainAxisAlignment = FlowMainAxisAlignment.SpaceEvenly,
mainAxisSpacing = 16.dp,
crossAxisSpacing = 24.dp,
horizontalArrangement = GridArrangementHorizontal(),
verticalArrangement = Arrangement.spacedBy(24.dp, Alignment.Top),
content = content
)

internal val GridItemWidth = 120.dp

private class GridArrangementHorizontal : Arrangement.Horizontal {

override val spacing: Dp = 8.dp

override fun Density.arrange(
totalSize: Int,
sizes: IntArray,
layoutDirection: LayoutDirection,
outPositions: IntArray
) {
val consumedSize = sizes.fold(0) { a, b -> a + b }
val gapSize = ((totalSize - consumedSize).toFloat() / (sizes.size + 1))
var current = gapSize
sizes.forEachIndexed { index, it ->
outPositions[index] = current.roundToInt()
current += it.toFloat() + gapSize
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package br.alexandregpereira.hunter.detail.ui

import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

Expand All @@ -34,6 +35,10 @@ private fun ProficiencyGrid(
) = Grid {

proficiencies.forEach { proficiency ->
Bonus(value = proficiency.modifier, name = proficiency.name)
Bonus(
value = proficiency.modifier,
name = proficiency.name,
modifier = Modifier.width(GridItemWidth),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,16 @@
<!--
~ Copyright 2022 Alexandre Gomes Pereira
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="69dp"
android:height="89dp"
android:height="88dp"
android:viewportWidth="69"
android:viewportHeight="89">
android:viewportHeight="88">
<path
android:pathData="M56,1H12.5C11.185,7.542 8.518,9.724 1,11.5V67c1.235,4.972 3.385,6.505 7.5,9h9c5.293,7.476 8.944,9.774 16.5,11 8.622,-1.027 12.615,-2.867 16.5,-11h10c4.518,-2.738 6.025,-4.725 7,-9V11.5C60.302,9.86 57.698,7.639 56,1z"
android:pathData="M56,1H12.5C11.185,7.542 8.518,9.724 1,11.5V67c1.235,4.972 3.385,6.505 7.5,9h9c5.293,7.476 8.944,9.774 16.5,11 8.622,-1.027 12.615,-2.867 16.5,-11h10c4.518,-2.738 6.025,-4.725 7,-9V11.5C60.302,9.86 57.698,7.639 56,1Z"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#000000"/>
<path
android:strokeWidth="1"
android:pathData="M53.143,5H15.857C14.73,10.933 12.444,12.913 6,14.523v50.338c1.059,4.509 2.902,5.9 6.429,8.162h7.714c4.536,6.78 7.666,8.865 14.143,9.977 7.39,-0.932 10.813,-2.6 14.143,-9.977H57c3.872,-2.483 5.165,-4.286 6,-8.162V14.523c-6.17,-1.486 -8.401,-3.502 -9.857,-9.523z"
android:fillColor="#00000000"
android:strokeColor="#000000"/>
<path
android:strokeWidth="1"
android:pathData="M34,61.5c-7.624,1.102 -11.129,3.432 -13.5,10.5 3.644,7.546 6.706,10.134 13.5,11 7.95,-1.395 11.405,-3.363 14,-11 -1.453,-6.58 -4.274,-9.023 -14,-10.5z"
android:pathData="M53.143,5H15.857C14.73,10.933 12.444,12.913 6,14.523v50.338c1.059,4.509 2.902,5.9 6.429,8.162h7.714c4.536,6.78 7.666,8.865 14.143,9.977 7.39,-0.932 10.813,-2.6 14.143,-9.977H57c3.872,-2.483 5.165,-4.286 6,-8.162V14.523c-6.17,-1.486 -8.401,-3.502 -9.857,-9.523Z"
android:fillColor="#00000000"
android:strokeColor="#000000"/>
</vector>
4 changes: 0 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[versions]
accompanist = "0.30.1"
android_gradle_plugin = "8.2.2"
appcompat = "1.6.1"
arch_core_testing = "2.2.0"
Expand Down Expand Up @@ -31,9 +30,6 @@ okhttp3_logging_interceptor = "4.12.0"
sqldelight = "1.5.5"

[libraries]
accompanist-flowlayout = { module = "com.google.accompanist:accompanist-flowlayout", version.ref = "accompanist" }
accompanist-insets = { module = "com.google.accompanist:accompanist-insets", version.ref = "accompanist" }
accompanist-pager = { module = "com.google.accompanist:accompanist-pager", version.ref = "accompanist" }
appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil_compose" }
compose-activity = { module = "androidx.activity:activity-compose", version.ref = "compose_activity" }
Expand Down
4 changes: 1 addition & 3 deletions ui/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ android {

kotlinOptions {
freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
freeCompilerArgs += "-opt-in=androidx.compose.foundation.layout.ExperimentalLayoutApi"
}

buildFeatures {
Expand All @@ -37,9 +38,6 @@ dependencies {
implementation libs.compose.util
implementation libs.kotlin.reflect
implementation libs.coil.compose
implementation libs.accompanist.pager
implementation libs.accompanist.insets
implementation libs.accompanist.flowlayout

androidTestImplementation libs.bundles.instrumentedtest
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import androidx.compose.foundation.Indication
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
Expand Down Expand Up @@ -58,11 +60,9 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import br.alexandregpereira.hunter.ui.compose.tablecontent.TableContentItemTypeState.BODY
import br.alexandregpereira.hunter.ui.compose.noIndicationClick
import br.alexandregpereira.hunter.ui.compose.tablecontent.TableContentItemTypeState.BODY
import br.alexandregpereira.hunter.ui.theme.HunterTheme
import com.google.accompanist.flowlayout.FlowRow
import com.google.accompanist.flowlayout.SizeMode
import kotlin.math.ln

@Composable
Expand Down Expand Up @@ -214,9 +214,8 @@ private fun AlphabetGrid(
onAlphabetIndexClicked: (Int) -> Unit,
modifier: Modifier = Modifier,
) = FlowRow(
mainAxisSize = SizeMode.Wrap,
mainAxisSpacing = 16.dp,
crossAxisSpacing = 16.dp,
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start),
verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.Top),
modifier = modifier
) {
alphabet.forEachIndexed { index, letter ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import androidx.compose.ui.composed
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.util.lerp
import dev.chrisbanes.snapper.ExperimentalSnapperApi
import kotlin.math.absoluteValue

@OptIn(ExperimentalFoundationApi::class)
Expand Down Expand Up @@ -90,7 +89,7 @@ fun <Data> HorizontalSlideTransition(
}
}

@OptIn(ExperimentalFoundationApi::class, ExperimentalSnapperApi::class)
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun <Data> Transition(
dataList: List<Data>,
Expand All @@ -108,13 +107,13 @@ fun <Data> Transition(
content(
transitionData.data,
{ transitionData.fraction },
isTarget = false
false
)
if (transitionData.data != transitionData.nextData) {
content(
transitionData.nextData,
{ transitionData.fraction },
isTarget = true
true
)
}
}
Expand Down
27 changes: 14 additions & 13 deletions ui/core/src/main/kotlin/br/alexandregpereira/hunter/ui/util/View.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package br.alexandregpereira.hunter.ui.util

import android.content.Context
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.systemBars
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp
import com.google.accompanist.insets.LocalWindowInsets
import com.google.accompanist.insets.ProvideWindowInsets

fun Context.createComposeView(
withBottomBar: Boolean = false,
Expand All @@ -39,17 +39,18 @@ fun ComposeView.setContentWithPadding(
content: @Composable (PaddingValues) -> Unit
) {
setContent {
val bottomBarNavigationSize = if (withBottomBar) 58.dp else 0.dp
ProvideWindowInsets {
val insets = LocalWindowInsets.current
val top = with(LocalDensity.current) { insets.systemBars.top.toDp() }
val bottom = with(LocalDensity.current) { insets.systemBars.bottom.toDp() }
content(
PaddingValues(
top = top,
bottom = bottom + bottomBarNavigationSize
)
val bottomBarNavigationSize = if (withBottomBar) BottomNavigationHeight else 0.dp
val insets = WindowInsets.systemBars
val density = LocalDensity.current
val top = with(density) { insets.getTop(this).toDp() }
val bottom = with(density) { insets.getBottom(this).toDp() }
content(
PaddingValues(
top = top,
bottom = bottom + bottomBarNavigationSize
)
}
)
}
}

val BottomNavigationHeight = 56.dp

0 comments on commit 74d142c

Please sign in to comment.