Skip to content

Commit 11788ce

Browse files
committed
feat: allow renaming the recordings
1 parent 68dae0d commit 11788ce

File tree

5 files changed

+57
-9
lines changed

5 files changed

+57
-9
lines changed

example/src/components/RecordButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default function RecordButton({
6262
const styles = StyleSheet.create({
6363
container: {
6464
paddingHorizontal: 16,
65-
paddingVertical: 16,
65+
marginTop: 16,
6666
},
6767
button: {
6868
flexDirection: 'row',

example/src/components/RecordingItem.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { View, Text, TouchableOpacity, StyleSheet, Share } from 'react-native';
1+
import {
2+
View,
3+
Text,
4+
TouchableOpacity,
5+
StyleSheet,
6+
Share,
7+
TextInput,
8+
} from 'react-native';
29
import type { RecordedHaptic } from '../types/recording';
310

411
interface RecordingItemProps {
@@ -9,6 +16,7 @@ interface RecordingItemProps {
916
onPlay: (id: string) => void;
1017
onPause: (id: string) => void;
1118
onDelete: (id: string) => void;
19+
onNameChange: (id: string, name: string) => void;
1220
}
1321

1422
export default function RecordingItem({
@@ -19,6 +27,7 @@ export default function RecordingItem({
1927
onPlay,
2028
onPause,
2129
onDelete,
30+
onNameChange,
2231
}: RecordingItemProps) {
2332
const formatDuration = (seconds: number) => {
2433
const mins = Math.floor(seconds / 60);
@@ -59,10 +68,22 @@ export default function RecordingItem({
5968
<TouchableOpacity
6069
onPress={() => onSelect(recording.id)}
6170
activeOpacity={0.8}
71+
disabled={isSelected}
6272
>
6373
<View style={[styles.container, isSelected && styles.selectedContainer]}>
6474
<View style={styles.info}>
65-
<Text style={styles.name}>{recording.name}</Text>
75+
<TextInput
76+
style={styles.name}
77+
editable={isSelected}
78+
pointerEvents={isSelected ? 'auto' : 'none'}
79+
defaultValue={recording.name}
80+
onChangeText={(text) => {
81+
onNameChange(recording.id, text);
82+
}}
83+
returnKeyType="done"
84+
placeholderTextColor="#636366"
85+
maxLength={50}
86+
/>
6687
<View style={styles.meta}>
6788
<Text style={styles.metaText}>
6889
{formatDuration(recording.duration)}
@@ -139,6 +160,7 @@ const styles = StyleSheet.create({
139160
fontWeight: '600',
140161
color: '#FFFFFF',
141162
marginBottom: 4,
163+
paddingEnd: 16,
142164
},
143165
meta: {
144166
flexDirection: 'row',
@@ -158,9 +180,9 @@ const styles = StyleSheet.create({
158180
gap: 8,
159181
},
160182
button: {
161-
width: 40,
162-
height: 40,
163-
borderRadius: 20,
183+
width: 30,
184+
height: 30,
185+
borderRadius: 30 / 2,
164186
alignItems: 'center',
165187
justifyContent: 'center',
166188
},

example/src/components/RecordingsList.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
import { View, Text, StyleSheet, FlatList, TouchableOpacity } from 'react-native';
1+
import {
2+
View,
3+
Text,
4+
StyleSheet,
5+
FlatList,
6+
TouchableOpacity,
7+
} from 'react-native';
28
import type { RecordedHaptic } from '../types/recording';
39
import RecordingItem from './RecordingItem';
410
import { useSafeAreaInsets } from 'react-native-safe-area-context';
511
import { Link } from 'expo-router';
12+
import { KeyboardStickyView } from 'react-native-keyboard-controller';
613

714
interface RecordingsListProps {
815
recordings: RecordedHaptic[];
@@ -12,6 +19,7 @@ interface RecordingsListProps {
1219
onPlay: (id: string) => void;
1320
onPause: (id: string) => void;
1421
onDelete: (id: string) => void;
22+
onNameChange: (id: string, name: string) => void;
1523
}
1624

1725
export default function RecordingsList({
@@ -22,6 +30,7 @@ export default function RecordingsList({
2230
onPlay,
2331
onPause,
2432
onDelete,
33+
onNameChange,
2534
}: RecordingsListProps) {
2635
const insets = useSafeAreaInsets();
2736

@@ -45,7 +54,7 @@ export default function RecordingsList({
4554
}
4655

4756
return (
48-
<View style={styles.container}>
57+
<KeyboardStickyView style={styles.container}>
4958
<View style={styles.header}>
5059
<Text style={styles.title}>Recordings</Text>
5160
<Link href="/import-modal" asChild>
@@ -57,6 +66,8 @@ export default function RecordingsList({
5766
<FlatList
5867
data={recordings}
5968
keyExtractor={(item) => item.id}
69+
keyboardShouldPersistTaps="handled"
70+
keyboardDismissMode="interactive"
6071
renderItem={({ item }) => (
6172
<RecordingItem
6273
recording={item}
@@ -66,18 +77,23 @@ export default function RecordingsList({
6677
onPlay={onPlay}
6778
onPause={onPause}
6879
onDelete={onDelete}
80+
onNameChange={onNameChange}
6981
/>
7082
)}
7183
contentContainerStyle={{ paddingBottom: insets.bottom + 16 }}
7284
/>
73-
</View>
85+
</KeyboardStickyView>
7486
);
7587
}
7688

7789
const styles = StyleSheet.create({
7890
container: {
7991
flex: 1,
8092
paddingHorizontal: 16,
93+
paddingTop: 16,
94+
borderRadius: 30,
95+
overflow: 'hidden',
96+
backgroundColor: '#000',
8197
},
8298
header: {
8399
flexDirection: 'row',

example/src/contexts/RecorderContext.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ interface RecorderContextValue {
5454
onUserScrollEnd: () => void;
5555
deleteRecording: (id: string) => void;
5656
importRecording: (recording: RecordedHaptic) => void;
57+
renameRecording: (id: string, name: string) => void;
5758
}
5859

5960
const RecorderContext = createContext<RecorderContextValue | null>(null);
@@ -392,6 +393,12 @@ export function RecorderProvider({ children }: { children: ReactNode }) {
392393
setRecordings([...recordings, recording]);
393394
};
394395

396+
const renameRecording = (id: string, name: string) => {
397+
setRecordings(
398+
recordings.map((r) => (r.id === id ? { ...r, name } : r))
399+
);
400+
};
401+
395402
return (
396403
<RecorderContext.Provider
397404
value={{
@@ -426,6 +433,7 @@ export function RecorderProvider({ children }: { children: ReactNode }) {
426433
onUserScrollEnd,
427434
deleteRecording,
428435
importRecording,
436+
renameRecording,
429437
}}
430438
>
431439
{children}

example/src/screens/Recorder.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function RecorderContent() {
4747
onUserScrollStart,
4848
onUserScrollEnd,
4949
deleteRecording,
50+
renameRecording,
5051
} = useRecorder();
5152

5253
const [playingId, setPlayingId] = useState<string | null>(null);
@@ -212,6 +213,7 @@ function RecorderContent() {
212213
onPlay={handlePlayRecording}
213214
onPause={handlePauseRecording}
214215
onDelete={deleteRecording}
216+
onNameChange={renameRecording}
215217
/>
216218
</View>
217219
);

0 commit comments

Comments
 (0)