-
Notifications
You must be signed in to change notification settings - Fork 44
feat: Option to restore the last set "App Volume" on next app launch #509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
34eb51a
feat: Option to restore the volume set in the last app session
cyanChill acf9c09
chore: Move volume setting to its own file
cyanChill db8f153
refactor: Abstract the slider component used on the "Audio Effects" s…
cyanChill d471300
refactor: Make `AudioEffectSlider` slimmer
cyanChill f04a0b2
chore: Display "App Volume" Slider on "Audio Effects" screen
cyanChill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
mobile/src/modules/audio/_components/AudioEffectSlider.tsx
This file contains hidden or 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,34 @@ | ||
| import { View } from "react-native"; | ||
|
|
||
| import type { Icon } from "~/resources/icons/type"; | ||
|
|
||
| import { CachedSlider } from "~/components/Form/Slider"; | ||
| import { Em } from "~/components/Typography/StyledText"; | ||
|
|
||
| interface Props extends Omit< | ||
| React.ComponentProps<typeof CachedSlider>, | ||
| "_className" | ||
| > { | ||
| displayedValue: string; | ||
| /** Optional icon that appears before the `displayedValue`. */ | ||
| Icon?: (props: Icon) => React.JSX.Element; | ||
| } | ||
|
|
||
| export function AudioEffectSlider({ displayedValue, Icon, ...props }: Props) { | ||
| return ( | ||
| <View className="flex-row items-center gap-2"> | ||
| <CachedSlider | ||
| hitSlop={10} | ||
| trackColor="surfaceContainer" | ||
| roundedEndStop | ||
| _debounceMultiplier={1} | ||
| _className="shrink grow" | ||
| {...props} | ||
| /> | ||
| <View className="w-14 flex-row items-center justify-center gap-2"> | ||
| {Icon ? <Icon size={20} /> : null} | ||
| <Em style={{ fontVariant: ["tabular-nums"] }}>{displayedValue}</Em> | ||
| </View> | ||
| </View> | ||
| ); | ||
| } |
This file contains hidden or 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
This file contains hidden or 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,59 @@ | ||
| import { useState } from "react"; | ||
| import AudioBrowser from "react-native-audio-browser"; | ||
| import { useAnimatedReaction, useSharedValue } from "react-native-reanimated"; | ||
| import { scheduleOnRN } from "react-native-worklets"; | ||
|
|
||
| import { VolumeUp } from "~/resources/icons/VolumeUp"; | ||
| import { playbackStore, usePlaybackStore } from "~/stores/Playback/store"; | ||
|
|
||
| import { SegmentedList } from "~/components/List/Segmented"; | ||
| import { TStyledText } from "~/components/Typography/StyledText"; | ||
| import { Switch } from "~/components/UI/Switch"; | ||
| import { AudioEffectSlider } from "./AudioEffectSlider"; | ||
|
|
||
| export function VolumeSettings() { | ||
| const restoreVolume = usePlaybackStore((s) => s.restoreVolume); | ||
| const volume = usePlaybackStore((s) => s.volume); | ||
| const cachedValue = useSharedValue(volume); | ||
| const [_volume, _setVolume] = useState(1); | ||
|
|
||
| useAnimatedReaction( | ||
| () => cachedValue.get(), | ||
| (currVal) => scheduleOnRN(_setVolume, currVal), | ||
| ); | ||
|
|
||
| return ( | ||
| <SegmentedList> | ||
| <SegmentedList.Item | ||
| labelTextKey="feat.playback.extra.restoreVolume" | ||
| onPress={toggleRestoreVolume} | ||
| RightElement={<Switch enabled={restoreVolume} />} | ||
| /> | ||
| <SegmentedList.CustomItem className="gap-4 p-4"> | ||
| <TStyledText textKey="feat.playback.extra.volume" className="text-sm" /> | ||
| <AudioEffectSlider | ||
| initValue={volume} | ||
| liveValue={cachedValue} | ||
| min={0} | ||
| max={1} | ||
| step={0.01} | ||
| onChange={setVolume} | ||
| _debounceMultiplier={5} | ||
| Icon={VolumeUp} | ||
| displayedValue={`${Math.round(_volume * 100)}%`} | ||
| /> | ||
| </SegmentedList.CustomItem> | ||
| </SegmentedList> | ||
| ); | ||
| } | ||
|
|
||
| //#region Helpers | ||
| function toggleRestoreVolume() { | ||
| playbackStore.setState((prev) => ({ restoreVolume: !prev.restoreVolume })); | ||
| } | ||
|
|
||
| function setVolume(volume: number) { | ||
| playbackStore.setState({ volume }); | ||
| AudioBrowser.setVolume(volume); | ||
| } | ||
| //#endregion | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.