Fix sample picker and tempo slider alignment
This commit is contained in:
1 parent
302128fdbc
commit
3caf21794d
5 files changed
+84
-93
No files matched your search
@@ -15,6 +15,7 @@
|
||||
android:label="@string/title_activity_main"
|
||||
android:theme="@style/AppTheme.NoActionBarLaunch"
|
||||
android:launchMode="singleTask"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:exported="true">
|
||||
|
||||
<intent-filter>
|
||||
|
||||
Binary file not shown.
@@ -1,13 +1,13 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import type { CSSProperties } from 'react';
|
||||
import { useMemo, useRef, useState } from 'react';
|
||||
import {
|
||||
IonAccordion,
|
||||
IonAccordionGroup,
|
||||
IonButton,
|
||||
IonContent,
|
||||
IonIcon,
|
||||
IonItem,
|
||||
IonLabel,
|
||||
IonPopover,
|
||||
IonModal,
|
||||
IonSearchbar,
|
||||
} from '@ionic/react';
|
||||
import { add } from 'ionicons/icons';
|
||||
@@ -17,7 +17,8 @@ import {
|
||||
isInstrumentId,
|
||||
} from '../domain/instruments';
|
||||
import type { InstrumentId } from '../domain/instruments';
|
||||
import { usePopoverDisclosure } from '../hooks/usePopoverDisclosure';
|
||||
|
||||
const PICKER_SHEET_BREAKPOINTS = [0, 0.82, 1];
|
||||
|
||||
interface InstrumentSelectorProps {
|
||||
onSelectInstrument: (instrumentId: InstrumentId) => void;
|
||||
@@ -26,27 +27,8 @@ interface InstrumentSelectorProps {
|
||||
export function InstrumentSelector({ onSelectInstrument }: InstrumentSelectorProps) {
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [expandedCategoryIds, setExpandedCategoryIds] = useState<string[]>([]);
|
||||
const [viewportHeight, setViewportHeight] = useState(
|
||||
() => window.visualViewport?.height ?? window.innerHeight,
|
||||
);
|
||||
const popoverRef = useRef<HTMLIonPopoverElement>(null);
|
||||
const popover = usePopoverDisclosure();
|
||||
|
||||
useEffect(() => {
|
||||
const visualViewport = window.visualViewport;
|
||||
|
||||
function updateViewportHeight(): void {
|
||||
setViewportHeight(visualViewport?.height ?? window.innerHeight);
|
||||
}
|
||||
|
||||
window.addEventListener('resize', updateViewportHeight);
|
||||
visualViewport?.addEventListener('resize', updateViewportHeight);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('resize', updateViewportHeight);
|
||||
visualViewport?.removeEventListener('resize', updateViewportHeight);
|
||||
};
|
||||
}, []);
|
||||
const [isPickerOpen, setIsPickerOpen] = useState(false);
|
||||
const modalRef = useRef<HTMLIonModalElement>(null);
|
||||
|
||||
const filteredCategories = useMemo(() => {
|
||||
const query = searchQuery.trim().toLowerCase();
|
||||
@@ -100,8 +82,8 @@ export function InstrumentSelector({ onSelectInstrument }: InstrumentSelectorPro
|
||||
setExpandedCategoryIds(typeof value === 'string' ? [value] : []);
|
||||
}
|
||||
|
||||
function handlePopoverDidDismiss(): void {
|
||||
popover.onDidDismiss();
|
||||
function handlePickerDidDismiss(): void {
|
||||
setIsPickerOpen(false);
|
||||
setSearchQuery('');
|
||||
setExpandedCategoryIds([]);
|
||||
}
|
||||
@@ -109,7 +91,7 @@ export function InstrumentSelector({ onSelectInstrument }: InstrumentSelectorPro
|
||||
function addInstrument(value: unknown): void {
|
||||
if (!isInstrumentId(value)) return;
|
||||
|
||||
void popoverRef.current?.dismiss();
|
||||
void modalRef.current?.dismiss();
|
||||
onSelectInstrument(value);
|
||||
}
|
||||
|
||||
@@ -119,25 +101,26 @@ export function InstrumentSelector({ onSelectInstrument }: InstrumentSelectorPro
|
||||
id="instrument-add-trigger"
|
||||
className="instrument-add-button"
|
||||
fill="solid"
|
||||
onClick={() => setIsPickerOpen(true)}
|
||||
aria-label="Open samples"
|
||||
aria-haspopup="dialog"
|
||||
aria-expanded={popover.isOpen}
|
||||
aria-expanded={isPickerOpen}
|
||||
>
|
||||
<IonIcon icon={add} slot="start" />
|
||||
Samples
|
||||
</IonButton>
|
||||
|
||||
<IonPopover
|
||||
ref={popoverRef}
|
||||
className="instrument-picker-popover"
|
||||
style={{ '--picker-viewport-height': `${viewportHeight}px` } as CSSProperties}
|
||||
trigger="instrument-add-trigger"
|
||||
triggerAction="click"
|
||||
side="top"
|
||||
alignment="start"
|
||||
onDidPresent={popover.onDidPresent}
|
||||
onDidDismiss={handlePopoverDidDismiss}
|
||||
<IonModal
|
||||
ref={modalRef}
|
||||
className="instrument-picker-modal"
|
||||
isOpen={isPickerOpen}
|
||||
breakpoints={PICKER_SHEET_BREAKPOINTS}
|
||||
initialBreakpoint={0.82}
|
||||
expandToScroll={false}
|
||||
handle
|
||||
onDidDismiss={handlePickerDidDismiss}
|
||||
>
|
||||
<IonContent className="instrument-picker-content" scrollY={false}>
|
||||
<div className="instrument-picker-menu">
|
||||
<IonSearchbar
|
||||
className="instrument-picker-search"
|
||||
@@ -146,6 +129,7 @@ export function InstrumentSelector({ onSelectInstrument }: InstrumentSelectorPro
|
||||
value={searchQuery}
|
||||
debounce={0}
|
||||
showClearButton="always"
|
||||
onIonFocus={() => void modalRef.current?.setCurrentBreakpoint(1)}
|
||||
onIonInput={(event) => handleSearchInput(event.detail.value)}
|
||||
onIonClear={() => handleSearchInput('')}
|
||||
/>
|
||||
@@ -189,7 +173,8 @@ export function InstrumentSelector({ onSelectInstrument }: InstrumentSelectorPro
|
||||
<p className="instrument-picker-empty" role="status">No matching samples.</p>
|
||||
)}
|
||||
</div>
|
||||
</IonPopover>
|
||||
</IonContent>
|
||||
</IonModal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -10,9 +10,14 @@ interface TempoControlProps {
|
||||
onTempoChange: (tempoBpm: number) => void;
|
||||
}
|
||||
|
||||
const TEMPO_TRACK_HEIGHT = 164;
|
||||
const TEMPO_THUMB_SIZE = 18;
|
||||
|
||||
export const TempoControl = memo(function TempoControl({ tempoBpm, onTempoChange }: TempoControlProps) {
|
||||
const popover = usePopoverDisclosure();
|
||||
const tempoProgress = ((tempoBpm - MIN_TEMPO_BPM) / (MAX_TEMPO_BPM - MIN_TEMPO_BPM)) * 100;
|
||||
const tempoThumbCenter = (TEMPO_TRACK_HEIGHT - TEMPO_THUMB_SIZE) / 2
|
||||
+ ((100 - tempoProgress) / 100) * (TEMPO_TRACK_HEIGHT - TEMPO_THUMB_SIZE);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -41,7 +46,13 @@ export const TempoControl = memo(function TempoControl({ tempoBpm, onTempoChange
|
||||
>
|
||||
<div className="tempo-popover-content">
|
||||
<output className="tempo-value" aria-live="polite">{tempoBpm} BPM</output>
|
||||
<div className="tempo-range-track">
|
||||
<div
|
||||
className="tempo-range-track"
|
||||
style={{
|
||||
'--tempo-progress': `${tempoProgress}%`,
|
||||
'--tempo-thumb-center': `${tempoThumbCenter}px`,
|
||||
} as CSSProperties}
|
||||
>
|
||||
<input
|
||||
className="tempo-range"
|
||||
type="range"
|
||||
@@ -50,9 +61,9 @@ export const TempoControl = memo(function TempoControl({ tempoBpm, onTempoChange
|
||||
max={MAX_TEMPO_BPM}
|
||||
step={1}
|
||||
value={tempoBpm}
|
||||
style={{ '--tempo-progress': `${tempoProgress}%` } as CSSProperties}
|
||||
onChange={(event) => onTempoChange(event.currentTarget.valueAsNumber)}
|
||||
/>
|
||||
<span className="tempo-range-thumb" aria-hidden="true" />
|
||||
</div>
|
||||
</div>
|
||||
</IonPopover>
|
||||
|
||||
+45
-51
@@ -872,25 +872,26 @@ ion-content.app-content-studio {
|
||||
font-size: 19px;
|
||||
}
|
||||
|
||||
ion-popover.instrument-picker-popover {
|
||||
ion-modal.instrument-picker-modal {
|
||||
--width: min(420px, calc(100vw - 24px));
|
||||
--picker-menu-height: min(60vh, 420px);
|
||||
--picker-menu-height: min(
|
||||
60dvh,
|
||||
420px,
|
||||
max(120px, calc(var(--picker-viewport-height, 100vh) - 160px))
|
||||
);
|
||||
--max-height: var(--picker-menu-height);
|
||||
--height: min(88vh, 620px);
|
||||
--max-height: calc(100vh - 12px);
|
||||
--max-height: calc(100dvh - 12px);
|
||||
--background: var(--surface);
|
||||
--backdrop-opacity: 0;
|
||||
--box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
|
||||
--border-radius: 18px 18px 0 0;
|
||||
--box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.45);
|
||||
}
|
||||
|
||||
ion-content.instrument-picker-content {
|
||||
--background: var(--surface);
|
||||
--overflow: hidden;
|
||||
}
|
||||
|
||||
.instrument-picker-menu {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: var(--picker-menu-height);
|
||||
max-height: var(--picker-menu-height);
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
min-height: 0;
|
||||
box-sizing: border-box;
|
||||
flex-direction: column;
|
||||
@@ -1137,6 +1138,24 @@ ion-popover.instrument-picker-popover {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.tempo-range-track::before {
|
||||
position: absolute;
|
||||
top: 9px;
|
||||
bottom: 9px;
|
||||
left: 50%;
|
||||
width: 3px;
|
||||
border-radius: 999px;
|
||||
background: linear-gradient(
|
||||
to top,
|
||||
var(--accent) 0%,
|
||||
var(--accent) var(--tempo-progress),
|
||||
#58537d var(--tempo-progress),
|
||||
#58537d 100%
|
||||
);
|
||||
content: '';
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
.tempo-range {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
@@ -1148,57 +1167,32 @@ ion-popover.instrument-picker-popover {
|
||||
border: 0;
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
z-index: 1;
|
||||
transform: translate(-50%, -50%) rotate(-90deg);
|
||||
background: transparent;
|
||||
cursor: ns-resize;
|
||||
opacity: 0;
|
||||
touch-action: none;
|
||||
}
|
||||
|
||||
.tempo-range::-webkit-slider-runnable-track {
|
||||
width: 100%;
|
||||
height: 3px;
|
||||
border-radius: 999px;
|
||||
background: linear-gradient(
|
||||
to right,
|
||||
var(--accent) 0%,
|
||||
var(--accent) var(--tempo-progress),
|
||||
#58537d var(--tempo-progress),
|
||||
#58537d 100%
|
||||
);
|
||||
}
|
||||
|
||||
.tempo-range::-webkit-slider-thumb {
|
||||
.tempo-range-thumb {
|
||||
position: absolute;
|
||||
top: var(--tempo-thumb-center);
|
||||
left: 50%;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
margin-top: -7.5px;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
-webkit-appearance: none;
|
||||
background: var(--accent);
|
||||
box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.18);
|
||||
}
|
||||
|
||||
.tempo-range::-moz-range-track {
|
||||
width: 100%;
|
||||
height: 3px;
|
||||
border-radius: 999px;
|
||||
background: #58537d;
|
||||
}
|
||||
|
||||
.tempo-range::-moz-range-progress {
|
||||
border-radius: 999px;
|
||||
background: var(--accent);
|
||||
}
|
||||
|
||||
.tempo-range::-moz-range-thumb {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
background: var(--accent);
|
||||
box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.18);
|
||||
pointer-events: none;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.tempo-range:focus-visible {
|
||||
.tempo-range-track:focus-within .tempo-range-thumb {
|
||||
box-shadow: 0 0 0 2px var(--base), 0 0 0 4px var(--accent);
|
||||
}
|
||||
|
||||
.tempo-range-track:focus-within {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 4px;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user