Skip to content

Commit

Permalink
Fix systembar borders & add back reader settings
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 b62d804 commit fcca32f
Show file tree
Hide file tree
Showing 18 changed files with 423 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

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

4 changes: 2 additions & 2 deletions .idea/deploymentTargetSelector.xml

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

1 change: 1 addition & 0 deletions .idea/gradle.xml

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

3 changes: 2 additions & 1 deletion .idea/misc.xml

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

13 changes: 13 additions & 0 deletions .idea/runConfigurations.xml

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

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ aboutLibraries {


dependencies {
def composeBom = platform('androidx.compose:compose-bom:2024.09.02')
def composeBom = platform('androidx.compose:compose-bom:2024.09.03')
implementation composeBom
androidTestImplementation composeBom

Expand All @@ -111,7 +111,7 @@ dependencies {
implementation "androidx.compose.runtime:runtime-livedata"
implementation "androidx.compose.material3:material3"
// Material icons.
implementation 'androidx.compose.material:material-icons-extended:1.7.2'
implementation 'androidx.compose.material:material-icons-extended:1.7.3'
// Material theme for main activity.
implementation 'com.google.android.material:material:1.12.0'
// Android 12+ splash API.
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
<activity
android:name=".ui.screens.reader.main.activities.ReaderActivity"
android:configChanges="orientation|screenSize|uiMode|locale|layoutDirection|screenLayout"
android:exported="true">
android:exported="true"
android:theme="@style/Theme.Myne.ReaderActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
Expand Down
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 @@ -79,7 +79,8 @@ fun MainScreen(
Scaffold(
bottomBar = {
BottomBar(navController = navController)
}, containerColor = MaterialTheme.colorScheme.background
},
containerColor = MaterialTheme.colorScheme.background,
) {
NavGraph(
startDestination = startDestination,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ class ReaderActivity : AppCompatActivity() {
ChaptersContent(
state = state,
lazyListState = lazyListState,
onToggleReaderMenu = {
viewModel.toggleReaderMenu()
toggleSystemBars(state.showReaderMenu)
}
onToggleReaderMenu = { viewModel.toggleReaderMenu() }
)

// Toggle system bars based on reader menu visibility.
LaunchedEffect(state.showReaderMenu) {
toggleSystemBars(state.showReaderMenu)
}
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ private fun ChapterLazyItemItem(
val context = LocalContext.current
val paragraphs = remember { chunkText(chapter.body) }

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

val fontSize by animateFloatAsState(
targetValue = targetFontSize,
animationSpec = tween(durationMillis = 300),
Expand Down
Loading

0 comments on commit fcca32f

Please sign in to comment.