-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fullscreen mode, set safe drawing area, handle taps
- Loading branch information
Showing
31 changed files
with
462 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
readium/navigators/demo/src/main/java/org/readium/navigator/demo/DemoReader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright 2024 Readium Foundation. All rights reserved. | ||
* Use of this source code is governed by the BSD-style license | ||
* available in the top-level LICENSE file of the project. | ||
*/ | ||
|
||
package org.readium.navigator.demo | ||
|
||
import androidx.compose.animation.AnimatedVisibility | ||
import androidx.compose.animation.fadeIn | ||
import androidx.compose.animation.fadeOut | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Settings | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.ModalBottomSheet | ||
import androidx.compose.material3.TopAppBar | ||
import androidx.compose.material3.rememberModalBottomSheetState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.zIndex | ||
import org.readium.navigator.demo.preferences.UserPreferences | ||
import org.readium.navigator.web.PrepaginatedWebNavigator | ||
import org.readium.r2.shared.ExperimentalReadiumApi | ||
|
||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalReadiumApi::class) | ||
@Composable | ||
fun Reader( | ||
state: DemoViewModel.State.Reader, | ||
fullScreenState: MutableState<Boolean> | ||
) { | ||
val showPreferences = remember { mutableStateOf(false) } | ||
val preferencesSheetState = rememberModalBottomSheetState() | ||
|
||
if (showPreferences.value) { | ||
ModalBottomSheet( | ||
sheetState = preferencesSheetState, | ||
onDismissRequest = { showPreferences.value = false } | ||
) { | ||
UserPreferences( | ||
model = state.preferencesViewModel, | ||
title = "Preferences" | ||
) | ||
} | ||
} | ||
|
||
Box { | ||
TopBar( | ||
modifier = Modifier.zIndex(1f), | ||
visible = !fullScreenState.value, | ||
onPreferencesActivated = { showPreferences.value = !showPreferences.value } | ||
) | ||
|
||
PrepaginatedWebNavigator( | ||
modifier = Modifier.fillMaxSize(), | ||
state = state.navigatorState, | ||
onTap = { fullScreenState.value = !fullScreenState.value; true } | ||
) | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
private fun TopBar( | ||
modifier: Modifier, | ||
visible: Boolean, | ||
onPreferencesActivated: () -> Unit | ||
) { | ||
AnimatedVisibility( | ||
modifier = modifier, | ||
visible = visible, | ||
enter = fadeIn(), | ||
exit = fadeOut() | ||
) { | ||
TopAppBar( | ||
title = {}, | ||
actions = { | ||
IconButton( | ||
onClick = onPreferencesActivated | ||
) { | ||
Icon( | ||
imageVector = Icons.Filled.Settings, | ||
contentDescription = "Preferences" | ||
) | ||
} | ||
} | ||
) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
readium/navigators/demo/src/main/java/org/readium/navigator/demo/util/Fullscreenable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.readium.navigator.demo.util | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.State | ||
import androidx.core.view.WindowInsetsCompat | ||
import androidx.core.view.WindowInsetsControllerCompat | ||
|
||
@Composable | ||
fun Fullscreenable( | ||
fullscreenState: State<Boolean>, | ||
insetsController: WindowInsetsControllerCompat, | ||
content: @Composable () -> Unit | ||
) { | ||
insetsController.systemBarsBehavior = | ||
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE | ||
|
||
LaunchedEffect(fullscreenState.value) { | ||
if (fullscreenState.value) { | ||
insetsController.hide(WindowInsetsCompat.Type.systemBars()) | ||
} else { | ||
insetsController.show(WindowInsetsCompat.Type.systemBars()) | ||
} | ||
} | ||
|
||
content.invoke() | ||
} |
2 changes: 1 addition & 1 deletion
2
readium/navigators/web/scripts/dist/prepaginated-double-script.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.