Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Commit ed08a5b

Browse files
committed
Update example app to include static UI for adding tracks
1 parent b94a450 commit ed08a5b

File tree

3 files changed

+80
-14
lines changed

3 files changed

+80
-14
lines changed

example/App.tsx

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,57 @@
11
import React, { useState } from 'react';
2-
import { StyleSheet, View, Text } from 'react-native';
3-
import { AudioEngine } from 'react-native-audio-engine';
2+
import { Button, FlatList, SafeAreaView, StyleSheet, View } from 'react-native';
3+
import { TrackListItem } from './src';
44

5-
export const App = () => {
6-
const [message, setMessage] = useState<string | undefined>();
5+
type TrackDetails = {
6+
uri: string;
7+
};
78

8-
AudioEngine.sampleMethod('howdy!', 123, message => {
9-
setMessage(message);
10-
});
9+
export const App = () => {
10+
const [tracks, setTracks] = useState<TrackDetails[]>([
11+
{ uri: 'track 1' },
12+
{ uri: 'track 2' },
13+
]);
1114

1215
return (
13-
<View style={styles.container}>
14-
<Text>{message ?? 'Waiting for NativeModule...'}</Text>
15-
</View>
16+
<SafeAreaView style={{ flex: 1 }}>
17+
<FlatList
18+
data={tracks}
19+
renderItem={itemInfo => (
20+
<TrackListItem
21+
uri={itemInfo.item.uri}
22+
onSubmitEditing={text => {
23+
tracks[itemInfo.index].uri = text;
24+
}}
25+
onDelete={() => {
26+
tracks.splice(itemInfo.index, 1);
27+
setTracks([...tracks]);
28+
}}
29+
/>
30+
)}
31+
keyExtractor={(item, index) => `${index}-${item}`}
32+
style={styles.flatList}
33+
/>
34+
<View style={styles.addTrackContainer}>
35+
<Button
36+
title='Add Track'
37+
onPress={() => {
38+
tracks.push({ uri: '' });
39+
setTracks([...tracks]);
40+
}}
41+
/>
42+
</View>
43+
</SafeAreaView>
1644
);
1745
};
1846

1947
const styles = StyleSheet.create({
20-
container: {
48+
flatList: {
2149
flex: 1,
22-
justifyContent: 'center',
23-
alignItems: 'center',
24-
backgroundColor: '#F5FCFF',
50+
},
51+
addTrackContainer: {
52+
flexShrink: 1,
53+
paddingTop: 20,
54+
borderTopWidth: 1,
55+
borderTopColor: '#ccc',
2556
},
2657
});

example/src/TrackListItem.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import { Button, StyleSheet, TextInput, View } from 'react-native';
3+
4+
interface Props {
5+
uri: string;
6+
onSubmitEditing: (text: string) => void;
7+
onDelete: () => void;
8+
}
9+
10+
export const TrackListItem = ({ uri, onSubmitEditing, onDelete }: Props) => {
11+
return (
12+
<View style={styles.container}>
13+
<TextInput
14+
style={styles.input}
15+
defaultValue={uri}
16+
onSubmitEditing={e => onSubmitEditing(e.nativeEvent.text)}
17+
autoCapitalize='none'
18+
/>
19+
<Button title='Delete' onPress={onDelete} />
20+
</View>
21+
);
22+
};
23+
24+
const styles = StyleSheet.create({
25+
container: {
26+
margin: 10,
27+
},
28+
input: {
29+
borderWidth: 1,
30+
borderColor: '#cccccc',
31+
borderRadius: 4,
32+
padding: 10,
33+
},
34+
});

example/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './TrackListItem';

0 commit comments

Comments
 (0)