Skip to content

Commit

Permalink
feat: Make fontsize controls more granular
Browse files Browse the repository at this point in the history
Signed-off-by: starry-shivam <[email protected]>
  • Loading branch information
starry-shivam committed Oct 10, 2024
1 parent fbd93b2 commit 51b89d8
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 5 deletions.
71 changes: 71 additions & 0 deletions app/src/main/java/com/starry/myne/ui/common/CustomBottomSheet.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.starry.myne.ui.common

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.material3.BottomSheetDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.Dp

/**
* Custom Bottom Sheet. Fixes bugs with [ModalBottomSheet].
*
* @param modifier [Modifier].
* @param hasFixedHeight Whether the bottom sheet has fixed height passed through [modifier] or not.
* @param scrimColor Scrim color.
* @param shape Shape.
* @param containerColor Container color.
* @param onDismissRequest OnDismiss callback.
* @param dragHandle Drag Handle, pass null to disable.
* @param content Content inside [ModalBottomSheet]. Provides you navigation bar padding.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CustomBottomSheet(
modifier: Modifier = Modifier,
hasFixedHeight: Boolean = false,
scrimColor: Color = BottomSheetDefaults.ScrimColor,
shape: Shape = BottomSheetDefaults.ExpandedShape,
containerColor: Color = MaterialTheme.colorScheme.surfaceContainerLow,
onDismissRequest: () -> Unit,
dragHandle: @Composable (() -> Unit)? = { BottomSheetDefaults.DragHandle() },
content: @Composable ColumnScope.(navigationBarPadding: Dp) -> Unit
) {
val navigationBarPadding =
WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()

Box(Modifier.fillMaxSize()) {
ModalBottomSheet(
scrimColor = scrimColor,
dragHandle = dragHandle,
modifier = Modifier
.then(
if (hasFixedHeight) Modifier.align(Alignment.BottomCenter)
else Modifier
)
.fillMaxWidth()
.then(modifier),
onDismissRequest = {
onDismissRequest()
},
shape = shape,
sheetState = rememberModalBottomSheetState(true),
contentWindowInsets = { WindowInsets(0, 0, 0, 0) },
containerColor = containerColor
) {
content(navigationBarPadding)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private fun ChapterLazyItemItem(
val paragraphs = remember { chunkText(chapter.body) }

val targetFontSize = remember(state.fontSize) {
(state.fontSize / 10) * 1.8f
(state.fontSize / 5) * 0.9f
}

val fontSize by animateFloatAsState(
Expand All @@ -103,7 +103,7 @@ private fun ChapterLazyItemItem(
label = "fontSize"
)
val titleFontSize by animateFloatAsState(
targetValue = targetFontSize * 1.4f,
targetValue = targetFontSize * 1.35f,
animationSpec = tween(durationMillis = 300),
label = "titleFontSize"
)
Expand Down Expand Up @@ -202,7 +202,7 @@ private fun ChapterLazyItemItem(
modifier = Modifier.padding(start = 12.dp, end = 4.dp, top = 10.dp),
text = chapter.title,
fontSize = titleFontSize.sp,
lineHeight = 32.sp,
lineHeight = 1.3f.em,
fontFamily = pacificoFont,
fontWeight = FontWeight.Medium,
color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.88f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ private fun ReaderTextScaleButton(
val context = LocalContext.current
val (iconRes, adjustment) = remember(buttonType) {
when (buttonType) {
TextScaleButtonType.DECREASE -> Pair(R.drawable.ic_reader_text_minus, -10)
TextScaleButtonType.INCREASE -> Pair(R.drawable.ic_reader_text_plus, 10)
TextScaleButtonType.DECREASE -> Pair(R.drawable.ic_reader_text_minus, -5)
TextScaleButtonType.INCREASE -> Pair(R.drawable.ic_reader_text_plus, 5)
}
}

Expand Down

0 comments on commit 51b89d8

Please sign in to comment.