🚀 Horizontal gesture "Pull animation" option
* Enables or disables pull animation when using horizontal gesture
This commit is contained in:
parent
1c0e259179
commit
e4cc80ab08
14 changed files with 90 additions and 1 deletions
|
|
@ -51,6 +51,7 @@ object DataStoreConstants {
|
|||
val HORIZONTAL_GESTURE_SCROLL = doublePreferencesKey("horizontal_gesture_scroll")
|
||||
val HORIZONTAL_GESTURE_SENSITIVITY = doublePreferencesKey("horizontal_gesture_sensitivity")
|
||||
val HORIZONTAL_GESTURE_ALPHA_ANIM = booleanPreferencesKey("horizontal_gesture_alpha_anim_bool")
|
||||
val HORIZONTAL_GESTURE_PULL_ANIM = booleanPreferencesKey("horizontal_gesture_pull_anim")
|
||||
val BOTTOM_BAR_PADDING = intPreferencesKey("bottom_bar_padding")
|
||||
val HIGHLIGHTED_READING = booleanPreferencesKey("highlighted_reading")
|
||||
val HIGHLIGHTED_READING_THICKNESS = intPreferencesKey("highlighted_reading_thickness")
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ fun ReaderContent(
|
|||
horizontalGestureScroll: Float,
|
||||
horizontalGestureSensitivity: Dp,
|
||||
horizontalGestureAlphaAnim: Boolean,
|
||||
horizontalGesturePullAnim: Boolean,
|
||||
highlightedReading: Boolean,
|
||||
highlightedReadingThickness: FontWeight,
|
||||
progress: String,
|
||||
|
|
@ -135,6 +136,7 @@ fun ReaderContent(
|
|||
horizontalGestureScroll = horizontalGestureScroll,
|
||||
horizontalGestureSensitivity = horizontalGestureSensitivity,
|
||||
horizontalGestureAlphaAnim = horizontalGestureAlphaAnim,
|
||||
horizontalGesturePullAnim = horizontalGesturePullAnim,
|
||||
highlightedReading = highlightedReading,
|
||||
highlightedReadingThickness = highlightedReadingThickness,
|
||||
progress = progress,
|
||||
|
|
|
|||
|
|
@ -35,12 +35,14 @@ fun Modifier.readerHorizontalGesture(
|
|||
horizontalGestureScroll: Float,
|
||||
horizontalGestureSensitivity: Dp,
|
||||
horizontalGestureAlphaAnim: Boolean,
|
||||
horizontalGesturePullAnim: Boolean,
|
||||
isLoading: Boolean
|
||||
): Modifier {
|
||||
if (horizontalGesture == ReaderHorizontalGesture.OFF || isLoading) return this
|
||||
val inverted = rememberUpdatedState(horizontalGesture == ReaderHorizontalGesture.INVERSE)
|
||||
val sensitivity = rememberUpdatedState(horizontalGestureSensitivity)
|
||||
val alphaAnim = rememberUpdatedState(horizontalGestureAlphaAnim)
|
||||
val pullAnim = rememberUpdatedState(horizontalGesturePullAnim)
|
||||
|
||||
val scope = rememberCoroutineScope()
|
||||
val density = LocalDensity.current
|
||||
|
|
@ -84,7 +86,8 @@ fun Modifier.readerHorizontalGesture(
|
|||
.alpha(calculateAlpha())
|
||||
.offset {
|
||||
IntOffset(
|
||||
x = animatedHorizontalOffset.value.roundToInt(),
|
||||
x = if (pullAnim.value) animatedHorizontalOffset.value.roundToInt()
|
||||
else 0,
|
||||
y = 0
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ fun ReaderLayout(
|
|||
horizontalGestureScroll: Float,
|
||||
horizontalGestureSensitivity: Dp,
|
||||
horizontalGestureAlphaAnim: Boolean,
|
||||
horizontalGesturePullAnim: Boolean,
|
||||
highlightedReading: Boolean,
|
||||
highlightedReadingThickness: FontWeight,
|
||||
progress: String,
|
||||
|
|
@ -164,6 +165,7 @@ fun ReaderLayout(
|
|||
horizontalGestureScroll = horizontalGestureScroll,
|
||||
horizontalGestureSensitivity = horizontalGestureSensitivity,
|
||||
horizontalGestureAlphaAnim = horizontalGestureAlphaAnim,
|
||||
horizontalGesturePullAnim = horizontalGesturePullAnim,
|
||||
isLoading = isLoading
|
||||
)
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ fun ReaderScaffold(
|
|||
horizontalGestureScroll: Float,
|
||||
horizontalGestureSensitivity: Dp,
|
||||
horizontalGestureAlphaAnim: Boolean,
|
||||
horizontalGesturePullAnim: Boolean,
|
||||
highlightedReading: Boolean,
|
||||
highlightedReadingThickness: FontWeight,
|
||||
progress: String,
|
||||
|
|
@ -166,6 +167,7 @@ fun ReaderScaffold(
|
|||
horizontalGestureScroll = horizontalGestureScroll,
|
||||
horizontalGestureSensitivity = horizontalGestureSensitivity,
|
||||
horizontalGestureAlphaAnim = horizontalGestureAlphaAnim,
|
||||
horizontalGesturePullAnim = horizontalGesturePullAnim,
|
||||
highlightedReading = highlightedReading,
|
||||
highlightedReadingThickness = highlightedReadingThickness,
|
||||
progress = progress,
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import ua.acclorite.book_story.R
|
|||
import ua.acclorite.book_story.presentation.settings.components.SettingsSubcategory
|
||||
import ua.acclorite.book_story.presentation.settings.reader.reading_mode.components.HorizontalGestureAlphaAnimOption
|
||||
import ua.acclorite.book_story.presentation.settings.reader.reading_mode.components.HorizontalGestureOption
|
||||
import ua.acclorite.book_story.presentation.settings.reader.reading_mode.components.HorizontalGesturePullAnimOption
|
||||
import ua.acclorite.book_story.presentation.settings.reader.reading_mode.components.HorizontalGestureScrollOption
|
||||
import ua.acclorite.book_story.presentation.settings.reader.reading_mode.components.HorizontalGestureSensitivityOption
|
||||
|
||||
|
|
@ -44,6 +45,10 @@ fun LazyListScope.ReadingModeSubcategory(
|
|||
HorizontalGestureSensitivityOption()
|
||||
}
|
||||
|
||||
item {
|
||||
HorizontalGesturePullAnimOption()
|
||||
}
|
||||
|
||||
item {
|
||||
HorizontalGestureAlphaAnimOption()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ fun HorizontalGestureAlphaAnimOption() {
|
|||
SwitchWithTitle(
|
||||
selected = state.value.horizontalGestureAlphaAnim,
|
||||
title = stringResource(id = R.string.horizontal_gesture_alpha_anim_option),
|
||||
description = stringResource(id = R.string.horizontal_gesture_alpha_anim_option_desc),
|
||||
onClick = {
|
||||
mainModel.onEvent(
|
||||
MainEvent.OnChangeHorizontalGestureAlphaAnim(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Book's Story — free and open-source Material You eBook reader.
|
||||
* Copyright (C) 2024-2025 Acclorite
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
package ua.acclorite.book_story.presentation.settings.reader.reading_mode.components
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import ua.acclorite.book_story.R
|
||||
import ua.acclorite.book_story.domain.reader.ReaderHorizontalGesture
|
||||
import ua.acclorite.book_story.presentation.core.components.settings.SwitchWithTitle
|
||||
import ua.acclorite.book_story.ui.main.MainEvent
|
||||
import ua.acclorite.book_story.ui.main.MainModel
|
||||
import ua.acclorite.book_story.ui.theme.ExpandingTransition
|
||||
|
||||
@Composable
|
||||
fun HorizontalGesturePullAnimOption() {
|
||||
val mainModel = hiltViewModel<MainModel>()
|
||||
val state = mainModel.state.collectAsStateWithLifecycle()
|
||||
|
||||
ExpandingTransition(
|
||||
visible = when (state.value.horizontalGesture) {
|
||||
ReaderHorizontalGesture.OFF -> false
|
||||
else -> true
|
||||
}
|
||||
) {
|
||||
SwitchWithTitle(
|
||||
selected = state.value.horizontalGesturePullAnim,
|
||||
title = stringResource(id = R.string.horizontal_gesture_pull_anim_option),
|
||||
description = stringResource(id = R.string.horizontal_gesture_pull_anim_option_desc),
|
||||
onClick = {
|
||||
mainModel.onEvent(
|
||||
MainEvent.OnChangeHorizontalGesturePullAnim(
|
||||
!state.value.horizontalGesturePullAnim
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -66,4 +66,5 @@ sealed class MainEvent {
|
|||
data class OnChangeFontThickness(val value: String) : MainEvent()
|
||||
data class OnChangeProgressCount(val value: String) : MainEvent()
|
||||
data class OnChangeHorizontalGestureAlphaAnim(val value: Boolean) : MainEvent()
|
||||
data class OnChangeHorizontalGesturePullAnim(val value: Boolean) : MainEvent()
|
||||
}
|
||||
|
|
@ -506,6 +506,14 @@ class MainModel @Inject constructor(
|
|||
it.copy(horizontalGestureAlphaAnim = this)
|
||||
}
|
||||
)
|
||||
|
||||
is MainEvent.OnChangeHorizontalGesturePullAnim -> handleDatastoreUpdate(
|
||||
key = DataStoreConstants.HORIZONTAL_GESTURE_PULL_ANIM,
|
||||
value = event.value,
|
||||
updateState = {
|
||||
it.copy(horizontalGesturePullAnim = this)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ data class MainState(
|
|||
val horizontalGestureScroll: Float = provideDefaultValue { 0.7f },
|
||||
val horizontalGestureSensitivity: Float = provideDefaultValue { 0.6f },
|
||||
val horizontalGestureAlphaAnim: Boolean = provideDefaultValue { true },
|
||||
val horizontalGesturePullAnim: Boolean = provideDefaultValue { true },
|
||||
val bottomBarPadding: Int = provideDefaultValue { 0 },
|
||||
val highlightedReading: Boolean = provideDefaultValue { false },
|
||||
val highlightedReadingThickness: Int = provideDefaultValue { 2 },
|
||||
|
|
@ -369,6 +370,10 @@ data class MainState(
|
|||
horizontalGestureAlphaAnim = provideValue(
|
||||
HORIZONTAL_GESTURE_ALPHA_ANIM
|
||||
) { horizontalGestureAlphaAnim },
|
||||
|
||||
horizontalGesturePullAnim = provideValue(
|
||||
HORIZONTAL_GESTURE_PULL_ANIM
|
||||
) { horizontalGesturePullAnim },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -425,6 +425,7 @@ data class ReaderScreen(val bookId: Int) : Screen, Parcelable {
|
|||
horizontalGestureScroll = mainState.value.horizontalGestureScroll,
|
||||
horizontalGestureSensitivity = horizontalGestureSensitivity,
|
||||
horizontalGestureAlphaAnim = mainState.value.horizontalGestureAlphaAnim,
|
||||
horizontalGesturePullAnim = mainState.value.horizontalGesturePullAnim,
|
||||
highlightedReading = mainState.value.highlightedReading,
|
||||
highlightedReadingThickness = highlightedReadingThickness,
|
||||
progress = progress,
|
||||
|
|
|
|||
|
|
@ -187,6 +187,13 @@
|
|||
<string name="horizontal_gesture_scroll_option">Частка прокрутки</string>
|
||||
<string name="horizontal_gesture_sensitivity_option">Чутливість</string>
|
||||
<string name="horizontal_gesture_alpha_anim_option">Анімація видимості</string>
|
||||
<string name="horizontal_gesture_alpha_anim_option_desc">
|
||||
Увімкнути анімацію видимості під час використання горизонтального жесту
|
||||
</string>
|
||||
<string name="horizontal_gesture_pull_anim_option">Анімація тягнення</string>
|
||||
<string name="horizontal_gesture_pull_anim_option_desc">
|
||||
Увімкнути анімацію тягнення під час використання горизонтального жесту
|
||||
</string>
|
||||
<string name="bottom_bar_padding_option">Відступ нижньої панелі</string>
|
||||
<string name="highlighted_reading_option">Підсвічування слів</string>
|
||||
<string name="highlighted_reading_option_desc">Підсвічувати початок кожного слова</string>
|
||||
|
|
|
|||
|
|
@ -218,6 +218,13 @@
|
|||
<string name="horizontal_gesture_scroll_option">Scroll fraction</string>
|
||||
<string name="horizontal_gesture_sensitivity_option">Sensitivity</string>
|
||||
<string name="horizontal_gesture_alpha_anim_option">Visibility animation</string>
|
||||
<string name="horizontal_gesture_alpha_anim_option_desc">
|
||||
Enable visibility animation when using horizontal gesture
|
||||
</string>
|
||||
<string name="horizontal_gesture_pull_anim_option">Pull animation</string>
|
||||
<string name="horizontal_gesture_pull_anim_option_desc">
|
||||
Enable pull animation when using horizontal gesture
|
||||
</string>
|
||||
<string name="bottom_bar_padding_option">Bottom bar margin</string>
|
||||
<string name="highlighted_reading_option">Highlight words</string>
|
||||
<string name="highlighted_reading_option_desc">Highlight the beginning of each word</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue